Iteration 2 | Jack | HRV Micro:bit Research

Iteration #2 - Micro: Bit Research & HRV

Jack Duggan | 20094010 | IOT Apps

For the second iteration sprint of the module, I got hands-on with the Micro:bit. I had previously used these devices way back in secondary school for Leaving Certificate Computer Science, so the basics came back to me fairly quickly.

We were sent home to 'research' the Micro:bit, and become familiar with it's basic functionality, before class on Friday the 2nd of February. In the class, I worked alone (as we had an odd number of students present) with a Micro:bit V2, an expansion board for the Microbit, and a heart rate sensor.


Above is the physical setup
Below is the device output screen with my finger on the sensor. The top graph shows my pulse as analogue input as identified by the sensor. Some mathematics is performed (as shown under the below graph) that converts these pulse values to HRV (delta_t). This HRV value is then displayed on the 'boxier looking' graph underneath.


The way this second graph works, is it takes the peaks and the troughs of the pulse, and checks them against a value in an if/else statement. A bit of tinkering needed to be done, to adjust these values to be as consistent as possible. 


The main struggle was making sure that my pulse's 'wave' hit the specified threshold almost every time, while also pushing as close as possible to the maximum peak and minimum trough values. I implemented a visual display onto the Micro: bit LED screen that would show me the if/else triggering, live. This can be seen in the video linked below.



This solution still isn't perfect, however. As you can see from the graphs, there are still inconsistencies, such as random spikes that disrupt the accuracy of the graph. Occasionally, when all environmental factors are perfect (finger stays perfectly still, HR sensor stays tight to my finger, no spikes etc.) I could see smooth curves on the HRV graph rising and falling depending on my breathing, but it was tedious.

Leaving this Friday class, I was sent home with the Micro: bit expansion board and heart-rate sensor and tasked with investigating a bit deeper, and attempting to improve the experiment.
The first investigation was voltage disparity and how it could be negatively affecting the results. Micro:bit boards run at 3.3V, and the expansion board is classed for the same, with my board containing a 3V rechargeable battery. The heart-rate sensor is 'recommended 5V' however, and as such is likely receiving less volts than required. Such inconsistencies can lead to inaccurate readings and signal integrity deprecation, which in an experiment where precision is vital, is less than ideal.
I spent some time charging up the expansion board, to make sure it was operating at 'best' potential. As rechargeable batteries discharge, their voltage can decrease below what they're rated for. When we're already dealing with a voltage mismatch, this can cause further problems - not good. Such tests didn't produce much in the way of improvement unfortunately, nothing I could immediately tell. If charging up the battery does improve the results, I fear it may be negligible, in my case anyway.

I wanted to provide some feedback, or indication of the user's HRV to the solution. I experimented with sound, but didn't have enough time to get it working how I wanted.
The basic idea was to have the Micro: bit V2's built-in speaker play a note or melody, and have the tempo of that sound change in accordance with the user's HRV. Unfortunately, I couldn't get my HRV values to be reliable enough (as talked about enough) to really test and improve this idea - hopefully someone else did! 



For the next part of my take-home experimentation, I looked at adding a breathing pacer to the solution, helping the user time their inhales/exhales to try and help the overall accuracy. My immediately idea was to use the LED display to imitate a breathing pattern of some kind - I wanted to try and leave space for my other visual indicators, so decided to add my pacer to the outer LEDs on the board. Coding each LED change with the right timings would be easy - but long and annoying , so I decided to make use of GenAI - as I feel these kind of situations are ones where it should be embraced.

I've learned to become quite savvy with generative AI over the last few months, and have made the realization that context is everything. Ultimately, generative AI models can only produce up to the quality of what's supplied, i.e. "Garbage In, Garbage Out." To get a good response that works as intended, it's absolutely vital that you provide the model with as much context as possible.


I supplied ChatGPT with the following prompt:
Can you write me some Microbit code that acts as a pacer for breathing exercises.
My breathing will be 4 seconds in, 6 seconds out. I want a visual LED display of a circle/square ring around the LEDs building for 4 seconds, then going away for 6 seconds, to kind of represent breathing. This should only be activated when B button pressed.
A
ChatGPT quickly provided my with basic code, which I simply chucked in beside my existing code and tested, which can be seen in the video below. The result was perfect - even if it only currently works when the B button is pressed. This result was all down to the quality of the prompt - Let's run through it quickly.
  • I started by telling the model what I want it to at a fundamental level. I want it to write me some code, specifically for the Micro:bit.
  • I gave it context by telling it why I wanted the code, which is to work as a pacer for breathing exercises.
  • I then described in detail exactly how I want it to work. It should operate for 10 seconds (4/6), and the LEDs should pulse in accordance to these times.
If I told the model something like: "make microbit code for breathing pacer", it's going to struggle to produce anything meaningful.



I briefly looked into comparisons between the 3.3V Micro: bit we're currently using, and 5V systems such as the Arduino. I read an article to try and understand the differences - as I'm fairly unfamiliar with Arduino in general.

The GPIO pins on an Arduino can work with both 3V and 5V logic levels, rather than just 3V, like the micro:bit.

  • micro:bit is more powerful and contains more features in one single board, however Arduino can be connected to dozens of different extension boards for more advanced projects

The Micro: bit is easy, familiar and a great device, but the lower voltage could be an issue. It may be worth testing the setup using Arduino or another 5V system and see if the readings are improved.


I didn't get the time to dump readings to CSV, but I believe this could be useful. When we have the visual data in the numerical, cellular format that CSV offers, we can use Excel to filter out the outliers, eradicating those annoying spikes talked about above, and perhaps get a much better data source.

Other miscellaneous work I did over the week:
* Whenever I was in Tesco or some other toy-selling establishment, I tried to remember to look out for any cheap toys/items with LEDs or other in them, that could be turned into a bio feedback device. Ultimately didn't find anything.






Comments

Popular posts from this blog

Iteration 5.2 | Lock In | Jack

Week 1: HRV Review