Hi everyone!!
I have been trying to read the data coming out of the RX pin of the M800 ECU using the pin 10 of the Arduino Uno ( which I have previously set as a virtual RX pin). The Arduino module is connected to my laptop. The ECU is connected to another laptop via a CAN to USB converter and is sending dummy sensor data to the Arduino. I have looked at the data sending protocol of the ECU, but have not been successful yet to extract anything but nonsense. Here's my code:Please before going through the code have a look at the data sending protocol of the ECU which I have attached.
/*
Software serial multple serial test
Receives from the hardware serial, sends to software serial.
Receives from software serial, sends to hardware serial.
The circuit:
* RX is digital pin 10 (connect to TX of other device)
* TX is digital pin 11 (connect to RX of other device)
Note:
Not all pins on the Mega and Mega 2560 support change interrupts,
so only the following can be used for RX:
10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69
Not all pins on the Leonardo support change interrupts,
so only the following can be used for RX:
8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
created back in the mists of time
modified 25 May 2012
by Tom Igoe
based on Mikal Hart's example
This example code is in the public domain.
*/
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
#define head0 0x82
#define head1 0x81
#define head2 0x80
#define marker1 0xFC
#define marker2 0xFB
#define marker3 0xFA
int rpm[2];
int RPM = 0;
char ET[2];
float EngTemp;
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(19200);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.println("Goodnight moon!"); // test
// set the data rate for the SoftwareSerial port
mySerial.begin(19200);
//mySerial.println("Hello, world?");
}
void loop() // run over and over
{
if (mySerial.read() == head0){
Serial.println("RPM");
if (mySerial.read() == marker2){
if (mySerial.read() == marker3){
//skip next byte
// mySerial.read();
//RPM read next 2 bytes
//rpm[0] = mySerial.read();
//rpm[1] = mySerial.read();
//RPM = rpm[0] << 8 && rpm[1];
Serial.println("RPM");
}
}
}
if (mySerial.available())
Serial.println(mySerial.read());
}//}}}}