tinker2much
Posts: 153
Joined: Wed Jun 20, 2018 12:38 am

A home-brew lap counter/recorder/calculator

Wed Feb 05, 2020 2:27 am

I've been walking a lot around an indoor track this winter. I want a device that will note the end of a lap every time I press of a button, calculate the elapsed time since last press and display that as most recent lap time, plus - at the press of another button - cycle through lap count/min/max/avg/median, plus total session time. Lap times are no more than two digits worth of seconds with perhaps a tenth for spurious accuracy. Total session times can be two digits worth of minutes, with tenths of minutes, ditto. I would like a way to easy offload the day's times to another device.

So I imagine I don't need a lot of parts here:
  • a pi Zero (maybe even an Arduinio, but I know nothing about those)
    a couple of buttons
    a modest NN.NM multi-segment display, where N is a number and M indicates mode (somehow)
    a custom case
    some kind of shim that allows:
    a battery pack for portability
I'm very familiar with the PI, totally unfamiliar with an Arduino, although I gather the Arduino could be fine for simpler use cases and also lower power.

This seems like a matter of ordering a few parts, hacking it together with some very simple software, and figuring out the case after I have the size and shape settled. Unless some electrical tape suffices.

Thoughts?

deepo
Posts: 431
Joined: Sun Dec 30, 2018 8:36 pm
Location: Denmark

Re: A home-brew lap counter/recorder/calculator

Wed Feb 05, 2020 9:54 pm

Why not go for a small OLED screen instead of those multi segment displays?
Like the Adafruit 128x64 OLED bonnet https://www.adafruit.com/product/3531
You even get buttons and a joystick on that bonnet.

/Mogens

tinker2much
Posts: 153
Joined: Wed Jun 20, 2018 12:38 am

Re: A home-brew lap counter/recorder/calculator

Fri Feb 07, 2020 12:56 am

deepo wrote:
Wed Feb 05, 2020 9:54 pm
Why not go for a small OLED screen instead of those multi segment displays?
Like the Adafruit 128x64 OLED bonnet https://www.adafruit.com/product/3531
You even get buttons and a joystick on that bonnet
Am I right that I would have to make up my own graphics for the numerals, coding in pygame? There are probably primitives that I could combine. I could also make up symbols and/or text for which mode I was in. This is very interesting.

PhatFil
Posts: 1615
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: A home-brew lap counter/recorder/calculator

Fri Feb 07, 2020 1:14 am

or pick up a cheap coin cell powered 433mhz button controller, and use your pi to receive the button code and host a web page with all the metrics/data/forcasts you want to display and use your phone or puter to view..

button ideas
https://www.aliexpress.com/wholesale?ca ... mhz+button


diy rf reciever h/w
https://www.googleadservices.com/pagead ... BBb&adurl=

alternative 433mhz receiver option
https://tasmota.github.io/docs/#/device ... Bridge-433

tinker2much
Posts: 153
Joined: Wed Jun 20, 2018 12:38 am

Re: A home-brew lap counter/recorder/calculator

Tue Feb 11, 2020 9:12 pm

Like the Adafruit 128x64 OLED bonnet https://www.adafruit.com/product/3531
You even get buttons and a joystick on that bonnet.
That seems like a good choice just for the display, PLUS I could use the buttons to click for each lap or for starting and stopping, AND the joystick to scroll through previous lap times, or previous days' results.

For power, I'm wondering about one of these two adafruit boards https://www.adafruit.com/product/1944 or https://www.adafruit.com/product/2465 which allow attaching (and boosting the voltage from) LiPo batteries. This article details how to attach it to the bottom of a zero[w], : https://github.com/NeonHorizon/lipopi. I was especially interested in that method of BOTTOM attachment, because it would leave the gpio header free on top to attach the display.

I need to figure out whether, bottom and top attachment aside, these two items would conflict over specific gpio pins.

deepo
Posts: 431
Joined: Sun Dec 30, 2018 8:36 pm
Location: Denmark

Re: A home-brew lap counter/recorder/calculator

Wed Feb 12, 2020 9:59 pm

Go for it.
Worst case would be that you can't connect any communication wires from the power supply.
But do you really need that, or is it nice to have?

/Mogens

tinker2much
Posts: 153
Joined: Wed Jun 20, 2018 12:38 am

Re: A home-brew lap counter/recorder/calculator

Wed Feb 12, 2020 11:40 pm

I need battery power somehow, to make it portable. I've never tried to power a pi via battery before, and this is the first solution I've looked into. What other types of battery-based solutions are there?

deepo
Posts: 431
Joined: Sun Dec 30, 2018 8:36 pm
Location: Denmark

Re: A home-brew lap counter/recorder/calculator

Thu Feb 13, 2020 8:13 pm

tinker2much wrote:
Wed Feb 12, 2020 11:40 pm
I need battery power somehow, to make it portable. I've never tried to power a pi via battery before, and this is the first solution I've looked into. What other types of battery-based solutions are there?
I didn't write you couldn't connect the power leads, only that you might not be able to add the communication wires.

/Mogens

Ramblin Wreck
Posts: 1
Joined: Thu Feb 20, 2020 3:33 pm

Re: A home-brew lap counter/recorder/calculator

Thu Feb 20, 2020 3:40 pm

Regarding a battery: I ran my Rasberry Pi Zero Wireless on a random cell phone power bank I had laying around...mainly just out of curiosity to see how long it would last. It ran for a few days before dying, during which it was just running a Python program to send an update to Twitter every 5 minutes to report that it was still alive. Seems like some sort of solution like that would be sufficient for daily usage.

tinker2much
Posts: 153
Joined: Wed Jun 20, 2018 12:38 am

Re: A home-brew lap counter/recorder/calculator

Mon Mar 02, 2020 1:25 am

tinker2much wrote:
Tue Feb 11, 2020 9:12 pm
Like the Adafruit 128x64 OLED bonnet https://www.adafruit.com/product/3531
You even get buttons and a joystick on that bonnet.
That seems like a good choice just for the display, PLUS I could use the buttons to click for each lap or for starting and stopping, AND the joystick to scroll through previous lap times, or previous days' results.

For power, I'm wondering about one of these two adafruit boards https://www.adafruit.com/product/1944 or https://www.adafruit.com/product/2465 which allow attaching (and boosting the voltage from) LiPo batteries. This article details how to attach it to the bottom of a zero[w], : https://github.com/NeonHorizon/lipopi. I was especially interested in that method of BOTTOM attachment, because it would leave the gpio header free on top to attach the display.

I need to figure out whether, bottom and top attachment aside, these two items would conflict over specific gpio pins.
I've leaped into the pool! I bought the OLED bonnet, the smaller boost/charger circuit, and a 2000mAh LiPo battery. I've soldered a header on a Pi Zero W that I had on hand, soldered a short micro-usb lead onto the charger board, installed a bunch of libraries, cloned the Adafruit git project that has the sample code, and gotten the whole thing to work together, cheers from the crowd!

Given that the hardware works , and given some good example code from Adafruit, I think I"m going to write my application code next.

Finally, I'll see how to cram everything together into some kind of case. I didn't think I was up to the fine soldering in that other link. I may go back to that later. It *would* add a bunch of integration between the pi and the battery and charger, and would make things as physically small as possible. For now, I just wanted to see that it all worked, and I'm OK with the extra cabling.

The attached picture shows the pi and bonnet running purely off battery power, with the sample app running.
Attachments
IMG_3823.JPG
IMG_3823.JPG (74.07 KiB) Viewed 1374 times

tinker2much
Posts: 153
Joined: Wed Jun 20, 2018 12:38 am

Re: A home-brew lap counter/recorder/calculator

Tue Mar 03, 2020 12:45 am

After I'd posted that picture, I realized that I had plugged the power into the data port. Even so, it seems to have worked fine. Hmmmm....

I've got it the right way now.

User avatar
rpdom
Posts: 16306
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: A home-brew lap counter/recorder/calculator

Tue Mar 03, 2020 7:35 am

tinker2much wrote:
Tue Mar 03, 2020 12:45 am
After I'd posted that picture, I realized that I had plugged the power into the data port. Even so, it seems to have worked fine. Hmmmm....

I've got it the right way now.
It doesn't really matter which port the Zero is powered from. The +5V and 0V lines are directly connected to both ports. Only the data port has the data lines connected.

deepo
Posts: 431
Joined: Sun Dec 30, 2018 8:36 pm
Location: Denmark

Re: A home-brew lap counter/recorder/calculator

Tue Mar 03, 2020 10:11 pm

Looking cool!
Good you took the jump!

/Mogens

tinker2much
Posts: 153
Joined: Wed Jun 20, 2018 12:38 am

Re: A home-brew lap counter/recorder/calculator

Mon Mar 09, 2020 1:21 am

Prototype!

Software: I hacked on the Adafruit sample app that shows how to use the buttons and joystick, and created something close to the functionality I want.

Hardware: I stacked everything into a fat sandwich, held together by rubber bands, and voila! a prototype I could take to the track:
  • Adafruit OLED display with controls
    A couple of plastic standoffs (cut from a cheap ballpoint pen, attached by short pieces of twist ties)
    Raspberry pi Zero with header
    a piece of insulating plastic cut from the lid of an oatmeal container
    Adafruit 2000mAh battery
    Adafruit 500C Li-Poly Boost and Charger board
    a piece of insulating plastic, ditto

I cut the micro-USB end off a short cable and soldered the wire end to the power out holes of the boost/charge board. Not beautiful, but easy to undo, and I can also unplug that and plug the pi into the mains whilst debugging, which I find I can only do when stationary ;-)

The trial was a success. I learned several things:
  • this is quite a chunky - and surprisingly heavy - little object
    my hand is big enough to comfortably hang onto it
    I can both hold it and press the button with one hand
    The buttons are small, with very little travel, so I sometimes wasn't sure whether a press had registered or not (I knew I hadn't when I pressed next time and had one lap of double length showed up
Here are some pictures. The specific features are subject to change.

The meanings of the numbers are:

Lap Time | average lap time | minimum lap time
Lap number | total number of laps | maximum lap time

By pressing button #5, you start the clock and also signal the end of each lap.

By pressing button #6, you pause the action - stop the clock - put things on hold (not yet working.)

By pressing the joystick in various directions (without pressing down) left, I can
  • Left: page back through the earlier lap times
    Right: page forward to a later lap time
    Up: Go to the first lap
    Down: go to the last/latest lap
By pressing the joystick down, and then also pressing in various directions, I can perform administrative functions:
  • Left: BEGIN - throw away any data so far and start the session over
    Right: WRITE the session's times so far to a csv file
    Up: EXIT the program
    Down: SHUTDOWN the pi
Here's some actual data: the first row is my real session, the second row is the fake one shown in the pictures.

2020-03-05_19:38:36,54,52,51,52,51,52,51,52,51,52,51,48,52,50,49,50,49,52,50,49,49,50,51,51,52,50,50,49,50,51,51,51,51,50,50,51,50,51,49,51,51,50,52,50,50,51,49,51,51,51,51,53,50,49,51,51,51,51,50,50,51,50,50,50,51,50,51,49,51,51,51,51,50,55
2020-03-08_19:39:13,8,8,6,8,9,8,10
IMG_3836.JPG
At the start
IMG_3836.JPG (80.92 KiB) Viewed 1135 times
IMG_3837.JPG
The sandwich
IMG_3837.JPG (75.57 KiB) Viewed 1135 times
IMG_3839.JPG
Bottom view
IMG_3839.JPG (61.15 KiB) Viewed 1135 times

tinker2much
Posts: 153
Joined: Wed Jun 20, 2018 12:38 am

Re: A home-brew lap counter/recorder/calculator

Mon Mar 09, 2020 1:26 am

I couldn't get more than three pictures at once. Here are some more.
IMG_3848.JPG
The usual display of numbers
IMG_3848.JPG (86.25 KiB) Viewed 1131 times
The above display means you're looking at the 7th lap, which took 10 seconds. The average lap time is 8 seconds, over 7 total laps. The minimum lap time was 6 seconds, the maximum lap time was 10 seconds.
IMG_3850.JPG
Administrative functions
IMG_3850.JPG (80.42 KiB) Viewed 1131 times
IMG_3853.JPG
Charging end
IMG_3853.JPG (76.18 KiB) Viewed 1131 times

tinker2much
Posts: 153
Joined: Wed Jun 20, 2018 12:38 am

Re: A home-brew lap counter/recorder/calculator

Mon Mar 09, 2020 1:42 am

And one last picture.
7C0D12F1-C0BB-40C3-A757-8252F76AD27E.jpeg
7C0D12F1-C0BB-40C3-A757-8252F76AD27E.jpeg (56.14 KiB) Viewed 1112 times

deepo
Posts: 431
Joined: Sun Dec 30, 2018 8:36 pm
Location: Denmark

Re: A home-brew lap counter/recorder/calculator

Mon Mar 09, 2020 7:51 pm

Looking good!

/Mogens

tinker2much
Posts: 153
Joined: Wed Jun 20, 2018 12:38 am

Re: A home-brew lap counter/recorder/calculator

Mon Mar 09, 2020 9:05 pm

The OLED screen isn't big enough to really see the data, so I always intended to make the zero into a web server. I've now done that.

I installed apache and I also wrote a simple awk cgi program that serves the csv lap times data as a web page.

This page COULD be viewed from the pi Zero itself (if I hooked it up to a monitor and keyboard and started Chromium), but that's a bother, and pretty CPU intensive. It's better to view the page from a more powerful computer with a nice big screen. Which works fine.

See attached image.
Laptrack data as web page.png
Laptrack data as web page.png (153.75 KiB) Viewed 955 times

tinker2much
Posts: 153
Joined: Wed Jun 20, 2018 12:38 am

Re: A home-brew lap counter/recorder/calculator

Mon Mar 09, 2020 11:35 pm

Added count/min/max/avg to the web page:
new_and_improved.scrot.png
Added count/min/max/avg
new_and_improved.scrot.png (81.57 KiB) Viewed 929 times

tinker2much
Posts: 153
Joined: Wed Jun 20, 2018 12:38 am

Re: A home-brew lap counter/recorder/calculator

Tue Mar 10, 2020 9:20 pm

After another real trial this afternoon, I added a total session time to the web page.
new_and_even_more_improved.scrot.png
Added total session time
new_and_even_more_improved.scrot.png (93.04 KiB) Viewed 842 times

tinker2much
Posts: 153
Joined: Wed Jun 20, 2018 12:38 am

Re: A home-brew lap counter/recorder/calculator

Tue Mar 10, 2020 9:32 pm

Given a couple of real trials, I have lots of new ideas for Laptrack (note the name change - it does much more than count laps. And "Laptrack" reminds me of "Laugh track" which is what ought to accompany an old guy like me getting athletic. )

I noted that it's hard to tell if the tiny button was actually pressed. If this lap's time is the same as last lap's time, all that changes is the lap number which is very tiny. Would it be possible to reverse black and white for a second - a kind of flash to indicate a key really pressed?

I would like to add a timer so I know when my hour's walk is done - counting up or counting down, or beeping or flashing when time's up

I have to get the pause/hold/time out functionality working, with a key press to start the pause and another key press to end the pause. I had been thinking of requiring the user to hold the button for the whole pause, that's too hard.

I will move the average time over to the right between the minimum and maximum times, and have the middle of the display just be a larger lap number. That will also make it more obvious that the key press succeeded.

The standard display is great as a summary of the session, but isn't so useful while actually walking. Perhaps I will make a really stripped down alternate display for while walking.

deepo
Posts: 431
Joined: Sun Dec 30, 2018 8:36 pm
Location: Denmark

Re: A home-brew lap counter/recorder/calculator

Wed Mar 11, 2020 8:22 pm

The adafruit_ssd1306.py seems to have an invert function:

Code: Select all

def invert(self, invert):
        """Invert all pixels on the display"""
So invert when button is pressed and invert again when button is released?

/Mogens

tinker2much
Posts: 153
Joined: Wed Jun 20, 2018 12:38 am

Re: A home-brew lap counter/recorder/calculator

Mon Mar 16, 2020 4:47 pm

various tweaks, some debugging

The normal display now has min/avg/max at the right.

There are more messages when doing administrative functions like "Write data".

The hold or pause functionality now works - press #6 once and let go to pause, press it again momentarily to resume.

The web page now displays most-recent sessions at the top.

You can restart the whole session, i.e. clear all the counts and be as if you had just started.

All going well, even the battery seems to last longer than I expected - at least 5 or 6 hours, though I should time it to be sure. That would be enough for a week's worth of walking.

tinker2much
Posts: 153
Joined: Wed Jun 20, 2018 12:38 am

Re: A home-brew lap counter/recorder/calculator

Mon Mar 16, 2020 4:49 pm

IMG_3886.JPG
initial display
IMG_3886.JPG (80.84 KiB) Viewed 324 times
IMG_3887.JPG
started, no laps finished yet
IMG_3887.JPG (76.93 KiB) Viewed 324 times
IMG_3890.JPG
a few laps in, see min/avg/max
IMG_3890.JPG (78.25 KiB) Viewed 324 times

tinker2much
Posts: 153
Joined: Wed Jun 20, 2018 12:38 am

Re: A home-brew lap counter/recorder/calculator

Mon Mar 16, 2020 4:51 pm

IMG_3896.JPG
admin functions
IMG_3896.JPG (85.8 KiB) Viewed 322 times
IMG_3899.JPG
nice message upon program exit
IMG_3899.JPG (83.84 KiB) Viewed 322 times
IMG_3904.JPG
shutting down
IMG_3904.JPG (85.76 KiB) Viewed 322 times

Return to “Other projects”