Techie Tinkering: StepCounter 6.0
Giving My Treadmill a Brain
ChatGPT really delivered on this one! "Draw a cartoon of a treadmill walking, with a cartoon brain added to its head" |
Long-time readers will remember the main issue I have with my desk treadmill from my acclaimed article about it: it’s dumb.
Whilst the treadmill came with a companion app, it required me to start and stop the treadmill via this app in order to collect any usage stats. And there was no option to export that data. That was the spark that led to StepCounter 6.0, a project to give my treadmill a brain.
The Plan
- I'd get one of these little screens, which I could program to record how many steps I'd done:
The screen is 0.99" across. Diddy. |
It contains a Raspberry Pi Pico and an accelerometer—all for under £20.
- I'd write some simple step detection and logging logic.
- And it would just work, without me needing to start or stop anything.
Requirements
-
Wait until I start walking.
-
Detect steps using accelerometer data and count them.
-
Start recording after 10 consecutive steps.
-
Stop counting when I stop walking.
-
Save the session to a file.
-
Change screen colour every 1,000 steps for a quick visual update.
And repeat!
Simple enough, right?
The Code
Aside: Whilst a relatively small project, it's still a pain when you forget to save your progress at all and your system reboots. Being a simple thing, the Thonny IDE offers zero auto-recovery and it turns out I'm used to things just autosaving... So had to completely restart the project several hours in. :(
The tricky bits
Detecting actual steps took a few minutes to figure out, in the end it was quite straightforward:
-
Look for changes in accelerometer readings above a certain threshold.
-
Don't resample for a (brief) period of time to avoid double-counting.
MicroPython is also so small that some quite basic things are missing. Notably I wanted to calculate the length of a walking session by finding the difference between the start and end times. The easiest way of doing this was to work it out from first principles. This was largely fine, but catching all the edge cases took a bit of thought. I was struck that this was the kind of problem that's an excellent candidate for TDD.
Let's 3D print something!
You know me, never one to let a project go by without 3D printing something. I thought it would be helpful to have some kind of bracket the device could sit in - enabling me to remove it from the treadmill without having to restick it every time. I went through several design iterations starting with clips, moving on to screws and finally ending with a simple friction push-fit design.
Sometimes the simplest solution is the right one. |
Testing, Testing…
I started with short sessions to dial in thresholds, timing, and verify file saving and colour logic. I'd count to 100 as I stepped and see how many steps the step counter thought I'd done:
- 8/10 times step counter said I'd done 100 steps, the other two times, it said 101
- 2 steps extra over 1000 steps sounds like a reasonable level of accuracy for my purposes
I quickly became more confident in the step counter than the app - and as I'm taller, I'd not be surprised if I took fewer steps in a fixed distance than someone of average height.
It hadn't really occurred to me that the step count in the app might be that far off...So in retrospect I feel like that difference alone entirely validated my doing this project :)
Demo
I suppose I should show you 4 seconds of the step counter attached to the treadmill with the number ticking up...
Results
If I'm honest, the step counter works better than I expected - it's simple and just works the way I wanted it to - and with really quite a good level of accuracy.
I enjoyed getting this thing working - it was a fun “bite-sized” project with a practical application.
And I'm actually getting the data I'm interested in and consequently feeling more motivated to keep on walking on the treadmill. Result!
What’s Next?
-
Make it run without being tethered to the computer (a 30 second job. honest.)
-
Attach the bracket more permanently to the treadmill - its held on with masking tape at the mo!
-
Work out a clean way to sync data somewhere useful
The end. Thank you!
You don't have to go home, but you can't stay here.
Etc.
:)
Oh, by the way, ChatGPT wrote this
(and I rewrote it)
For something like this, which is more about showing what I've been up to, I quite like the brevity. For more of a "thought piece" I know my audience would miss my more rambly style...so maybe I'll keep it mixed up.
Anyway, maybe a minor success... I'll keep you in the loop on future experiments!