Nextion reciever issues with updatable values

Hi, I've tried the majority of the libraries out there for the Nextion editor, but none of them work for me, even after watching Interlink Knight videos, Cheap Controls videos, online solutions including the stuff on the forum, and a bit of ChatGPT because I was desperate.

So, my main problem is updating values in the sketch, such as p0.pic = # and n0.val = #, followed by the Nextion terminator, 0xFF 0xFF 0xFF, into the serial. While my loop runs from Arduino, which sends messages to the Nextion, which the Nextion is not processing. However, I have found that the Nextion pushbuttons I made did send hex to the Arduino mega serial, where I could determine which button was pressed, which got me thinking that I could use the communication it uses at its most basic and work from there to get it to update values when communicating with an Arduino mega tx1 rx1 ports.

Since I can't post everything here because it won't let me upload the HMI file, I've added it to a Google doc linked here: Nextion device not working: How I've set it up

This below is the code that allowed me to read my hex values from the Nextion editor:

void setup() {
  Serial.begin(9600);      // Initialize Serial Monitor communication
  Serial1.begin(9600);     // Initialize Nextion communication on Serial1
  delay(1000);             // Wait for Nextion to start up


  Serial.println("Arduino ready. Type a message to send to the Nextion:");
}


void loop() {
  // Check if there's data from the Serial Monitor (PC)
  if (Serial.available()) {
    String message = Serial.readString();
   
    // Send the message to Nextion via Serial1
    Serial1.print(message);   // Sends message to Nextion
    Serial1.write(0xFF);      // Send Nextion terminator
    Serial1.write(0xFF);
    Serial1.write(0xFF);
   
    // Print the message sent
    Serial.println("Sent to Nextion: " + message);
  }


  // Check if there's data from the Nextion
  if (Serial1.available()) {
    Serial.println("Received from Nextion (in HEX):");
   
    // Read and print data in hexadecimal format
    while (Serial1.available()) {
      int byteReceived = Serial1.read();  // Read each byte
      Serial.print("0x");
      if (byteReceived < 0x10) {
        Serial.print("0");  // Add leading zero for single-digit hex values
      }
      Serial.print(byteReceived, HEX);    // Print byte as a 2-digit hex value
      Serial.print(" ");                  // Separate bytes with a space
    }
    Serial.println();  // Add a new line after printing all bytes
  }


  // Small delay to avoid spamming
  delay(100);
}



So how can I make the values change using Arduino code from the Arduino mega board and update values of picture IDs and number values on the Nextion editor?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.