The goal of this project is to provide a step-by-step guide to make a stand-alone or IoT enabled health monitoring application. This project uses BeagleBoard.org® PocketBeagle® and MikroElektronika Click Boards™. PocketBeagle® is an ultra-tiny-yet-complete open-source USB-key-fob computer developed by BeagleBoard.org® and features the OSD3358-SM System-in-Package (SiP) from Octavo Systems.This project features the Heart rate 3 Click Board and Weather Click Board along with a WiFi dongle to create a remote health monitor.
Get the story behind the story on the Octavo Systems blog site.
The project will use the 2 headers of PocketBeagle® to connect the MikroElektronika Click Boards. The following figure shows the pin-out of the 2 headers of PocketBeagle®.
The default function of each pin is highlighted in dashed line. Click Boards™ have a standardized MikroBUS™ pin-out (shown below).
BeagleBoard.org® PocketBeagle® (pictured below) headers conform to the MikroBUS™ standard and allow for two click boards™ to be interfaced with PocketBeagle® at a time (shown in the following figure). Although no guarantees are made with respect to compatibility, most click boards™ work with PocketBeagle® with a little bit of effort.
MikroElektronika produces 450 click boards that provide functionalities that include sensing and communication. The figure below shows an example of how click boards can be added to PocketBeagle®. These examples are OLED and RadioStation.
This project's procedure assumes that an SD card with a Linux image from Beagleboard.org: https://beagleboard.org/latest-images is installed on PocketBeagle®. Please see the PocketBeagle® System Reference Manual for additional information on bringing up and connecting PocketBeagle®.
In the health monitoring application, PocketBeagle® functions as a measurement sensor. It can be part of a fleet of sensors that send data to a gateway where data is gathered and is sent to a display or processed for decision making. The following figure shows the block diagram of the system.
While the health monitor is part of this system of multiple sensors that send data to be aggregated, It can also operate individually without other components of the system.
The heart rate 3 click board uses the AFE4404 analog front end IC for digital measurements of photoplethysmography (PPG) signal. The click board exposes I2C interface of the analog front end. We will use I2C1 interface of the header on PocketBeagle® to communicate with the click board. This corresponds to 'Click board position #1' in the above header position figure.
The weather click board uses the BME280 sensor for temperature and humidity measurements. The weather click board exposes the I2C interface of the sensor. We will use I2C2 interface of the header on PocketBeagle® to communicate with the click board. This corresponds to 'Click board position #2' in the above header position figure. The following figure shows the positions of the two click boards on PocketBeagle®.
First, the USB1 port needs to be enabled and made into a “Host” USB port. This part needs a little bit of soldering.
The above figure shows how enable the USB1 peripheral. “VI” pin (VIN) needs to be connected to the “VB” (VBUS) pin. Additionally, to set the USB port to “Host” mode, “ID” pin needs to be connected to ground (GND). We can do this by using solder jumpers on the backside of PocketBeagle®. Now that USB1 Host port is enabled, we need to connect it to a USB breakout connector. To do this, a small solderless breadboard can be used. First, wire up connections as shown in the following figure.
The wiring setup as shown requires the header pin 1 of PocketBeagle® to be inserted in Row 2 and the USB breakout board header pin 1 to be inserted in Row 25. Please note that while the power (VBUS) and ground (GND) wires can be different lengths, the D+/D- wires (i.e. the two middle wires) should be the same length. Additionally, a piece of double-sided sticky foam can be placed on the breadboard to provide mechanical support to the USB breakout board. The following figure shows PocketBeagle® with the two click boards and the USB port installed.
Use a Micro-USB to USB cable to connect PocketBeagle® to a computer/laptop. You should be able to bring up the Cloud9 IDE by entering the URL: http://192.168.7.2:3000/ide.html into the web browser. (use http://192.168.6.2:3000/ide.html for MAC o/s) Make sure you are using Chrome or Firefox. The IDE should look like the following figure:
The Python code for this project relies on some external packages and code repositories. To install these things, you will need to first connect PocketBeagle® to the internet. You can either use this tutorial on how to connect to the internet or you can use a USB WiFi adapter to connect directly to a WiFi router that can provide internet connectivity.
You will eventually need to use the WiFi adapter to connect to the IoT gateway but first we need to setup the software. This section will go through how to connect to a WiFi network and can be referenced later. If you only want to see the sensor outputs on a terminal in Cloud9, you do not need a WiFi adapter.
First, install the USB WiFi adapter as shown:
In a Cloud9 terminal, run the command 'ifconfig'. The output should show a "wlan" interface as shown below:
debian@beaglebone:/var/lib/cloud9$ ifconfig lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 ... wlan0: flags=-28669<UP,BROADCAST,MULTICAST,DYNAMIC> mtu 1500 ether 74:da:38:ed:7f:7f txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Now we can use the "connman" program to connect our WiFi adapter to a WiFi access point. You will need to run the following commands:
debian@beaglebone:/var/lib/cloud9$ connmanctl connmanctl> enable wifi Error wifi: Already enabled connmanctl> scan wifi Scan completed for wifi connmanctl> agent on Agent registered connmanctl> services octavo_guest wifi_xxxxxxxxxxxx_xxxxxxxxxxxx_managed_psk ... connmanctl> connect wifi_xxxxxxxxxxxx_xxxxxxxxxxxx_managed_psk Agent RequestInput wifi_xxxxxxxxxxxx_xxxxxxxxxxxx_managed_psk Passphrase = [ Type=psk, Requirement=mandatory ] Passphrase? xxxxxxxxxxxx Connected wifi_xxxxxxxxxxxx_xxxxxxxxxxxx_managed_psk connmanctl> exit
Occasionally, the WiFi adapter may not work (i.e. you will not see any services when you try to list the services) and needs to be restarted. This can be done using the 'ifconfig' command as well:
debian@beaglebone:/var/lib/cloud9$ sudo ifconfig wlan0 down debian@beaglebone:/var/lib/cloud9$ sudo ifconfig wlan0 up
Once you have connected to a network, the PocketBeagle® will try to reconnect to the same network on a reboot.
To install the system software, we will need to run the following commands:
sudo apt-get update sudo apt-get install git zip build-essential python-pip python-dev python-smbus
To install the python packages, we will need to run the following commands:
sudo pip install serbus
Note: You can also install "ez_setup" in case you want to install the Adafruit Python modules. However, this is not necessary given the PYTHONPATH settings in the 'run.sh' script.
To install the necessary Adafruit code repositories, we will need to run the following commands (Note: the 'run.sh' script assumes that these commands are executed in the /var/lib/cloud9 directory):
git clone https://github.com/adafruit/Adafruit_Python_PureIO git clone https://github.com/adafruit/Adafruit_Python_GPIO git clone https://github.com/adafruit/Adafruit_Python_BME280
The Weather Click Board uses a different I2C address setting than the default address in the Adafruit_Python_BME280 library. Therefore, we need to edit Adafruit_Python_BME280/Adafruit_BME280.py to change the I2C address of BME280 from 0x77 to 0x76:
nano Adafruit_Python_BME280/Adafruit_BME280.py < ---- change line ---- > # BME280 default address. BME280_I2CADDR = 0x76
At this point, we can now install the health monitor code. Download 'health_monitor.zip' from this project and place that in the /var/lib/cloud9 directory. Unzip the file:
Then we can run the 'run script' that will set up all of the environment variables for the program:
The program should then run and produce output that looks like:
Initializing Temp/Humidity Sensor Initializing Heart Rate Sensor ..........................................done. Starting Health Monitor | Heart Rate | Temperature (C) | Humidity (%) | Pressure (kPa) | |------------|-----------------|--------------|----------------| | 0 | 33.473 | 20.86 | 101.32 | | 72 | 33.395 | 23.68 | 101.32 | | 78 | 33.452 | 22.22 | 101.32 | | 78 | 33.638 | 23.55 | 101.33 | ^C--- 33.80 seconds ---
To stop the program you can press "Ctrl-C".
If we would like to use the IoT Gateway, we need to do a few more things.
First, make sure that the USB WiFi adapter is installed, and that the health monitor is connected to the IoT Gateway (See Step 4 above for instructions on how to do this). Then we need to install the IoT Gateway code attached to this project ('sensor_gateway.zip'). The IoT Gateway code creates a command line interface to transfer data from a client sensor to an IoT Gateway.
Download 'sensor_gateway.zip' and drag it into the /var/lib/cloud9 directory.
Unzip the file:
Then we need to build the executables:
cd sensor_gateway/ make
When this is done, you should see the executable 'msg_client' in the /var/lib/cloud9/sensor_gateway directory.
Now, you can run the health monitor code and it will transmit the results to the IoT Gateway. If the health monitor is not connected to the IoT Gateway, then you will see:
Initializing Temp/Humidity Sensor Initializing Heart Rate Sensor ..........................................done. Starting Health Monitor | Heart Rate | Temperature (C) | Humidity (%) | Pressure (kPa) | |------------|-----------------|--------------|----------------| | 0 | 33.473 | 20.86 | 101.32 | unable to connect to server 192.168.0.1 on port 50000 Cannot transmit results! | 72 | 33.395 | 23.68 | 101.32 | Cannot transmit results! | 78 | 33.452 | 22.22 | 101.32 | Cannot transmit results! | 78 | 33.638 | 23.55 | 101.33 | ^C--- 33.80 seconds ---
Please check the connection to the IoT Gateway to resolve this error.
The message format that the health monitor uses to transmit the data to the IoT Gateway is:
HR [Heart rate]bpm [Temperature]C [Pressure]kPa [Relative Humidity]%
An example of this would be:
HR 94 31.728 102.36 37.57 HR 95 32.004 102.32 41.69 HR 93 32.259 102.29 41.32
This data can be parsed, analyzed, stored, and/or displayed depening on the end application.
At this time, we have not published the project that shows the full functionality of the IoT Gateway. Please check back in the future for a link to that project.
Currently, the IoT Gateway message client is hard coded to use a "msg_id" of 10 and a "src_id" of 200. By modifying the message client code to take both "msg_id" and "src_id" as command line input, it would be easy to pass that information in as part of the health monitor Python code. This could then be further extended so that the health monitor itself took in an ID that would allow the IoT Gateway and cloud infrastructure to support multiple health monitors.
This project shows how easy it is to prototype IoT measurement systems such as health monitors by using low cost and easy to use open hardware, such as PocketBeagle® featuring the OSD335x System in Package along with Click Boards, as well as the associated open software resources. We hope you build your own health monitor and enhance the project.