I've still been playing with different ways of sending data from the nextion textboxes to Arduino variables and have gotten it a little better with the attached code but it's still somewhat intermittent and sometimes sends incorrect values. I'm wondering if anyone has had better luck on the nextion side with and of the following(I'm using get right now to send the textboxes):
get - Send attribute/constant over serial (0x70/0x71 Return Data)
print - Send raw formatted data over Serial to MCU – print/printh does not use Nextion Return Data, user must handle MCU side
prints - Send raw formatted data over Serial to MCU – prints does not use Nextion Return Data, user must handle MCU side
printh - Send raw byte or multiple raw bytes over Serial to MCU
void HMI_display_rec() {
if (mySerial.available()) {
inByte = mySerial.read(); //INCOMING DATA BITS
if (inByte > 47 && inByte < 58) { //BETWEEN 0 & 9?
message.concat(char(inByte)); //MESSAGE BIT BY BIT
}
if (inByte == 255) { //END BYTE?
endBytes = endBytes + 1;
}
if (inByte == 255 && endBytes == 3) { //MESSAGE COMPLETE?
int val = message.toInt(); //RETURN VARIABLE
message = "";
endBytes = 0;
Serial.print("TEST MESSAGE = "); //TESTING SENDING DATA TO ARDUINO FROM NEXTION
Serial.println(val); //TESTING SENDING DATA TO ARDUINO FROM NEXTION
Serial.println(""); //TESTING SENDING DATA TO ARDUINO FROM NEXTION
}
}
}