Page Content:

Knee Replacement Exercises Resources:

Interface examples for projects similar to my project:

MIT App Inventor Resources:

Bluetooth (RNF4871) Resources:

Datasheets:


First sketch

First, I made a sketch of the user interface I am intended to do by hand. The first page is the Exercises Timeline Page that includes a list of rehabilitation exercises reqired to do by time. Then, by clicking on each exercise name, the user will be directed to the Exercise page, which includes all inforamtion about it. The following images shows how my project interface should look like.

interface1 interface2


MIT App Inventor Test

The next step is to build my project interface using MIT App Inventor. First thing I did was navigating the App Inventor website to get familiar with it. Next thing I did was building a setup program for Bluetooth communication. To do that I followed this tutorial.

In the begnning I have created a simple program, which turn an LED on and off from a mobile device using "HC-05" bluetooth module for communication with Arduino UNO. Connection for this test is shown below:

HC_connection

Communication between Arduino UNO and "HC-05" is over serial commands through Tx and Rx pins. However, these pins should be disconnected when uploading the code to Arduino UNO.

I have uploaded the following code to my Arduino UNO. The code tells arduino UNO to turn on the LED connected to pin 13 when the user click on "ON" button and turn it off when click on "OFF" button from the MIT app.

// https://www.youtube.com/watch?v=aQcJ4uHdQEA
// https://github.com/binaryupdates/arudino-hc05-bluetooth

char Incoming_value = 0;
                
void setup() 
{
  Serial.begin(9600);         
  pinMode(13, OUTPUT);       
}

void loop()
{
  if(Serial.available() > 0)  
  {
    Incoming_value = Serial.read();      
    Serial.print(Incoming_value);        
    Serial.print("\n");        
    if(Incoming_value == '1')             
      digitalWrite(13, HIGH);  
    else if(Incoming_value == '0')       
      digitalWrite(13, LOW);   
  }                            
}

After uploading the code, connect back Tx and Rx pins. The next step is to build a mobile app using MIT app inventor website. It provides a free programming enviroment that is easy to understand and follow for beginners in programming.

The following screenshot shows my Designer window that contains all the components I used and shows how the app will look like when installed on the mobile phone later:

BluetoothAppDesigner

While the following screenshot shows my Blocks window that contains all the programming code:

BluetoothAppBlocks

Now the app is ready to install on mobile phone. To do that click on Build from the top menu then App(provide QR code for .apk).

MITbuild

Wait until the QR produced. This may take 1 to 2 minutes based on your internet speed. QRcode

When QR code appears on the screen, open The MIT AI2 Companion app and scan it with your mobile phone.

QRcode2

Follow the below steps on the mobile phone to install the app: installingSteps

Finally, the app is installed on the mobile phone. Pair the mobile device with the bluetooth module "HC-05", connect it, and turn the LED on and off. The following video shows how to connect to bluetooth module and the operated system.


Bluetooth Low Energy Module "RN4871" Test

Later, I decided to use an on board bluetooth "RN4871" instead of "HC-05" bluetooth module to save space and energy. Also, I shifted to "RN4871" because it has more advanced features that allow me to create my own services and characteristics than "HC-05".

Click here for “RNF4871” datasheet.

“RN4871” mounted on my micro-controller board: RN4871

For full circuit schematic, routing and PCB, refer to point 1.3. from circuit design section of my final project page.

The circuit I did was based on RN4871 (2.4 GHz Bluetooth) components and board provided in the networking and communications week of Fab Acadmey Schedule.

Board: board

Components: hello.RN4871.ftdi

Bill of Materials (BoM):

QtyPart nameValue
1RN4871Bluetooth low energy
1Resistor10K ohms
1Capacitor1 uF
1LM3480IM33.3 Voltage regulator
1FTDI cable6 pins

This bluetooth board works differently than "HC-05" bluetooth module since it needs to be configured and programmed as you want before running and not just plug and play as the "HC-05" operates.

Bluetooth communication through FTDI (serial):

Use terminal to install pyserial on your PC if you don’t have it. Type the following:

python -m pip install -U pip setuptools

Result: pyserial

Later, open terminal in your PC and follow steps provided in Neil’s tutorial here.

Steps are as following:

Connect your circuit that contains “RN4871” bluetooth to your PC using an FTDI cable.

In a Linux computer, open terminal and upload miniterm.py file to your board, which you can download it from here. To do that, type the following:

$ miniterm.py /dev/ttyUSB0 115200

Note: you may change USB port numeber based on your setup.

If this is done successfully and the port is connected, you will get the following message: miniterm

Settings:

Then typed the following commands to get everything working based on Neil's tutorial. This basically enters command mode, turn on ECHO, sets it in UART Transparent mode, then reboots.

$$$
+
SS,C0
R,1

However, when I first typed "$$$" and pressed Enter button, I got error message that says: "Command not found".

notFound

Later, I tried to connect my mobile phone (Android system) with "RN4871" bluetooth circuit. To do that, I have installed an app called "BLE Scanner"

From the "Near By" tab, I found my bluetooth shown as "BLE-8BE2". So I clicked on it to connect.

NearBy

When I connected, I got the following command on my PC termianl:

connect

So, I decided to shift to send data using Arduino IDE serial as explained in the next steps.

Bluetooth communication through Arduino UNO:

In this step I'll communicate with my bluetooth chip through Arduino IDE serial command. But, instead of using an FTDI cable, I'll use my Arduino UNO to communicate with my bluetooth chip through ISP connection. I have followed this useful tutorial step by step.

Connection:

Connect attiny84 board, which conatins "RN4871" bluetooth chip to Arduino UNO using ISP connection. As well as, connect Tx and Rx pins of attiny84 board to Rx and Tx pins of Arduino UNO.

connection

I have used the same app that I used in the steps previously, which is BLE Scanner by Bluepixel Technologies LLP app. You can install the app from here for Android devices. Howerver, there are many similar apps that you can use.

Open the BLE Scanner app, you should see the "RN4871", which named "BLE-8BE2". However, it may named differently for you. Click on it to connect.

You will be directed to the device information page. Click on "GENERIC ACCESS" and read the characteristic data by clicking the small R icon on the right side.

BluetoothConnection

Now we make sure that it is working, so we can try sending and receving messages between mobile device and PC through Arduino IDE serial terminal.

Next step is to open Arduino IDE serial monitor and change the line endings to “No line ending”, buad rate to "115200 and type the following to enter the command mode:

$$$

You will get a “CMD>” reply.

CMD

Change to "Carriage return" and use BLE scanner mobile app to connect to "RN4871" again while the serial monitor still open. When connecting is done, connection details will be sent to the serial monitor:

details

To know the firmware version, enter "V" command. As the return shows, the module I have is using firmware V1.18.3.. To get device information, enter "D" command. Based on return:

  • Device MAC Address: D880039FD8BE2
  • Device Name: BLE-8BE2
  • Connected Device MAC address: No
  • Authentication Method: 2
  • Device Features as set by the “SR” command: 0000
  • Server Services: C0

VD

Now try to send data to the serial monitor. To do that, open the BLE Scanner" mobile app and click on custom services >> custom characteristic >> "W" icon >> a text input box will appear, enter the text you want to send, for me I've entered "Maryam" >> click OK.

The value of the custom characteristic changes to "Maryam" and you should see the same in the serial monitor.

Transmit

Serial monitor: serialM

Now, try to recevie data from the serial monitor. To do that, first open the BLE Scanner" mobile app and click on the "N" icon to turn on notifications. In the serial monitor enter the text you want to send, for me I've entered "It's Maryam again" and click send. The text will appear in the custom characteristic of the BLE Scanner" mobile app.

send


Final User Interface (UI)

After testing the functionality of both "HC-05" bluetooth module and "RN4871" bluetooth low energy module, I decided to use "RN4871" to save space and energy.

To build the project interface, I've used MIT App Inventor. The following screenshot shows my Designer window that shows how the app will look like when installed on the mobile phone:

BluetoothAppDesigner

While the following screenshot shows my Blocks window that contains the programming code:

finalBlocks

Then I have followed the same steps explained in MIT App Inventor Test section to install the app I've created to a mobile phone.

Video of connecting the system:

Video of the operating system with final interface: