you should try to 0xff some of the unused bytes just for fun to see if any undocumented stuff lights up
you should try to 0xff some of the unused bytes just for fun to see if any undocumented stuff lights up
have you decided what you’re going to write the code with? arduino c?
I've ordered an Arduino Uno, it will be here tomorrow. I believe it's C++, not C. First step is basically just the example code shown here: https://www.arduino.cc/reference/en/.../serial/write/. Except I'll swap the hello string for the 0A 58 40 0D AC byte sequence and the proper 8192 baud rate. If I've done my math correctly and it works, that should give me a tach reading of 3500.
right on
here's a general function to generate a checksum byte with c or c++, just run it against the array
here's a function to test an incoming checksum (not that you should have to for this program)Code:char checksum_generate(char *buf, int len) { int x = 0; unsigned int sum = 0; for(x=0;x<len;x++) sum += buf[x]; return ( 256 - ( sum % 256 ) ); }
Code:bool checksum_test(char *buf, int len) { int x = 0; unsigned int sum = 0; for(x=0;x<len;x++) sum += buf[x]; if((sum & 0xFF) == 0) { return true; } else { return false; } }
Ah yes, I had completely forgotten about the checksum! Adding in your checksum function, this is pretty much the entirety of the initial test! I'm leaving out all of the other bytes because I expect they are uneccessary. I'm assuming the gauge cluster will only look at the 5 bytes after 0x0A.
It compiles without errors or warnings, but that doesn't mean my logic is sound!Code:void setup() { Serial.begin(8192); } void loop() { if (Serial.availableForWrite() > 5) { byte b[5] = {0x0A, 0x58, 0x40, 0x0D, 0xAC}; unsigned int x, sum = 0; for (x = 0; x < sizeof(b); x++) sum += b[x]; byte cs = ( 256 - ( sum % 256 ) ); Serial.write(b, 5); Serial.write(cs); } }
Adding a little math to convert an integer RPM into MSB and LSB...
Now if that works, I will add a potentiometer and read that for input to convert to an rpm reading, and I should be able to control my tachometer in real time!Code:void setup() { Serial.begin(8192); } void loop() { if (Serial.availableForWrite() > 5) { int rpm = 3200; byte msb = floor(rpm / 256); byte lsb = rpm % 256; byte b[5] = {0x0A, 0x58, 0x40, 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); } }
looking good
the third byte in your 'testing' datastream packet is probably 0x40 because your test bench had the check engine light on, so use 0x00
you'll probably be best off introducing a small delay like delay(10) into your main loop (inside your if()) as most aldl devices can't accept data at such a high rate
really curious to see if it works on the first try for you
Bookmarks