Version 2 with High Speed Dual Processor
I don’t know if this is the first bicycle with two separate arduino microprocessors but it’s certainly the first on my block!
Because the target platform for this project is my motorcycle I wanted to use this prototype to try out a few things. The first version worked very well at the speeds you see on a bicycle - 60-120 rpm pedaling and 100-150 wheel rpm. I needed to know whether the arduino could handle the motorcycle calculations at 7000+ engine rpm and 1000-1500 wheel rpm.
I decided to use a separate sanguino processor board which I had handy to boost the pedalling speed by a factor of 50 and to mount two extra magnets on the rear wheel so the wheel sensor would see 3 pulses for each rpm. This let me get the tach rpm to wheel rpm for 2nd, 4th, and 6th gears on the bicycle to be roughly the same as the ratios for 1st, 2nd, and 3rd gears on the motorcycle. For example pedaling 60 times a minute on the bicycle in 2nd gear its wheels are going around 95 times a minute. In my simulation this would look to the arduino like 3000 engine rpm and 285 wheel rpm which is a bit like the motorcycle going 20mph in 1st gear. I wasn’t trying for accuracy, just the same range of numbers.
As it happened, I couldn’t get the wheel magnets placed evenly enough to provide decent results so I ended up just multiplying the wheel rpm by 3 in the arduino code. I could see that it was having no trouble at all dealing with the “engine” pulses even at a simulated 8500 rpm so I don’t see any problem moving to the motorcycle.
The Arduino board is much the same as the original. The de-bouncing hardware for the pedal sensor is gone because the signal from the sanguino booster is clean. The de-bouncing hardware for the wheel sensor has been replaced by a resistor and capacitor required for the hall effect switch. I also changed out the smaller red radio shack led display I’d been using for a larger bright green one from Jameco.
The code for the sanguino was a bit tricky. There’s an interrupt routine that calculates the time between pedal revolutions and a main loop that calculates 1/50th of that time then continuously issues pulses that length. So if the pedal goes around once a second the sanguino divides 1000 msec by 50 and starts issuing 2 msec pulses every 20 msec. I ran into some odd problems with the timing because the arduino delay() function adds more-or less 1 msec to each execution – I ended up unrolling the delay() function into my own code. Thanks to JCW and Mekon83 on the arduino forums for giving me enough knowledge to be dangerous (the code for both the sanguino and arduino are posted below).
The code for the Arduino stayed pretty much the same with interrupt routines logging the events in a table that is copied out periodically by the main loop. I made the table larger and I had the tach input log an entry every 10 interrupts and the wheel input every time. I also changed the gear ratio calculation to be based on tach rpm/wheel rpm rather than the reverse. Any other changes were minor or cosmetic.
Conclusions – Things I learned
- The arduino had no trouble at all with the interrupt rates. My table never got more than half full even with the booster pumping out 8-9000 events a minute (150/sec).
- 9V batteries suck. Each of these boards went through a couple of them in development.
- Even the brighter green LED isn’t bright enough for daylight use and the wiring is a hassle. I think the MC version may come to use an array of 5 discrete leds – one for each gear. If I use Charlieplexing to drive them I can stick the RBBB under the MC tank and run just a 3 conductor lead up to a little display on the handlebars.
- I now see this as entirely practical for the MC with very little hardware required. I’ll either tack the few extra components onto an RBBB or wire it up from scratch on perfboard.
Obviously I’ve actually got to get poking at the motorcycle pretty soon but I do want to try a couple of things first.
- Find out what the tach pulses look like on my bike or plan to use inductive input from the spark plug leads.
- Figure out how to run the RBBB or similar power supply in what I’m told is a noisy MC electrical environment
- Get a persistent bluetooth connection working so I can debug the motorcycle with my laptop by the roadside.
Again the writeup pics and code are hosted on a windows live blog at http://cid-6648e3bd665ceac9.spaces.live.com/blog/cns!6648E3BD665CEAC9!154.entry?&_c02_vws=1
- The original version of this project got a writeup on the make magazine blog which I thought was great. http://blog.makezine.com/archive/2009/03/arduino_bicycle_gear_indicator.html?
- We are heading home from our winter hideaway so i had to return the mountain bike i was using as my test mule. As I was making the 16 km trek it occured to me that it would, in fact, be nice to know what gear I was in! Maybe there is some point in the bicycle version after all.