Hey, I'm really pleased with how this is going. This is still a prototype but it's functionally complete and works very well. It's messy because I hacked up a generalized arduino proto-shield to mount it but there's really not a lot to the hardware and now that it's working I can refine it to something much smaller and neater. The functions that are there at the moment are speedo, tach, and gear indicator the speedo and tach are dead accurate and the gear indicator responds very crisply to shifting up or down.
Actually, if you think this is messy, have a look at yesterdays incarnation which had a bluetooth module on it. I rode around with my laptop in a backpack for 20 minutes gathering data.
Hardware
Underneath the protoboard is a standard arduino. It's getting fed pulses from the bike's tachometer circuit, a reed switch senses wheel rotation, and there's a connection to the neutral light. The sort-of-beige connector on the left carries the connections from the bike and the round barrel connector goes from the power resistor on the protoboard to the arduino's regulator.
A lot of the complexity comes from interfacing with the bike's electrical system: There's a power resistor to take a bit of a load off the regulator and there are resistor divider networks to bring the tach signal and the neutral light connection under 5 volts. There's also a debounce circuit for the reed switch. Otherwise it's all software.
Software
The code is mostly not too tricky. At each wheel pass it calculates wheel speed in RPM and then divides that into the most recent engine RPM. The ratio is unique for each gear ranging from around 12 in 1st gear to around 4.5 in 5th gear. I require 2 consecutive wheel passes to give the same result before I accept the gear change.
This all sounds ok on the surface by the way but what you're really doing is counting how many times the engine turns while the wheel turns once. The answer is a smallish integer generally in the range of 4-12 but depending on the exact coincidence of engine and wheel you could get an answer of 4,5, or 6 in 4th gear and the possibilities for 5th and 3rd fully overlap these. Taking the time for each rather than actually counting works pretty well. When I was monitoring with bluetooth I saw a few false selections but none that persisted long enough to get to the display.
I said the code was mostly not too tricky, the exception is in the interrupt handling. My standard way of handling interrupts is to queue them in a log which I peel off in the “loop” function. This lets me put all kinds of debugging stuff in the code without worrying about missing interrupts. Because the tach interrupts can be fairly quick – maybe 100 a second, I bulk them up by only logging every 10th one. This probably doubles the amount of code but I'm used to it and the flexibility is great.
Next Steps
I'm going to redo the hardware based on an RBBB circuit board from Modern Device Company with a section of vero-board or other prototype PCB beside it rather than above it to hold the dividers and debounce circuits. It should be easy to get this into a package that can go inside the tank console instead of being glued to the top.
I'll use the same software for now but I'm dreaming up functions I can add. I want to do some work with 0-60 timing and wind resistance calculations. I also have a notional idea of getting rid of the tank console indicators and do a little strip of lights on the handlebars.