I’m trying to send a space delimited list of integers over serial to Arduino.
I’m using strtok
to split the string received, but it only ever gets the first value. What’s going on?
char received[16];
setup() {
Serial.begin(9600);
}
void loop() {
int bytesRead = 0;
if (Serial.available()) {
delay(3); //delay to allow buffer to fill
if (bytesRead > 0) {
Serial.print("Received message ");
Serial.print(" Length: ");
Serial.println(bytesRead); // For example: "1 2n"
strtok_i = strtok(received, ' ');
int m_1 = atoi(strtok_i);
strtok_i = strtok(NULL, ' ');
int m_2 = atoi(strtok_i);
Serial.print("Value_one: ");
Serial.print(m_1);
Serial.print(" Value_two: ");
Serial.println(m_2); // Always zero.
}}
}