VPW, that's the Class 2 stream, right? I was looking into that as a possible source of input to get the RPM signal.
But first, I think I may have a math problem in the code above... I attached a pot to use for input, and I get a whole sweep from 0 to 7000, but it happens in large chunks rather than one segment at a time. Almost like it's only reading the MSB.
Code:
int potPin = 2;
int potVal = 0;
void setup() {
Serial.begin(8192);
}
void loop() {
delay(100);
if (Serial.availableForWrite() > 5) {
potVal = analogRead(potPin) * 7;
int rpm = potVal;
byte msb = floor(rpm / 256);
byte lsb = rpm % 256;
byte b[5] = {0x0A, 0x58, 0x00, msb, lsb};
unsigned int x = 0, sum = 0;
for (x = 0; x < sizeof(b); x++) sum += b[x];
byte cs = ( 256 - ( sum % 256 ) );
Serial.write(b, 5);
Serial.write(cs);
}
}
I added the longer delay so I could see the onboard TX LED flashing, too short a delay and it just looks like it's *on*. The potentiometer input should be 0-1023, so multiplying that by 7 gives me something closer to my 0-7000 gauge. Am I calculating the lsb correctly?
Bookmarks