Thank you for your consideration, all. FWIW, the old Wees can be had at very reasonable prices and they seem to hold up well. The newer bikes have GPI and volt meters built in - having built one for my older 07 makes it just that much better! Ride safe.
The Wee generates the required signal as a discreet value - no need to manipulate rpm and speed to figure out the gear (that said, my next project for another bike will do that.) That made this project easier.
I've posted the code below. There are two computations going on; the top portion is reading the GPI input, figuring the gear, and displaying it. (I'm using a 4 digit 7 segment LCD display with backlighting - it's large so my tired old eyes can see it.) The bottom portion is figuring out the battery volt level from a voltage divider in my project box and displaying that. There is a push button on the project box to select the GPI or voltage.
There is a delay in the code that allows me to switch to the desired display more easily. I avoided any averaging of GPI data because I want to see that display change quickly - such as when I am coasting and downshifting into a stop light or stop sign.
// note that the backlight draws 3.5 ma and can be run directly from the arduino
#include <SPI.h>
// 0 1 2 3 4 5 6 7 8 9 -
const uint8_t nums[] = {
0xEE, 0x22, 0x7C, 0x76, 0xB2, 0xD6, 0xDE, 0x62, 0xFE, 0xF6, 0x10 };
const uint8_t dot = 0x01;
bool column = true;
uint8_t display[5];
int GearPin = 0; // The Gear "pink" wire is connected to analog pin 0
int BatteryPin = 2; // The Battery wire is connected to analog pin 2
int ButtonPin = 7; // The button is connected to digital pin 7 as an input
// use a pull down resistor
int BLAPin = 5; // The LCD display backlight is connected to digital pin 5 as a PWM output
int Gear = 0;
int ButtonPushCounter = 0; // counter for the number of button presses
int ButtonValue = 0; // current state of the button
int LastButtonValue = 0; // previous state of the button
int GearValue; // to store the value of the Gear
int BatteryValue;
int GrossedUpBatVal;
int ConvBatVal2;
int ConvBatVal = 1400;
void setup()
{
pinMode(ButtonPin, INPUT);
pinMode(BLAPin, OUTPUT);
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV128); //this line slows the clock down
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE2);
/*
At CPOL=1 the base value of the clock is one (inversion of CPOL=0)
For CPHA=0, data is captured on clock's falling edge and data is propagated on a rising edge.
Mode CPOL CPHA
0 0 0
1 0 1
2 1 0
3 1 1
*/
//Serial.begin(9600);
// analogWrite values from 0 to 255
analogWrite(BLAPin, 100); // this turns on the backlighting at reduced level
}
void loop()
{
delay(500); // repeat once per .5 second (change as you wish!)
ButtonValue = digitalRead(ButtonPin);
if (ButtonValue != LastButtonValue) {
if (ButtonValue == HIGH) {
ButtonPushCounter++;
}
else {
}
}
if (ButtonPushCounter % 2 == 0) //even number of pushes will show gear, odd will be battery
{
GearValue = analogRead(GearPin);
GearValue = GearValue * 5/ 10.23; // this turns the volt value from 0 - 1023 to 0 - 5
if (GearValue < 166) {
Gear = 1;
} //these volt values have been multiplied by 100
if (GearValue >= 166 && GearValue < 218){
Gear = 2;
}
if (GearValue >= 218 && GearValue < 291.5) {
Gear = 3;
}
if (GearValue >= 291.5 && GearValue < 372) {
Gear = 4;
}
if (GearValue >= 372 && GearValue < 438.5) {
Gear = 5;
}
if (GearValue >= 438.5 && GearValue < 480) {
Gear = 6;
}
if (GearValue >= 480) {
Gear = 10;
}
display[00] = 0x00;
// the colon is off and note that 00 in the display is really 0
display[1] = 0x00;
display[2] = 0x00;
display[3] = nums[Gear];
display[4] = 0x00;
for (uint8_t i = 0; i < 5; i++)
SPI.transfer(~display*);*
-
column = !column;*
-
} *
else
-
{*
-
BatteryValue = analogRead(BatteryPin);*
_ GrossedUpBatVal = BatteryValue * 14.68/4.68; //gross up back to pre-divider value adjusted to give an accurate result _
_ ConvBatVal2 = GrossedUpBatVal * 5/ 10.23;_
_ ConvBatVal=ConvBatVal * .9 + ConvBatVal2 * .1;_
-
display[0] = 0x00; // the colon is off*
-
if (ConvBatVal <1000) {*
-
display[1] = 0x00;*
-
}*
-
else {*
-
display[1] = nums[((ConvBatVal - (ConvBatVal % 1000)) / 1000)];*
-
}*
-
display[2] = nums[((ConvBatVal % 1000) - (ConvBatVal % 100))/100] | dot; //Hundreds with decimal point on*
-
display[3] = nums[((ConvBatVal % 100) - (ConvBatVal % 10))/10]; // Tens*
-
display[4] = nums[(ConvBatVal % 10)]; //Ones*
-
for (uint8_t i = 0; i < 5; i++)*
_ SPI.transfer(~display*);_
_ column = !column;_
_ }*_
* }*
[/quote]