Reputation: 1620
I'm trying to get the basics done with my Arduino, and thus I'm starting off small.
That said, I want the Arduino to listen for simple, multiple commands being sent from my Raspberry Pi (I'm emulating this through the serial monitor now, however)
This is the code I'm working with:
#include "SoftwareSerial.h"
void setup()
{
Serial.begin(9600);
delay(100);
}
void loop() {
if (Serial.find("test1")) {
delay(100);
Serial.println("TEST1 command received");
}
if (Serial.find("test2")) {
delay(100);
Serial.println("TEST2 command received");
}
}
}
Sadly, only the test1 command triggers a serial print response, test2 no. Can anyone here help point me in the right direction?
Thank you!
Upvotes: 0
Views: 42
Reputation: 400049
From reading the documentation, I don't think you can use the find()
function like that.
Consider what happens if test2
is input, when the find("test1")
call is running. It will probably consume all characters up to and including the 2
, and then return false
, at which point those characters are lost.
I think you should design an actual protocol, with some delimiter between commands, and read/parse those.
Upvotes: 1