To be honest, I have no idea what the printh 23 02 54 3E method is.
To avoid these issues, Nextion has a preinit and a postinit event for the page loading. The preinit is executed before the screen is updated. Ideally, the date is already set somewhere in a global variable on Nextion, because it makes life a whole lot easier. The Arduino only needs to update that one global variable, and the preinit event on Nextion only needs to copy that one variable into the local one.
If it really needs to be done the way you described it, meaning the Arduino sends the date only after entering the page, things get a little bit more complicated. Waiting for incoming data is one of those things that are noticeably less intuitive in Nextion than you’d expect.
The simple and dirty way (everything in the preinit event)
Notify the Arduino that it needs to send data.
Wait a fixed delay within which the Arduino must send said data.
That’s it. As long as the correct value has been set before the preinit event finishes, you won’t see glitches on screen.
The cleaner, more complicated way
Preinit notifies the Arduino that it needs to send data.
Preinit event stops screen updates using ref_stop
Preinit starts a timer running at 50ms (lowest value you can set in the editor)
Timer event checks if the value has been updated. If so, it enables screen updates again, using ref_star and disables itself.
You can’t wait in a loop because serial data isn’t processed while a loop is running (even if you include doevents).
Thank you @Max !
Option 2 seems like a cleaner implementation.
I may have to implement a “page handler” on arduino to send the relevant data for that page.
The time and date was just one of the few fields on each screen.
Thank you!
This forum is in no way affiliated with NEXTION®, ITEAD STUDIO®, TJC®, or anyone else really. All product names, logos, and brands are property of their respective owners. All company, product, and service names used in this website are for identification purposes only. Use of these names, logos, and brands does not imply endorsement from the respective rights holder(s).