Serial0 is used for monitoring
Serial1 is used for GPS monitoring
Serial2 is used for wireless communication
Serial0 will modify the variable when the request signal comes every second. (To be implemented)
Serial1 receives the GPS signal every second, and stores the latitude and longitude value in a variable.
Serial2 uses AT COMMAND every second to save the parameter value that comes in response.
Currently, Serial0, 1, and 2 are operating in loop ().
Question 1: Do I always have to wait in the loop() to wait for a response?
Question 2: Can not I always get the value every time I answer without having to wait?
Is it possible to use serialEvent()?
Question 3: If I put while (Serial.available ()> 0) {// action} in setup(), I can not escape.
The next function does not seem to be executed. Why?
Question 4: I called the Serial function once a second in the timer.
It's not working, is it a problem with my code?
void loop() {
/*
If the function is called in succession,
Delay () between function calls does not work well
When the function is terminated, the following function is executed.
*/
if (!LoRaParameter_oneTime && !GPS_oneTime && !Setting_File_SDCARD_oneTime) {
LoRa_SaveBuffer(); // for wireless communication
}
else if (LoRaParameter_oneTime && !GPS_oneTime && !Setting_File_SDCARD_oneTime) {
GPS_SaveBuffer(); // get the GPS data
}
else if (!Setting_File_SDCARD_oneTime && LoRaParameter_oneTime && GPS_oneTime){
Check_Setting_File_SDCARD(); // for SPI communication
}
else if (Setting_File_SDCARD_oneTime){
// some sensor action;
}
} // loop
void LoRa_SaveBuffer() {
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = 'D';
char endMarker = '\n';
char rc;
Serial2.println("$Rpar=");
while (Serial2.available() > 0 && newData == false) {
rc = Serial2.read();
if (recvInProgress == true) {
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData = true;
}
}
else if (rc == startMarker) {
recvInProgress = true;
}
}
if (newData == true ) {
// action
}
LoRaParameter_oneTime = true;
newData = false;
}
void GPS_SaveBuffer() {
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '
I have heard from someone that this source is very inefficient. Since Serial code is still waiting for communication in the loop () function, this serial code can expect all communication timing delays if other sensor extraction operations are in loop (). someone recommend using serial interrupt, then should I use serialEvent ()?
;
char endMarker = '\n';
char rc;
while (Serial1.available() > 0 && newData == false) {
rc = Serial1.read();
if (recvInProgress == true) {
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData = true;
}
}
else if (rc == startMarker) {
recvInProgress = true;
}
}
if ((newData == true) ) {
// action
}
GPS_oneTime = true;
newData = false;
}
I have heard from someone that this source is very inefficient. Since Serial code is still waiting for communication in the loop () function, this serial code can expect all communication timing delays if other sensor extraction operations are in loop (). someone recommend using serial interrupt, then should I use serialEvent ()?