Cant send data nextion with ESP32

greetings everyone... so i have a nextion NX3224K024 and ESP32S.. im trying to learn how to use nextion by sending a simple date and time text to show it on nextion display... the problem is the nextion didn't receive the data from esp (as i think)... for the nextion display i already design it with nextion editor and it works fine... here's the code im using to show date and time with NTP way..

#include <WiFi.h>
#include "time.h"
#include "esp_sntp.h"
#include <EasyNextionLibrary.h>

// WiFi credentials
const char *ssid = "Mod edit SSID redacted";
const char *password = "Mod edit password redacted";

// NTP servers and timezone configuration
const char *ntpServer1 = "pool.ntp.org";
const char *ntpServer2 = "time.nist.gov";
const long gmtOffset_sec = 25200; // GMT+7 for WIB (Western Indonesia Time)
const int daylightOffset_sec = 0;

// EasyNextion text objects for date and time display
EasyNex myNex(Serial2);
char datestr[10];
char timestr[10];
// char tDO[6];
// char tpH[6];
// char tTemp[6];

void printLocalTime() {
    struct tm timeinfo;
    if (!getLocalTime(&timeinfo)) {
        Serial.println("No time available (yet)");
        return;
    }

    // Format date as string (e.g., "24/07/2024")
    strftime(datestr, sizeof(datestr), "%d/%m/%y", &timeinfo);

    // Format time as string (e.g., "15:30:45")
    strftime(timestr, sizeof(timestr), "%H:%M:%S", &timeinfo);

    // Print to Serial (for debugging)
    Serial.println(datestr);
    Serial.println(timestr);

    // Update Nextion display with current date and time
    myNex.writeStr("page0.t2", timestr);
    myNex.writeStr("page0.t1", datestr);
}

// Callback function (gets called when time adjusts via NTP)
void timeavailable(struct timeval *t) {
    Serial.println("Got time adjustment from NTP!");
    printLocalTime();
}

void setup() {
    Serial.begin(115200);

    // Initialize Serial communication for Nextion
    Serial2.begin(9600, SERIAL_8N1, 17, 16); // TX = GPIO17, RX = GPIO16
    myNex.begin(9600);

    // Connect to WiFi
    Serial.printf("Connecting to %s ", ssid);
    WiFi.begin(ssid, password);

    // Optional: Configure NTP server via DHCP
    esp_sntp_servermode_dhcp(1);

    // Wait for WiFi connection
    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }
    Serial.println(" CONNECTED");

    // Set notification callback function for time sync
    sntp_set_time_sync_notification_cb(timeavailable);

    // Configure time with NTP servers
    configTime(gmtOffset_sec, daylightOffset_sec, ntpServer1, ntpServer2);

    // Optionally, set timezone with daylight saving rules
    // configTzTime(time_zone, ntpServer1, ntpServer2);
}

void loop() {
    delay(1000);
    printLocalTime(); // Update time every 5 seconds

    // Handle Nextion events
    myNex.NextionListen();
}

i also tried to change library from ITEAD to easynextionlib just in case there's something wrong with the library but there's no result ... the RX TX pins also seems right (im using GPIO16 as RX and GPIO17 as TX) the page and text in nextion also seems correct with the code i provided... i also did try change baudrate from 9600 to 115200....
its already a week with no results T_T

I have removed your SSID and password from your code, probably not things you should share in public.

24/07/2024 is 11 characters once you remember the final null terminator.

I don't know anything about the Easy Nextion library, but I've read a lot of good comments about it. I developed my own methods of communicating with a Nextion, they can be found here: Using Nextion displays with Arduino

I suggest that trying to start with printing date and time on a Nextion is too big a first step, I suggest you start by printing some simple text to a text box, tradition suggests you try to print "Hello World" (How many characters is that?). Once you have that working then try something more complicated. Does your PrintLocalTime function print OK to the serial monitor?

How is your Nextion connected? Photos and schematic are helpful, words are not. Schematics are acceptable hand drawn and photographed.

thank you very much for answering my question and hiding my ssid :), for the code

yes im using "%y" so it appear as 24 not 2024, so the total is 8 character. Im also considering printing simple text but coincidentally i have my time and date open in my arduino so im go with it.
im having a PCB board with ESP32S built in from my professor (he dont have any memory with nextion so im research it myself) and it was in good condition because it worked a program before and the nextion is connected to the esp32s fine (for context im formatting the program and the nextion) so im sure there's nothing wrong with the pin condition


after this message im going to try ur suggestion to print simple message... but considering all the things im doing, is there anything wrong? and yes the PrintLocalTime function works fine in serial monitor

Your schematic does not show that the ground from the Nextion is connected to the ESP32S, this is enough to stop it working. You've not shown how anything is powered. A schematic should show everything.

I can't tell you, as I mentioned, I don't know anything about the Easy Nextion library, other than I've read a lot of comments saying it is good.

When I created my methods as in the tutorial I started with one text box and got some text to display on it correctly, that is how you should start. You can't expect something as complex as getting the time, formatting it then displaying it to work correctly straight off, you have to do it in small steps.

If there is someone here who understands the Easy Nextion library then I hope they will reply and be able to offer more help than I can.

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