Week 7: Software Updates
In addition to the electrical updates we accomplished, we also produced a rough sketch of the finalized Arduino code. Since our group hasn't had a working Arduino Nano like we had hoped, we tested most of the sketch on an Arduino Uno that was given to us. Thus, we don't currently know whether the Nano has the storage space to hold the sketch like the Uno.
Arduino:
Below are screenshots of our most current Arduino sketch:
The overall purpose of the code was to establish a connection with an external bluetooth device and an app such that the Arduino could transfer data from the sensors (pulse-rate and temperature) to the app and have the app plot the data and alert an emergency contact if one of the two vitals exceeded a healthy boundary.
For the heartbeat sensor, temperature sensor, and OLED display screen special libraries provided by the manufacturers were utilized. The SoftwareSerial is the library that handles the communcation aspect of the sketch, connecting to both the Serial Monitor and Serial Plotter incorporated in the Arduino IDE, as well as being the way data is sent to the HC-06 and transmitted via bluetooth. It also allows the HC-06 module and the Arduino to read incoming data that can be sent by the app. Both the Adafruit_SSD1306 and the Adafruit_GFX libraries are used to control the OLED display, with the SSD1306 library facilitating the commands for display and the GFX library helping with the graphic components. The temperature sensor uses the Adafruit_MLX90614, which contains specific predefined functions used later in the sketch. Lastly, the heartbeat/pulse-rate sensor uses the DFRobot_Heartrate library. After initializing all variables and allocating pin locations for the different sensors, the baud rate was set to 115200 since this was the optimal rating that worked best with the analog read for the sensor. Moreover, both the OLED screen display and the temperature sensor required an I2C connection with the Arduino, so the Wire library already installed in the Arduino IDE was included.
In the setup portion of the code, besides establishing the baud rate, the OLED display, which served as an on screen display in case no bluetooth device is nearby, was initialized. In the main portion of the code, the HC-06 bluetooth module is first told to check if there is any bluetooth data to be read. If so, read it. After that, the code is designed to send either the sensor values from the heartbeat sensor or temperature sensor based on what byte values were sent from the bluetooth. The idea was to have two separate buttons on the app that could allow the user to see either the readings from the pulse-rate sensor or the temperature sensor and see the graphs from them. If a byte value of 0 is received, then a temperature sensor function is called and sends its sensor value to the app to be recorded and plotted, if possible. Data from this sensor is sent to the app in degrees Fahrenheit. Next, a similar process occurs for the heartbeat sensor if a byte of value 1 is received from the app, calling the bpm function, which returns the pulse-rate as a byte. This value is then sent via bluetooth to the app. Finally, a function to display the values on the OLED displayed is called. No data from this function is sent to the bluetooth app specifically, but rather uses the two previous functions mentioned and displays those to the led screen, updating the display every time a new value is sent.
App Updates:
Currently, our team is using MitAppInventor to create the bluetooth app. So far the app is design to display the values from the sensors and graph them in the green area displayed in the figure below. The user is also supposed to be able to switch between what values are displayed; although, currently our team is having issues with either the HC-06 module receiving values from the app or the app sending values. Another feature of the app is to allow the user to pick which bluetooth connection to make from a list of nearby devices, as seen with Bluetooth Connections list viewer.
Attached below is a screenshot of the block code produced in the MitAppInventor software that commands the features described above:
First, the user is asked to pick a bluetooth connection to make using the list viewer and button labelled "Bluetooth Connections". After a selection is made, the app connects to that device's address, and a text pops up notifying the user that a connection has been established. Next, the app reads values sent from the Arduino system and plots them, updating each value as time progresses, hence the need for the Clock1 component. Likewise, as new values are sent in, a text box also displays the most recent value received. Yet, there are still some functions and graphics that need to be added such as adding axis to the graphs to make the data visualization more readable to the user and to make sure that the app is indeed sending a byte to the Arduino with each button click.
Comments
Post a Comment