I'm trying to build a datalogger using Arduino UNO, I'll use RS232 for the communication between PC and Arduino, the problem I'm facing now is that I'm using delay(10000) : 10 seconds as a timestep for data acquisition. however, I can't find any solution to receive a string from the serial input to Arduino while delay is executing. Here is the code :
void setup() {
Serial.begin(9600);
}
void loop() {
serialRoutine();
dataLoggingEvery10Second(); // That's a function to receive data from the sensor and store it in SD card.
delay(10000);
}
// A function to handle all the serial in out
void serialRoutine(){
// print the string when a newline arrives:
while(Serial.readString() == ""){
String serstr = Serial.readString();
/*
* Getters
*/
if(serstr == "GETDATA"){
Serial.println("Here is my data");
}
serstr = "";
}
}
Any help would be highly appreciated !
GETDATA
anyway, so what is the point of the delay? – Majenko♦ Aug 14 '17 at 9:19serialRoutine();
anddelay(10000);
– mbarki mohamed Aug 14 '17 at 9:24while(Serial.readString() == ""){String serstr = Serial.readString();
- this seems to me to be reading two strings. – Nick Gammon♦ Aug 14 '17 at 9:56