Raspberry Pi practice problem · Projects
Bike computer
HardBudget $12Python · gpiozero
A cycle computer. A magnet on the wheel closes a switch once per turn; here that switch is a button on GPIO26. The wheel's circumference is 2.1 m. A 16×2 LCD (I²C 0x27) shows:
Speed: 12.6 km/h
Dist: 23 m
- Speed comes from the time between the last two pulses: 2.1 m ÷ that time, in km/h, with one decimal. Before the second pulse, and once 3 s pass without a pulse, it shows
0.0. - Distance is 2.1 m per pulse, in whole metres (rounded).
- Update the display at least 5 times a second.
The test rides at 12.6 km/h (a pulse every 0.6 s from 1.0 s to 4.0 s), speeds up to 18.9 km/h (every 0.4 s from 4.4 s to 6.0 s), then stops.