Can't print on Nextion from esp32

Hello, I'm trying to print on my Nextion simple text. its just wont work. it says communication error but I couldn't find the solution. On my esp32 wroom 32D there is no pin number for the tx and rx, its just Tx2 , Rx2 or Rx0, Tx0. please help

#include <Nextion.h>
NexText t0 = NexText(0,1,"t0");

void setup() 
{
  Serial2.begin(9600,SERIAL_8N1,17,16);
  nexInit();

}

void loop() {
  Serial2.print(F("t0.txt=\"")); // Start of command to change text
  Serial2.print(F("hi"));  // Text content
  Serial2.print(F("\""));        // End of text content
  Serial2.write(0xff);           // End of command delimiter (repeated 3 times)
  Serial2.write(0xff);
  Serial2.write(0xff);
  // t0.setText("hi");
  // Serial2.write(0xff);           
  // Serial2.write(0xff);
  // Serial2.write(0xff);


  delay(1000);
}

You must not double-post the same topic. Delete one.

@bahuri22 ,

Your other topic on the same subject deleted.

Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.

Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you take a few moments to Learn How To Use The Forum

It will help you get the best out of the forum in the future.

Thank you.

1 Like

Serial2 would be the 3rd serial port, does the esp32 wroom 32D have at least 3 serial ports? (I am not familiar with it).

They don't need to be for hardware serial ports because they are allocated to specific pins in the hardware, you can't (usually) change them, so they don't have to be specified.

You don't need the Nextion library for the simple prints to the serial port you are attempting. In any case, if you read this forum you will find that the official Nextion library does not have a good reputation.

I suggest:
You find out how many serial ports a esp32 wroom 32D has and which pins they are on, then use one of those serial ports.

You should then only need:

Serial1.begin(9600); // Serial port 1 (the second one)
Serial2.begin(9600); // Serial port 2 (the third one).
Etc

I have a tutorial here about the Nextion displays:

If you follow that and get stuck I will try to help.

I stress again that I am not familiar with the board you have, nor am I familiar with the ESP32 generally. I looked at a datasheet for an ESP32 board I considered buying but didn't buy. The data sheet shows 2 serial ports, I would guess that one of them is for the USB connection and one is for general use. I'd guess the general use one is Serial1, if this is correct then you need to use:

Serial1.begin(9600);

There is not, so far as I can see, any Serial2. Perhaps someone familiar with the ESP32 can comment.

Yes, ESP32 have 3 hardware serial ports. To initialize them you just need :

Serial1.begin(9600,SERIAL_8N1); //  pins RX - 27, TX- 26 
Serial2.begin(9600,SERIAL_8N1); //  pins RX - 17, TX- 16
1 Like

I tried playing with these lines but its not working

thank u for your time. i tried using serial1, i tried to change the baudrate in the code and in the nextion editor but nothing works.

The Nextion is a 5v device.

The Nextion's serial output can damage the ESP32, and It's not certain that the eps32's Serial output at 3.3v is high enough for the Nextion.

You may need to use a bidirectional level shifter between the two devices.

it worked before

I just review the specs, and I think I am wrong about the Serial voltage levels. It should be able to work at the eps32 voltage levels.

My Nextion is working with ESP32 for > 2 years now without the problem.
Markings on the board are a bit confusing, Serial1 pins are labeled Rx2, Tx2.

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