Serial Write From Esp32 to Nextion HMI Fail

Hey all,

First time working with ESP32 and Nextion HMI display. Having issues updating a text object on the Nextion HMI display via ESP32. Looked through a bunch of similar posts but nothing seems to work for me. Hoping someone with more experience can help.

MCU: esp32-wroom-32s
HMI: Nextion NX3224F028_011

Connections:
ESP32 micro-usb to PC
ESP32 RX2 (GPIO16) to Nextion TX
ESP32 TX2 (GPIO17) to Nextion RX
ESP32 VCC to Nextion 5V
ESP32 GND to Nextion GND

void setup() {
    Serial.begin(9600); // For debugging
    Serial2.begin(115200, SERIAL_8N1, 16, 17);
}

void loop() {
    Serial.println("sending data to Serial2");
    Serial2.print("t0.txt=");
    Serial2.print("Hello");
    Serial2.write("0xff");
    Serial2.write("0xff");
    Serial2.write("0xff");
    delay(1000);
}

I receive the output to Serial but the t0 object does not update. Tried this with a couple different boards. Works fine using Arduino.

Any ideas? Please let me know if you need any more info.

Post two simple schematics showing how you have connected this to Arduino and another for ESP32. Show all connections, power, ground, and any other hardware devices connected to it.

@rando32

Hi

Long time since I played with Nextion, but if I remember correctly, the text object to display needs to be in double quotes ala "your text".

Try...
Serial2.print("\"Hello\"");

2 Likes

See:

Try:

void loop() {
    Serial.println("sending data to Serial2");
    Serial2.print("t0.txt=");
    Serial2.print("\"Hello\"");
    Serial2.write(0xff);
    Serial2.write(0xff);
    Serial2.write(0xff);
    delay(1000);
}
1 Like

Here you go, please let me know if you need anything else.

Thanks, I tried that, same issue. I have one more board I can try. If that doesn't work, I'll probably look into using Arduino to update the HMI display and use the esp32 for it's wifi capabilities. Would be nice to not have to do that but, it is what it is.

The ESP is a 3V3 device and the Nextion is a 5V device. You need to place a level translator between the ESP 32 and the Nextion. The reason it works with the Arduino is it is a 5V processor and is using the appropriate logic levels.

1 Like

I've had no problems using Nextion HMI with 3V3 microcontrollers.

1 Like

Indeed, from the Data sheet for the NX3224F028 which @rando32 is using

1 Like

Hey all,

To rule out the HMI code, I updated the Nextion, then after many iterations I finally got it working via the ESP32 with this code:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(16,17); // RX,TX

void setup() {
  mySerial.begin(9600);
}

void loop() {
  mySerial.print("t0.txt=");
  mySerial.print("\"Test\"");
  mySerial.write("\xFF\xFF\xFF");
}

Prior to upload I had to install the library ESPSoftwareSerial by Dirk Kaar, Peter Lerup.

1 Like

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