Nextion events works with Serial2 but not with others Serials

Hi. I'm using a Nextion with a ESP32. I have a simple sketch that catches the event button, it works fine when I connect to Serial2 from my board, but when I change Serial, the button event stops working and I can only send data to the screen. I have also tried with different pins. From the editor, I send the Component ID.

#include <Nextion.h>
NexButton btn = NexButton(0, 1, "b0");

NexTouch *nex_listen_list[] =
{
  &btn,
  NULL
};

void setup() {
  Serial.begin(9600);
  Serial1.begin(9600, SERIAL_8N1, 26, 27); //Nextion

  //When I use Serial2, everything works.
  //Serial2.begin(9600);

  btn.attachPush(b0PushCallback, &btn);  // Press event. Only works with Serial2
  btn.attachPop(b0PopCallback, &btn);  // Press event. Only works with Serial2

  printDisplay("t0.txt=\"Hello\""); // Send data works with any Serial
}

void b0PushCallback(void *ptr)
{
  Serial.println("PushCallback");
  printDisplay("t0.txt=\"Button pressed\"");
}

void b0PopCallback(void *ptr)
{
  Serial.println("PopCallback");
  printDisplay("t0.txt=\"Button pressed\"");
}

void loop() {
  nexLoop(nex_listen_list);
}

void printDisplay(String content) {
  Serial1.print(content);
  Serial1.write(0xff);
  Serial1.write(0xff);
  Serial1.write(0xff);
}

I have tried with 2 ESP32 and 2 different Nextion screens, and the same thing happens.
Am i missing something?

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