The Silent Killer is how people in the medical field refer to High Blood Pressure or Hypertension. They also give the same title to diabetes, prostate cancer, and even Carbon Monoxide. Today we will only focus on Hypertension because according to American Heart Association, if left undetected (or uncontrolled), high blood pressure can lead to many things including heart disease. That in turn, according to the Centers for Disease Control and Prevention (CDC), is the Leading Cause of Death in the United States of America. Among other organizations, the International Society of Hypertension (ISH) also echoed those findings and the importance of accurate measurement.
Now that I got your attention, my imaginary legal team advised me to give the following disclaimer:
Statements made here have not been evaluated by the Food and Drug Administration. This product is not intended to diagnose, treat, cure, or prevent any disease.
I'm not a Doctor, and I've never even played one on TV. I should also mention that any resemblance to reality is purely coincidental.
We're all waivered-up, let's get this show on the road.
Game PlanThis is my second posted project with AVR-IoT WG board. In the first project we connected the board to a private Google cloud, saved all received data in Firebase, and displayed only the most recent Blood Pressure Monitor (BPM) data in Google Sheets. In this project we will save all data directly in Google Sheets. We will use Arduino IDE for this project because it lowers the barrier to entry for many new makers. I'm using Google sheets after receiving good feedback regarding my previous AVR-IoT WG project and Helium Network GPS Tracking Directly In Google Sheets project.
AVR-IoT WG will connect to Wi-Fi and send data to Google Sheets which means we will code only in Arduino IDE and Apps Script. Once a connection is made, BPM will take measurements and results will be sent with a simple HTTPS POST request. Apps Script will then parse the data and populate Google Sheets.
If you recall in the introduction we talked about "the importance of accurate measurement". The National Center for Biotechnology Information of National Library of Medicine of National Institutes of Health of U.S. Department of Health & Human Services studied the effect of ambient temperature on blood pressure:
Therefor, we will not only send Systolic, Diastolic, and Heart Rate values, we will also send the ambient temperature along with a timestamp to give our data some context for more accurate interpretation by healthcare professionals. Finally, to make data more accessible, we will present it in Google Sheets format.
Couple of things to note before we dive in:
- Topics will be introduced in this tutorial in the order they became relevant to the evolution of the product
- Text Fragments, i.e. "<URL>#:~:text=<first word>, <last word>" are used to highlight a single point, and that should not be taken out of context
This is one of the most useful diagrams in the documentations. We can get few bits of information from AVR-IoT_WG_Schematics.pdf. The first thing we need is the I2C address of CryptoAuthentication so we can get the serial number and avoid manually hard coding values in every device we deploy. The next I2C address we need to get is the Temperature Sensor's.
We don't need to do anything with SPI since ATmega4808 and WINC1510 already connected. However, we need to find from the schematic pin numbers for CHIP_EN, RESET, WAKE, and IRQN. We could also get the same information from MPLAB X IDE.
The AVR-IoT WG development board combines a powerful ATmega4808 AVR® MCU, an ATECC608A CryptoAuthentication™ secure element IC and the fully certified ATWINC1510 Wi-Fi® network controller - which provides the most simple and effective way to connect your embedded application to Google’s Cloud IoT core platform. The board will be used to take data from non-smart BPM and send it to Google cloud.
While waiting for my BPM to arrive, I stumbled upon a video on YouTube where Circuit Desolator took apart three different BPMs. His goal was to tap into Electrically Erasable Programmable Read-Only Memory (EEPROM) via Inter-Integrated Circuit (I2C) bus on each device. Once a device finishes measuring, it will save the results in EEPROM then data can be easily retrieved. This method requires some disassembly and precision soldering. For me that would be plan B.
My idea is slightly different. I took apart my BPM as soon as I received and tested it then I looked for a Serial Port. Best case scenario, I'll find the four holes of Universal Asynchronous Receiver/Transmitter (UART) next to each other and I'll have to find out which one is Vcc, GND, Tx, and Rx.
The second challenge is figuring out the voltage level. It is unlikely the voltage level would be 5 Volts since this BPM operates on two 1.5 Volts batteries. I measured 3.3 Volts and now I'm ready for the next challenge which is finding the Baud Rate. I used my FTDI and the following Python script to answer that question:
import serial.tools.list_ports as ports
import serial
BaudRates=[110, 150, 300, 600, 1200, 2400, 4800, 9600,
14400, 19200, 28800, 31250, 38400, 57600,
115200, 128000, 230400, 256000, 460800, 921600]
for p in ports.comports():
for b in BaudRates:
with serial.Serial(p.device,b,timeout=3) as s:
print(s.name + ' ' + str(s.baudrate) + ' ' +
s.read(100).decode('unicode_escape'))
exit()
I had to turn the BPM on to start reading from UART. The baud rate that gave me readable text was 38400. That number will be used by one of AVR-IoT WG's USARTs to read data from BPM.
If you feel uncomfortable around Python (ophidiophobic), you could also reach the same conclusion by using Arduino IDE Serial Monitor and try all Baud Rates in the lower right corner of the window.
Before we leave this section I wanted to point out that I preferred to use UART over I2C because I wanted to have the ability to expand on this project in the future. In addition to reading from the device, we can also write to the device via UART. For now, we just connect power and ground of AVR-IoT WG to BPM, and Tx of BPM to Rx of AVR-IoT WG. One more connection is needed between AVR-IoT WG and BPM On/off button. We need that because as soon as we supply BPM with power it goes into settings mode. Therefore, we need to get out of that mode then turn the device on to commence the measurement process.
Software - Arduino IDEFirst of all; we need to install the board in Arduino IDE following steps listed here. We also need to install three libraries for CryptoAuthentication, Wi-Fi, and temperature sensor.
The only modification that needed to be done outside Arduino IDE is in C:\Users\<login>\Documents\Arduino\libraries\ArduinoECCX08\src\ECCX08.cpp because that file uses 0x60 as I2C address. The I2C address of CryptoAuthentication that we obtained above was 0x58. Therefore, we needed to change:
ECCX08Class ECCX08(Wire, 0x60);
to
ECCX08Class ECCX08(Wire, 0x58);
One thing to note here is the I2C address in MPLAB X IDE is 7-bit left-aligned (0xB0) so we can't just use it without shifting right (divide by 2) first.
Please note that we used pin numbers in C:\Users\<login>\AppData\Local\Arduino15\packages\MegaCoreX\hardware\megaavr\1.0.6\variants\32pin-standard\pins_arduino.h
Software - PlatformIO (Optional)The same Arduino code works in PlatformIO. The file platformio.ini should include the following:
[env:avr_iot_wg]
platform = atmelmegaavr
board = avr_iot_wg
framework = arduino
build_flags = -DARDUINO_AVR_ATmega4808
upload_protocol = pkobn_updi
lib_deps =
arduino-libraries/WiFi101@^0.16.1
adafruit/Adafruit MCP9808 Library@^2.0.0
arduino-libraries/ArduinoECCX08@1.3.5
Notice that we have to update I2C as shown above once PlatformIO installs the library for us.
Software - Apps ScriptWhen you make an appointment with a doctor, they ask you to show up 15 minutes early to fill out three sets of paper with the same information you already provided when you registered online. That is, you write down your name, address, phone number, and you Social Security Number three times on papers that nobody will ever look at. If you didn't have Hypertension before you walked in, now you do.
Seriously though, it is unrealistic to expect people with that level of technology awareness to transition straight from paper to the cloud. We used the same Google Sheets and Apps Script from the previous project. We added doPost function to handle POST request made by AVR-IoT WG.
ConclusionWe may not be able to use BPM as a lie detector like Dwight Schrute claimed. Nonetheless, we were able to use AVR-IoT WG to send BPM readings to Google Sheets by an easy and secure process.
This device can be used by patients in the days or weeks leading up to a doctor visit. It can also be used when changing medication is critical to blood pressure. The last use case we want to mention here is the use in epidemiological surveys like the one highlighted the effect of ambient temperature on blood pressure readings.
DemoFull disclosure: Hackster kindly sent me only one AVR-IoT WG device. I had to create 6 more readings in the database to simulate entries from multiple devices. At the end of each line, I added a color based on my interpretation of chart below.
The top few rows came from the previous project and kept here for comparison. We can barely hear the sound, but as soon as BPM finishes reading, the data shows up in Google Sheet almost instantly.
Comments