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

  1. Wait until I start walking.

  2. Detect steps using accelerometer data and count them.

  3. Start recording after 10 consecutive steps.

  4. Stop counting when I stop walking.

  5. Save the session to a file.

  6. Change screen colour every 1,000 steps for a quick visual update.

  7. And repeat!

Simple enough, right?

The Code

Like other Pico projects I've done in the past, I used MicroPython, building on sample code provided with the device. It was a very small about of code (maybe 200 lines) to get the whole thing working.

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.

So the threshold and resample delay are the two main parameters you can tweak to fine tune performance.

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.

Cleaning the code also gave me a little pause for thought. I wound up with a number of nested conditionals, resulting in some arrow code. In some instances it would have been possible to flatten the code more at the expense of writing more complex conditionals, which would have been harder to read. Getting the balance right here was fun. 

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


Then I moved on to longer  longer sessions, so I could compare the output of my step counter against the treadmill's own app... and the results were interesting: 


StepCounter 6.0Treadmill app%
5397660981.66
3008352885.26
3619471976.69
3770470880.08
3438452675.96
2222254287.41

So my step counter consistently recorded 15-20% fewer steps than the treadmill app.

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! 

And goodnight.

You don't have to go home, but you can't stay here. 

Etc.

Etc.

:)

Oh, by the way, ChatGPT wrote this
(and I rewrote it)

I suggested in my last post that I might have ChatGPT write my posts for me based on slide decks. So I gave it a go on this post. The slide deck took about an hour, ChatGPT writing this post was instant and rewriting it took about another hour. Honestly, I'm not sure it saved a lot of time overall... But it was nice to have a straw man to edit rather than starting with a blank page. And I maybe feel the output is more succinct than it would have been had I written it myself from scratch. 

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!