Uart communication between esp32 and nextion HMI?

hello i write a program for esp32 and i need to control it with nextion HMI. baud rate must be 115200 for esp32 and nextion hmi i downloaded nextion library, but there is a communication error. i cant send text from esp32 to nextion hmi.. here is my code:

#include "Nextion.h"

#define RXD2 16
#define TXD2 17

NexText t0 = NexText(0, 2, "t0");
NexButton b0 = NexButton(0, 3, "b0");
NexPage p0 = NexPage(0, 0, "p0");
NexTouch *nexListenList[] =
{
&t0,
&b0,
&p0,
NULL
};

int montajButon = 25;
String msj = "merhaba";

void setup() {
  Serial.begin(115200);
nexSerial.begin(115200);
 pinMode(montajButon, INPUT);      // set the button pin mode
  digitalWrite(montajButon, LOW);
}

void loop() {
 if (nexSerial.available()) {
     Serial.print("Haberlesme OK");
     delay(2000);
     if (digitalRead(montajButon == true)){
           Serial.print("buton geliyor");

       nexSerial.print("t0.txt=");
       nexSerial.write(0x22);
       nexSerial.print(msj);
       nexSerial.write(0x22);
       nexSerial.write(0xff);
       nexSerial.write(0xff);
       nexSerial.write(0xff);
      delay(2000);
     }
 }
}

What error?

i cant see the text on hmi screen and there is no message on serial port screen.
when i tried write the program in a different way "recvretcommandfinished err" message on serial port screen.

Do you know that this will only be true when the nextion sends data to to the ESP32 ? What data are you expecting ?

im not expecting any data. there are programming errors maybe in my code. i need to send the text (String msj = "merhaba";) to hmi screen.

Then your code will send nothing.

This code is also incorrect...

Maybe you meant if(digitalRead(montajButon) == HIGH)

Maybe try some examples...
https://www.google.com/search?q=esp32+nextion+tutorial

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