I really am new to this (C as well as arduino), and I have tried searching but I am still no further forward. This is part of a CANBUS project using a sparkfun/SKPANG canbus shield, but I'm fairly sure my question is just a general one.
The data that I am extracting from the CANBUS is 8 bytes (8 pairs of HEX characters?). I can display each byte as HEX or DEC, which is fine for something like engine temp which is contained in a singe byte. My issue comes with engine RPM which is contained in two seperate bytes. I've worked out (by analysing the data in EXCEL) that I need to concatinate the bytes as HEX and then convert to DEC. But I can't work out how to do it. I've posted a generic example as opposed to the entire code;
void setup()
{
Serial.begin(9600);
byte data1 = 0x1e;
byte data2 = 0x3d;
String str12_0x = "0x" + String(data1,HEX)+String(data2,HEX);
Serial.print("data1 HEX = ");
Serial.println(data1,HEX);
Serial.print("data2 HEX = ");
Serial.println(data2,HEX);
Serial.print("data1 + data2 = ");
Serial.println(data1+data2);
Serial.print("Str12_0x = ");
Serial.println(str12_0x);
Serial.println(strtol(str12_0x, NULL, 16));
}
void loop()
{
}
I'm just trying to combine data1 1E and data2 3D and then convert the resultant 0x1E3D to an int for printing to a display or file as DEC. I've managed to combine them (by concatinating two strings) and get a string 0x1E3D but can't for the life of me convert the resultant string to an integer. I'm sure there is a simple answer to this but I can't find one. Tried using strtol(str12_0x, NULL, 16) but just get " error: cannot convert 'String' to 'const char*' for argument '1' to 'long int strtol(const char*, char**, int)' "