Listen Function doesn't seem to work with Nextion Screen

I'm using a Nextion screen and I have 4 pages. I'm trying to get it where whenever I go to "Main" there will be some communication between my Arduino and the Nextion Screen. Nothing pops up on my Serial Monitor.

#include <SoftwareSerial.h>
#include "Nextion.h"

//Pages
NexPage Main    = NexPage(0, 0, "Main");

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

void setup() {

  //Init Nextion Display
  nexInit();
  //Add Nextion Callback's 
  Main.attachPop(MainPopCallback);

}


void loop() {
 
  //List to Nextion Display
  nexLoop(nex_listen_list);

}

void MainPopCallback(void *ptr)
{
  Serial.println("Main Callback");
  digitalWrite(LED_BUILTIN, HIGH);
}

first of all what microcontroller shall receive the serial data from the nextion display?

I have never seen such a code before.

Did you do a real basic test if your nextion display is sending something over serial interface with a super standard testcode that is well known for working properly?

The code that you posted has no info about the used baudrate
depending on the microcontroller you are using software serial can do only slow baudrates

Did you do a test with some other device that is well known for sending serial data to test your code?

Did you do some tests with the simulator of the nextion-software?

The NexPage is often used with: page0.show(); and not much else.
Can you find an example of NexPage ?
If you receive a button press from the Nextion, then you can start a new page from the Arduino. Are you going to a other page within the Nextion display ? and are you expecting a code that a new page has started. I don't know if it works that way.

If you go to your top post, you can edit the Category for your topic. Put it in the "Displays" topic.
Have you read the main article about Nextion displays:

Many of us try to start with the ITEAD library, but get frustrated and try to make something else or find something else.

The setup is an Arduino Nano. Yeah it's just a basic code that I put together so that I can see if it works. I saw someone else on the forum use something like this and they said that it worked. But I can't seem to get it to print "Main Callback"

Kinda along the lines of what I said to the guy above you. I saw someone on the forum use "NexPage" and he said that it worked. I'm going to try the press button function to see if I can get communication.

I haven'r done much with a nextion-display.

instead of using some library you can send basic commands
like

void ButtonStartRed() {
  Serial2.print("b0.bco=63488");  // "b0" name of the button ".bco" color of the button
  Serial2.print("\xFF\xFF\xFF");         // arduino sends 0xff 0xff 0xff, which tells the Nextion Display this is end of command-string
}

There is a high change that there is somehing similar for pages and how to change to another page.

best regards Stefan

I've read through the Nextion Instruction Set and I think those commands are for inside "Nextion" and not for Arduino communication between the 2. I'll test the code though.
Thank you!

The Nextion commands work both 'inside' the Nextion and if you send them to the Nextion through the serial port.

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