Have a Nextion 3.5" with touch, making a thermostat. I can get messages from the Nextion to the ESP32 just fine. Using Serial2 on the ESP32, and it read and interprets the commands coming into the ESP32 with no problem, so my serial connect is OK.
When I try sending a simple number back into a text box - no luck. It can’t be this hard. I’ve looked at a lot of posts and I think my format is correct. Using " in my strings, sending three 0xff at the end. Here’s a test program I wrote. No luck. Thanks for any suggestions.
Theron Wierenga
// Nextion_write
// My test copy copy
// theron@wierengaconsulting.com
String sendThis;
void setup() {
Serial.begin(115200); //open the hardware serial port
Serial2.begin(9600);
}
void loop() {
String sendThis = ""; //Declare and initialise the string we will send
delay(1000); //Probably unneccessary, but I give the screen some time to respond
sendThis = "t1.txt=\"Test\""; //Build the part of the string that we know
writeString(sendThis); /*Use a function to write the message character by character to the Nextion because
mySerial.write(sendThis) gives you an error due to a datatype mismatch*/
}
//NOTE: A great big thanks to: RamjetX for writing this function. You can find his/her post here: http://forum.arduino.cc/index.php?topic=89143.0. Please go give him/her some Karma!
void writeString(String stringData) { // Used to serially push out a String with Serial.write()
for (int i = 0; i < stringData.length(); i++)
{
Serial2.print(stringData[i]); // Push each char 1 by 1 on each loop pass
Serial.print(stringData[i]);
}
Serial2.print(0xff); //We need to write the 3 ending bits to the Nextion as well
Serial2.print(0xff); //it will tell the Nextion that this is the end of what we want to send.
Serial2.print(0xff);
Serial.println(0xff);
}// end writeString function