This project is intended primarily to reduce contact between medical staff / workers (doctors, nurses, etc.) with patients infected with the COVID-19 virus. By implementing this project, healthcare professionals will reduce contact with the infected so that they will not have to go to each patient several times a day and examine his temperature and other parameters related to his body that disrupts the virus.
Every medical worker will be able to monitor the patient's condition in their office or the room where they spend most of their time. How will this be achieved? The "Thunderboard Sense 2" device will be used to measure body parameters, in such a way that the sensors will be placed directly on the patient's arm. And they will submit the data via BLE to BalenaFin v1.1 board. BalenaFin v1.1 will submit data to Google Firebase via WiFi. Arduino MKR WiFi 1010 board will submit data of temperature to Google Firebase via WiFi. Android studio application will be monitoring data from Thunderboard Sense 2, BalenaFin v1.1 and Arduino MKR WiFi 1010 board. Much more about that below the project description. I hope you will like the idea, enjoy.
Step 1: Installing Raspbian on BalenaFin kit and configurating this boardThe balenaFin is a professional carrier board for the Raspberry Pi Compute Module. Details for this board is on this link. Thanks Balena corporation for free hardware.
Get start. For installing Raspbian system on BalenaFin board, you need balenaEtcher application. This application serves for uploading/installing system on your BalenaFin board. Simple and short.
- DownloadbalenaEtcher
- Install this application and open it.
- Select image of your system (Raspbian image download from this link),
- Connect your BalenaFin board to power adapter and connect to your PC via USB cable,
- Wait a few seconds select your BalenaFin board and click "Flash!"
- Waiting for uploaded/installed your system in balenaEtcher application,
- After finishing this process, connect your HDMI, LAN cable and click restart button on board. After running your system you will see Raspbian desktop interface (photo bellow).
Connect keyboard and mouse to your balenaFin board and go to step 2.
If you don't have a keyboard and mouse, use a computer mouse and turn on the ssh option and follow this step to the end.
- Launch Raspberry Pi Configuration from the Preferences menu
- Navigate to the Interfaces tab
- Select Enabled next to SSH
- Click OK
- Reboot your balenaFin.
Next command (insert in terminal on your PC) is to access the terminal on the balenaFin board (IP adress is on screen on your dasktop of balenaFin board, previous second photo):
$ ssh pi@ip_address_balenaFin
Enter "yes" after press enter and insert password for Raspbian user account. Default password is: raspberry.
balenaFin board has a potential problem because it does not detect the automatic wireless module on the board, so it is necessary to enter the path to the module.
Use the following command to enter this option.
$ sudo nano /boot/config.txt
After last line insert next command and click CTRL+X and Y.
dtoverlay=balena-fin
Enter:
$ sudo reboot
After restart your balenaFin you will see WiFi networks in your scan.
Step 3: Google Firebase accountGoogle Firebase serves to store data collected on the BalenaFin v1.1 and Arduino MKR WIFI 1010 board. These datas can be further used on websites, mobile applications and anywhere they can access the Internet. Sign in using your Google Account and follow the steps below.
After login follow the next steps:
- Click on "+ Add project"
- Fill information and click "Create"
- After loading, click "Develop" in left navigation bar. Then click "Database"
- Click "Create database" then check "Start in test mode" and click "Enable"
- Next to "Database" title in the drop-down menu, select "Realtime Database"
- Click on "Roles" tab. In code delete "false" and add "true".
- Back to "Data" tab. Copy link of your database and insert in Arduino and Python code.
- Click on icon gear (left navigation bar) choose "Projects settings" and click on "Service accounts" choose "Database secrets".
- On right copy "Secret" code and insert in Arduino and Python code.
Now, we've connected BalenaFin v1.1, Arduino MKR Board and Google Firebase.
Step 4: BalenaFin v1.1 board Gateway for sending data to Google Firebase from Thunderboard Sense 2In order to communicate between Thunderboard Sense 2 and Google Firebase, it is necessary to create several python scripts on the balenaFin v1.1 board. In addition to the python scripts that have been created and need to be configured, you also need to install a few libraries and programs, so let’s get started with that first.
First, let's install a software tool to edit and create scripts with bellow command in BalenaFin terminal. Nano is text editor for Linux OS.
$ sudo apt-get install nano
Create python script with this commad in BalenaFin terminal:
$ sudo touch script_name.py
Open edit script with next commad:
$ sudo nano script_name.py
Ctrl + X and Y is save changes in script. Ctrl + X and N exit from nano editor without save.
Now, insert this command in terminal for install Google Firebase library:
$ sudo pip3 install python-firebase
And install Bluepy library for BLE communication between BalenaFin and Thunderboard Sense 2:
$ sudo pip3 install bluepy
After installing the necessary libraries, the basic things for the balenaFin application are doned, and python scripts can be written to communicating and sending data.
In thundercloud.py script you will see this line (line number 9):
self.addr = 'https://test-base.firebaseio.com/'
in ' ' inset your link of your Google Firebase database and with this your database is now connect with BalenaFin script. Secret code is not necessary.
There are 3 python scripts used to communicate between Thunderboard Sense 2, balenaFin v1.1 and Google Firebase.
- tbsense.py is used to connect balenaFin and Thunderboard Sense 2 via BLE communication, and there are defined parameters that will be read from Thunderboard Sense 2.
- thundercloud.py is used to communicate balenaFin v1.1 and Google Firebase.
- tbsense_scan.py is used to search Thunderboard Sense 2 boards in the environment and collect data from them using functions written in tbsense.py scripts and sends them to Google Firebase via functions called from the thunderboard.py script.
def getSession(self, deviceId):
timestamp = int(time.time() * 1000)
guid = str(uuid.uuid1())
d = {
"P1_temperature": 0,
"P1_pressure": 0,
"P1_pulse": 0,
}
self.firebase.put("Patients", "P1", d)
return guid
def putEnvironmentData(self, guid, data):
self.firebase.put("Patients", "P1", data)
getSession () function from the code above located in the thundercloud.py script. Used to test send data to Google Firebase and position it in name_database/Patients/P1/.
putEnvironmentData() function from thundercloud.py script is used to send accurate values for parameters read from the Thunderboard Sense 2 board.
def sensorLoop(fb, tb, devId):
session = fb.getSession(devId)
tb.session = session
value = tb.char['power_source_type'].read()
if ord(value) == 0x04:
tb.coinCell = True
while True:
text = ''
text += '\n' + tb.name + '\n'
data = dict()
try:
for key in tb.char.keys():
if key == 'temperature':
data['P1_temperature'] = tb.readTemperature()
text += 'Temperature:\t{} C\n'.format(data['temperature'])
elif key == 'humidity':
data['P1_humidity'] = tb.readHumidity()
text += 'Humidity:\t{} %RH\n'.format(data['humidity'])
elif key == 'pressure':
data['P1_pressure'] = tb.readPressure()
text += 'Pressure:\t{}\n'.format(data['pressure'])
except:
return
print(text)
fb.putEnvironmentData(session, data)
sleep(1)
Function sensorLoop() from tbsense_scan.py is used to read data from Thunderboard Sense 2, read the value of temperature, humidity and pressure and is delivered to Google Firebase by calling the function putEnvironmentData() which we explained earlier.
In the picture below, you can see at the bottom of the database how the value is entered at a precisely defined location according to the code.
- This is necessary because each time when connecting balenaFin board to the power supply, the script will automatically start. It's simpler because we will not have to run the script again in the terminal every time.
- This resolved the user's frustration, user won't have to run script every time when the power supply falls. Now, user must only provide new power, everything else will happens in the background.
- Let's start with the setting. Run next command in terminal on balenaFin:
sudo crontab -e
Choose editor and enter the next line of code at the end of document:
@reboot python3 /home/pi/Desktop/script_name.py
/home/pi/Desktop/script_name.py
is path to the script you want to run.
- Reboot balenaFin.
- Now, when you start the Raspberry Pi, the script you selected will automatically launch.
"The Arduino MKR WiFi 1010 is the easiest point of entry to basic IoT and pico-network application design. Whether you are looking at building a sensor network connected to your office or home router, or if you want to create a BLE device sending data to a cellphone, the MKR WiFi 1010 is your one-stop-solution for many of the basic IoT application scenarios."
From the above we can see that the Arduino MKR 1010 Wifi board has various benefits in the form of creating an IoT solution. Therefore its ability to communicate via WiFi network or BLE to some Gateway then further into the network is a great thing that can be included in the Doctor's dashboard project.
I took advantage of the WiFi module built into the Arduino MKR board. I accessed Google Firebase via the accompanying library and provided sensor data based on that. The sensor used is the NTC Thermistor where another 10k ohm resistor leads to the temperature value in the code. That temperature goes further into the Google Firebase every 2 seconds.
First of all, using the Arduino IDE program, we install board drivers and necessary library,
- Tools -> Boards -> Boards Manager and in search bar insert Arduino MKR and select first
- Sketch -> Include Library -> Manage Libraries and search WiFiNINA and select first
After install all drivers and libraries, we will connect NTC thermistor to Arduino MKR 1010 board as on next shema.
Let us now consider how the program code for reading and sending data works.
First, insert libraries and you need to enter the Google Firebase database link, the Secret code downloaded for the project. In addition, it is necessary to enter the name and code of the wifi network to which the MKR board will be connected.
#include "Firebase_Arduino_WiFiNINA.h"
#define FIREBASE_HOST "Google_Firebase_database_link"
#define FIREBASE_AUTH "firebase_secert_code"
#define WIFI_SSID "Wifi_name"
#define WIFI_PASSWORD "wifi_password"
A function is then written to read the conversion of the analog signal from the NTC thermistor to the actual temperature value. We can see that the for loop is used to read data 5 times from the thermistor. then the sum of these values is divided by 5 and the mean value is obtained.
for (i = 0; i < numSamples; i++)
{
adcVal = adcVal + analogRead(analogPin);
delay(100);
}
adcVal = adcVal/5;
K = 1.00 / (invT0 + invBeta*(log ( adcMax / (float) adcVal - 1.00)));
C = K - 273.15; // convert to Celsius
t[0] = K; t[1] = C;
return;
The value read using the above formula converts the mean value of the analog signal to the temperature expressed in kelvins. Then the value 273.15 is subtracted from that temperature and we get the value in degrees Celsius.
t [] represents a series of 2 elements and the first is the temperature in kelvins and the second is the temperature in Celsius.
In the loop function, we have the previously called preet function getTemp (), where in parentheses is the name of the array of two elements that the function will return to us. Then the second element of the array is taken below and sent to Google Firebase.
This process is repeated every 2 seconds.
void loop()
{
float temp[2];
getTemp(temp);
Firebase.setFloat(firebaseData, "/P2_temperature", temp[1]);
delay(2000);
}
Step 6: Android applicationThe Android application is used to display the results collected from the Thunderboard Sense 2 board and the Arduino MKR 1010 WiFi board. The Android app buys patient data from Google Firebase. Currently, the database contains enrolled values for 4 patients. The attached video shows how the color of a particular patient changes depending on the height of his temperature.
- If the temperature is below 37°C, then the window is tied to the patient in blue.
- If the patient's temperature is above 37°C, then his window is red.
dref = FirebaseDatabase.getInstance().getReference();
dref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
P2stringT = dataSnapshot.child("P2_temperature").getValue().toString();
P2textT.setText(P2stringT + "C");
float temp2Data = Float.parseFloat(P2stringT);
if (temp2Data < 37) {
RL2.setBackgroundColor(Color.parseColor("#003cb3"));
}
else {
RL2.setBackgroundColor(Color.parseColor("#ff5c33"));
}
}
From this part of the code we see that the reading of temperature data for the first patient is read and based on the level of his temperature, the color in the background of the text is changed.
Since the value is taken from the database in the form of a String, it is necessary to convert this value to Float in order to perform testing (if-else) whether it is above or below 37°C. (float temp1Data = Float.parseFloat(P1stringT);)
Full codes for the android application are attached to XML and JAVA.
Note:
Since data from Thunderboard Sense 2 is saved via balenaFin v1.1. panels in Google Firebase and are located on the location / Patients / P1 / then the code for this parameter should be changed in the code, and to read the data from the database downloaded from Thunderboard Sense 2 will be read as follows in the Android application
P1stringT = dataSnapshot.child("Patients").child("P1").child("P1_temperature").getValue().toString();
ConclusionThis system is used to monitor patients with COVID-19 virus. It is necessary to use sensors that will be placed on the patient's body and thus read the best results.The system should have a few more upgrades such as:
- Creating a housing for the device that will be located in the room with patients and be connected to the WiFi network. (balenaFin v1.1 case)
- Making a case for Thunderboard Sense 2 with attachment to the patient's body.
- Making a case for Android MKR 1010 board and sensors that will be connected to patients with cables.
- I believe there are many more shortcomings that need to be addressed.I managed to finish this at the last minute to submit the project (there was a delay in the delivery of parts)
I thank the hackster team, Balena, Silicon Labs and Arduino for boards delivered for doing this project.I hope you enjoyed reading.
Comments