The Nextion RTC
Usage and debugging
While the RTC of the Enhanced and Intelligent series HMI screens is pretty straightforward, once one has understood the concept of the RTC0 to RTC6 system variables, there is not much information about solving problems. That’s why we see here a simple RTC demo project, followed by a video, explaining how to preset the RTC and how to fix issues.
The simple HMI project
One screen holds everything: A text component for the title, 4 more text components for the separators (“-” and “:”), and 6 Xfloat components for the year, month, day, hours, minutes, and seconds display. Why Xfloat??? Simply for esthetic reasons. The Xfloat allows setting the number of displayed decimals, left and right from the decimal point, the .ws0 and .ws1 attributes. setting ws1 to 0 hides the decimal point and setting .ws0 to 4 for the year and to 2 for all other fields gives beautifully and automatically left-padded values with 0.
A timer on the page reads the RTC0 to RTC5 registers and updates the corresponding Xfloat values every 330ms to give a fluid and continuous display:
x0.val=rtc0 x1.val=rtc1 x2.val=rtc2 x3.val=rtc3 x4.val=rtc4 x5.val=rtc5
No black magic, no rocket science! The full HMI file for study, playing, and re-using is here: RTC_simple.HMI
Debugging the RTC
The video below shows how to use the Nextion Debugger to connect directly to a Nextion HMI which is connected with a TTL serial to USB adapter to your PC, for example using the Nextion Foca Max adapter. Then, it’s possible to do a full command and control from the command field, like on the simulated HMI, you are probably more used to. The RTC registers can be preset that way.
Fixing a “bricked” RTC
Such can happen following power supply issues (brown out) or due to X-Ray control during shipping. The internal RTC registers then carry invalid values which makes their public mirror registers RTC0 to RTC6 display weird stuff and refuse a preset with correct values. The video shows in its second part how to use the RTC calibration function of the debugger to fix this.