Ok so I have two arduino's setup with Xbees. One is sending to the other like this:
char buffer[128]
char buffer1[128]
char buffer2[128] //The function requires that they are char[]
if(Canbus.ecu_req(ENGINE_COOLANT_TEMP,buffer1) == 1)
if(Canbus.ecu_req(ENGINE_RPM,buffer2) == 1) //this stores the values in buffer1 and buffer2
sprintf(buffer,"%d%,d%,d%,%d;) // when i print
serial.println(buffer);
On my receiving arduino i figured out how to convert this into the integer value, however i can only manage to do this with the first number and then once it detects a comma it ignores the rest because of the atoi function:
int serReadInt()
{
int i, serAva; // i is a counter, serAva hold number of serial available
char inputBytes [7]; // Array hold input bytes
char * inputBytesPtr = &inputBytes[0]; // Pointer to the first element of the array
if (Serial.available()>0) // Check to see if there are any serial input
{
delay(5); // Delay for terminal to finish transmitted
// 5mS work great for 9600 baud (increase this number for slower baud)
serAva = Serial.available(); // Read number of input bytes
for (i=0; i<serAva; i++) // Load input bytes into array
inputBytes[i] = Serial.read();
inputBytes[i] = '\0'; // Put NULL character at the end
return atoi(inputBytesPtr); // Call atoi function and return result
}
else
return -1; // Return -1 if there is no input
}
Is there any way that I can take the buffer string and take each number separated by comma out individually?
Moderator edit: [code] ... [/code] tags added. (Nick Gammon)