It is important to explain how this project came about before diving in. When I applied for the free hardware, I didn't put too much thought into the idea. At that point I already submitted six good projects to three different contests, winning zero prizes. I was also waiting on the results of the latest contest that I submitted two projects to. So, my idea for Advanced Wearables contest was the same as the one I just built, a Smart Blood Pressure Monitor (SBPM).
Despite my best effort to get rejected, Nordic Semiconductor kindly sent me a free hardware bundle. I was so excited when I received my hardware because I will get to learn a lot of new things; however, I will not be building yet another SBPM.
"Why not a SBPM?", you might ask. Few reasons actually:
- I don't like it when Makers keep redoing their same old project with little to no improvement.
- Honestly, I don't think Bluetooth Low Energy (BLE) would add much value to that SBPM implementation.
- Upon reviewing the ideas submitted for free hardware, I found several SBPMs. So, now I know for sure what I will not be building.
- Last but not least, I think I have a better idea.
In addition to contest rules, we will commit to additional standards in this project. First, nRF5340DK will not be replaceable by a simple Smart Phone app. Also, nRF5340DK won't be made functionally redundant; as in using it with another MCU.
IntroductionWhen I built The AVR-IoT WG: Out for Blood Pressure Monitoring in Google it was meant to be the killer of The Silent Killer (High Blood Pressure or Hypertension). This project will be the killer of the killer of The Silent Killer.
You see, instead of checking blood pressure after the fact, we need a device that keeps Hypertension from happening in the first place. SBPM is a measurement reading device; we will build a device that facilitates preventive actions further upstream.
According to Mayo Clinic:
Exercise is a drug-free approach to lowering high blood pressure
Remember that drug-free thing, it'll come up again. The National Library of Medicine adds:
Running regularly decreases RBP
The one thing that helped me quit smoking after 14 years, and lower my blood pressure and heart rate was taking up running. To run more, I used several methods to reduce recovery time until my coach recommended a drug-free (see? told ya!) method called TENS or Transcutaneous Electrical Nerve Stimulation.
According to MedicalNewsToday:
TENS units work by delivering small electrical impulses through electrodes that have adhesive pads to attach them to a person’s skin. These electrical impulses flood the nervous system, reducing its ability to transmit pain signals to the spinal cord and brain. The same electrical impulses also stimulate the body to produce natural pain relievers called endorphins.
BTW, 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 started.
Game PlanThe main purpose of this project is not only to control TENS unit, but also to record the settings used for further analysis to determine which electrical impulse patterns work best for each muscle. As Peter Drucker once said:
If you can't measure it you can't improve it.
Unlike my previous project, we will not be using UART to communicate with TENS unit; we will use GPIOs to imitate button pressing. Every 10 second nRF5340DK will send the current settings to nRF52840 Dongle which will relay the information to WeMos D1 Mini via UART. Finally, the information will be sent to Google Sheets via Wi-Fi.
nRF5340DK + Adafruit 2.8" TFT Touch Shield for Arduino w/Capacitive Touch DisplayThe the star of the show is nRF5340DK which has been programmed using Segger Embedded Studio (SES) that came with nRF Connect SDK installation. The display fits nicely on the board, but in order to get it to work we have to apply a patch. More details are in Hung Bui's Webinar.
Once we make sure ncs-display-ble-example works, we can modify it to fit our project. We can keep LED Button Service (LBS) code in this project, but we need Nordic UART Service (NUS) to send text via BLE.
Plugging nRF5340DK to a computer will make it show up as a drive. We could just drag N-TENS.hex on that drive to load our code. We could also follow few simple steps to build the project from source in GitHub. First, We need the following structure to recreate this project:
Files and folders are bundled in N-TENS.zip. Next, open Toolchain Manager.
File > Open nRF Connect SDK Project...
Select Projects and Board Name.
Hold down Ctrl button then press and release T then press and release F5.
Our project is now loaded on nRF5340DK.
The unit we ended up using has 10 speed levels, 10 power levels, and 8 modes. All this plus on/off functionality controlled through 4 buttons only. This unit also has a countdown timer for 15 minute session.
We used pins P0.28, P0.29, P0.30, and P0.31 since they are already configures as outputs (LEDs) in:
C:\ncs\v1.5.0\zephyr\boards\arm\nrf5340dk_nrf5340\nrf5340_cpuapp_common.dts
From the same file, we also used P0.09 (Button 4 ) to send signal to Buzzer through 2N2222A transistor for amplification. This has been done to provide audible feedback to the user when screen is touched.
Instead of shared function buttons, we will use dedicated sliders to control speed and power level independently. As you may have already noticed, the sliders are abstract of a fusion between Nordic logo and Yin and yang. The display size is 320 X 240 and we had to plan the placement of sliders, button, and text.
Left slider will always control the speed level while right slider will always control power level. As a result, the user does not have to keep track of S/P button which is not shown on TENS unit display. As for the mode button, we've noticed that most of the 8 modes have the same rhythm. Regardless, we gave each mode a unique letter even if descriptions are the same just in case they affect muscles differently. Mode can be changed by pressing the button between the two sliders. That's it, two sliders, one button, text at the top to show advertising name and BLE connection status, and text at the bottom to show how long the device have been running.
Like the case? Upcycled from a previous project after making it Blue.
The small window on the right is for demo verification only. The final product should have the touch screen only which has all the controls and information.
nRF52840 DongleAccording to the contest rules:
The nRF52840 Dongle is a complementary device included in the bundle and is not required to be used in the project.
That being said, I really appreciate Nordic Semiconductor including it in the bundle. I started to use SES and write the resulting HEX file using nRF Connect Programmer then I switched to CircuitPython. I know it's a little slower to run, but it's faster to develop and load.
rdagger68 has an awesome video to get us started with CircuitPython on nRF52840 Dongle. Everything was going great in that tutorial until he started writing code. It took me a while to figure this out, but CircuitPython is relatively young (8+ years old) and few things have changed in the past couple of years. For example, you'll see that I had to use "adafruit_ble.services.nordic" for UART in my code instead of "adafruit_ble.uart". Nonetheless, we had more success using CircuitPython on nRF52840 Dongle than on any other board.
Since nRF52840 Dongle offers the flexibility to chose pins, I soldered 8 adjacent pins on one side only to include VBUS and GND (P0.02 and VDD OUT are not connected).
Writing code in Mu is pretty straight forward; however, we didn't really need it. We could've just use any recommended text editor and saved the file as code.py on CIRCUITPY Drive.
Be aware that CircuitPython constantly looks for updated code file on the board to run. There are four options: code.txt, code.py, main.txt and main.py. CircuitPython looks for those files, in that order, and then runs the first one it finds.
As you can see in the screenshot above, code.py was not the only file needed to be copied on nRF52840 Dongle. CIRCUITPY.zip contains all files and folders needed to be copied.
WeMos D1 Mini & OLED DisplayWhat's square, blue, and smells like super glue?
If you guessed WeMos D1 Mini and OLED display in a dental floss case, you are correct. Otherwise, you can try again.
There is no direct connection between them, but they're both connected to nRF52840 Dongle. We had to make them separable because WeMos D1 Mini does not like anything on Tx and Rx pins while flashing. Speaking of WeMos D1 Mini, we went with Arduino IDE to take advantage of one of the best Wi-Fi libraries, WiFiManager.
To keep things simple, WeMos D1 Mini will connect to Wi-Fi then wait for a call from nRF52840 Dongle. Once that's done, WeMos D1 Mini will enter a loop to send via Wi-Fi any UART data received from nRF52840 Dongle.
Instead of making an opening for the display, OLED light goes through the dental floss case side to make the setup look more classy.
Google SheetsWe created Google Sheet to save our data and noted <SheetID>
We used the same <SheetID> in Google Apps Script
Data coming from nRF5340DK will be saved in the first column while the second column holds a timestamp.
Each cell in the first column will contain 8 alphanumeric characters. The first three numbers are elapsed time in seconds, the next two are the speed level, the only letter is the mode, and the last two numbers are the power level.
If the speed level, mode, and power level are the same as the previous cell, the new record will be deleted which means we will only keep a record if it contains a new settings value. To indicate the end of the session, the last record will always be 900 which is the amount of seconds in 15 minutes.
There's an app for thatGoogle Apps Script is expecting HTTPS post with payload {"report":"PlaceHolder"} and it does not matter if it comes from nRF52840 Dongle + WeMos D1 Mini or an app.
The main functionality of nRF5340DK can't be replaced with an app since it is controlling TENS unit and sending data. On the other hand, we could replace the nRF52840 Dongle + WeMos D1 Mini with an app on any smart device with BLE and Wi-Fi functionalities. The easiest way to do this is using MIT App Inventor which has been covered in one of my previous projects.
Note that app connects to N-TENS using name not MAC (loosely coupled).
Keeping it realWe did face issues, opportunities, challenges, and valuable learning experiences in the making of this project. Unlike Wally, we had to work through them. Thankfully, none was related to nRF5340DK because of how robust it is. The first causality was another more expensive TENS unit also with 4 buttons, but no display. Unlike nRF5340DK, TENS unit does not have short circuit protection. The second causality was a TENS unit similar to the one we ended up using here.
Just couldn't stop pushing the limits and trying new things as long as nRF5340DK kept going. I aspire to one day write code like Torbjørn Øvrebekk does. Until then, I will take projects like this as an opportunity to show that most of us don't just roll out of bed and cobble together some software and hardware to build a project.
ConclusionI hope you had as much fun as I did building this project. This has been a successful simple implementation of the powerful nRF5340DK. The board and nRF Connect SDK were not that hard to use and most of the project work was needed outside. I normally build multiple projects for every hardware I receive, but due to time constraints, I built only one big project with nRF5340DK. Nonetheless, I've learned a lot about BLE, Zephyr, CircuitPython, and other useful technologies.
DemoHere is the one minute Demo video required for BONUS - 15 points:
Comments