Using Nextion RTC

Has anyone used the built-in RTC ?

I have just started using a 3.2 Enhanced but I cannot find any code examples for setting or reading the RTC, and very little in the Nextion Docs.

Can anyone help ? Thanks.

There are 7 numeric system variables, rtc0 (year), rtc1 (month), rtc2 (day), rtc3 (hour), rtc4 (minute), rtc5 (second), and rtc6 (dayOfWeek).

Setting the RTC is done by setting rtc0 to rtc5, for example rtc0=2020, rtc1=9, rtc2=21, rtc3=8, rtc4=41, rtc5=30. rtc6 is read-only and will automatically be set according to rt0-rtc2.

Reading the RTC is simply done by reading these system variables and using these to update display components.

1 Like

Many thanks - I will explore this.

/ The following is going to execute before we load this current page:
//
// Read the EEPROM to know if we are in 24 hour mode:
repo bt24.val,20 // reads from EEPROM address 20 into the dual state button
//
// I am going to read the EEPROM to know in what setting the brightness is:
repo h0.val,10 // reads from EEPROM address 10 into the slider
repo n0.val,10 // reads from EEPROM address 10 into the n0.val
//
// Read the EEPROM to know if the DST is enable:
repo btdst.val,30 // reads from EEPROM address 30 into the dual state button
//
//
//
// I am going to run everything on the timer here so it can refresh immediately
// when this page loads:
// If you edit anything on the timer, please copy/paste the entire content
// of the timer code in here.
//
// Write the number boxes with the value of the RTC:
// rtc0 is year 2000 to 2099,
// rtc1 is month 1 to 12,
// rtc2 is day 1 to 31,
// rtc3 is hour 0 to 23,
// rtc4 is minute 0 to 59,
// rtc5 is second 0 to 59,
// rtc6 is dayofweek 0 to 6 (Sunday=0, Saturday=6).
//
second.val=rtc5 // write the second box with RTC data
minute.val=rtc4 // write the minute box with RTC data
// for the hour (rtc3) we are going to do it later to check if is 12H or 24H mode.
day.val=rtc2 // write the day box with RTC data
month.val=rtc1 // write the month box with RTC data
year.val=rtc0 // write the year box with RTC data
//
// Day of the week is stored as 0 (Sunday) to 6 (Saturday).
// For that reason we are going to write the corresponding text:
if(rtc6==0) // if day of the week is 0
{
weektext.txt=“Sonntag” // write to the text the word “SUNDAY”
}else if(rtc6==1) // if day of the week is 1
{
weektext.txt=“Montag” // write to the text the word “MONDAY”
}else if(rtc6==2) // if day of the week is 2
{
weektext.txt=“Dienstag” // write to the text the word “TUESDAY”
}else if(rtc6==3) // if day of the week is 3
{
weektext.txt=“Mittwoch” // write to the text the word “WEDNESDAY”
}else if(rtc6==4) // if day of the week is 4
{
weektext.txt=“Donnerstag” // write to the text the word “THURSDAY”
}else if(rtc6==5) // if day of the week is 5
{
weektext.txt=“Freitag” // write to the text the word “FRIDAY”
}else if(rtc6==6) // if day of the week is 6
{
weektext.txt=“Samstag” // write to the text the word “SATURDAY”
}
//
//
//
// Daylight saving time (DST):
// To create a DST mode, we are going to edit the time when the correct day
// come to pass. The date in which the time changes for DST is different
// depending on your area. This is set to US DST standard, but you
// should check for your area and edit the following code accordingly.
// In United States DST starts at the second Sunday of March, and
// it ends at the first Sunday of November.
// It goes from 1:59 to 3:00 when it starts, and from 1:59 to 1:00
// when it finishes.
//
// Check if is the month to start the DST:
if(rtc1==3) // if is march:
{
if(rtc6==0) // if is sunday:
{
vasunday.val=rtc2 // store the day number on the variable
if(vasunday.val>7) // if the day is greater than 7:
{ // it would mean that this is not the 1st sunday of the month.
if(vasunday.val<15) // and if the day is less than 15:
{ // meaning is not the 3rd or 4th sunday of the month
if(rtc3==2) // if the hour is 2:
{
if(rtc4==0) // if the minute is 0:
{
if(rtc5==0) // if the second is 0:
{
// We check if DST is enable:
repo vadst.val,30 // reads from EEPROM address 30 into variable vadst
if(vadst.val==1) // if DST is enabled:
{
rtc3=rtc3+1 // add 1 to hour
} // end of “if DST is enabled”
} // end of “if the second is 0”
} // end of “if the minute is 0”
} // end of “if the hour is 2”
} // end of “and if the day is less than 15”
} // end of “if the day is greater than 7”
} // end of “if is sunday”
} // end of “if is march”
//
// End of checking if is the month to start the DST
//
// Check if is the month to end the DST:
if(rtc1==11) // if is november:
{
if(rtc6==0) // if is sunday
{
vasunday.val=rtc2 // store the day number on the variable
if(vasunday.val<8) // if the day is below 8:
{ // it would mean that this is the 1st sunday of the month.
// before continue checking if is going to be the end of DST,
// I am going to record that we didn’t pass through this yet:
if(rtc3==0) // if is hour 0
{
vadst2.val=0 // record that we didn’t pass through the end of DST
} // end of “if is hour 0”
// End of recording that we didn’t pass through this yet.
// Continue checking if is time to end DST:
if(rtc3==2) // if the hour is 2:
{
if(rtc4==0) // if the minute is 0:
{
if(rtc5==0) // if the second is 0:
{
if(vadst2.val==0) // if we didn’t do this yet for this year:
{ // This is to prevent a loop of always returning to 1 AM.
// We check if DST is enable:
repo vadst.val,30 // reads from EEPROM address 30 into variable vadst
if(vadst.val==1) // if DST is enabled:
{
rtc3=rtc3-1 // subtract 1 from hour
vadst2.val=1 // record that we pass through the end of DST
} // end of “if DST is enabled”
} // end of “if we didn’t do this yet for this year”
} // end of “if the second is 0”
} // end of “if the minute is 0”
} // end of “if the hour is 2”
} // end of “if the day is below 8”
} // end of “if is sunday”
} // end of “if is november”
//
// End of Daylight Saving Time.
//
//
//
// 24 hours mode:
if(bt24.val==1) // if 24 hour mode is enabled
{
vis pmam,0 // hide the object called pmam
hour.val=rtc3 // show hour with RTC data. By default is 24 hour mode.
}else // since we are in 12H mode:
{
vis pmam,1 // show the object called pmam
// Check if hour is above 12:
if(rtc3>12) // if hour is above 12
{
hour.val=rtc3-12 // substract 12 to the hour showing on RTC
}else // since hour is less than 12:
{
if(rtc3==0) // if hour is 0
{
hour.val=12 // show hour as 12 (AM)
}else // since hour is not 0:
{
hour.val=rtc3 // show hour with RTC data
}
} // end of “since hour is less than 12”
if(rtc3>11) // if hour is above 11:
{
pmam.txt=“PM” // write “PM”
}else // since hour is not above 11:
{
pmam.txt=“AM” // write “AM”
}
} // end of “since we are in 12H mode”

Reiter : Preint…Event

  • Val. (tm0, vadst, vasun. vadst2, tmhok, tmrep, vab

val
tmhok

// This timer simulates a press event every cycle, while is enable.
//
// Check what button was pressed:
if(vab.val==4) // if button 4 was pressed:
{
click b4,1 // simulate a press event on button b4
} // end of “if button 4 was pressed”
if(vab.val==10) // if button 10 was pressed:
{
click b10,1 // simulate a press event on button 10
} // end of “if button 10 was pressed”
if(vab.val==5) // if button 5 was pressed:
{
click b5,1 // simulate a press event on button b5
} // end of “if button 5 was pressed”
if(vab.val==11) // if button 11 was pressed:
{
click b11,1 // simulate a press event on button b11
} // end of “if button 11 was pressed”
if(vab.val==6) // if button 6 was pressed:
{
click b6,1 // simulate a press event on button b6
} // end of “if button 6 was pressed”
if(vab.val==12) // if button 12 was pressed:
{
click b12,1 // simulate a press event on button b12
} // end of “if button 12 was pressed”
if(vab.val==1) // if button 1 was pressed:
{
click b1,1 // simulate a press event on button b1
} // end of “if button 1 was pressed”
if(vab.val==7) // if button 7 was pressed:
{
click b7,1 // simulate a press event on button b7
} // end of “if button 7 was pressed”
if(vab.val==2) // if button 2 was pressed:
{
click b2,1 // simulate a press event on button b2
} // end of “if button 2 was pressed”
if(vab.val==8) // if button 8 was pressed:
{
click b8,1 // simulate a press event on button b8
} // end of “if button 8 was pressed”
if(vab.val==3) // if button 3 was pressed:
{
click b3,1 // simulate a press event on button b3
} // end of “if button 3 was pressed”
if(vab.val==9) // if button 9 was pressed:
{
click b9,1 // simulate a press event on button b9
} // end of “if button 9 was pressed”

val tmrep
// This timer simulates a press event every cycle, while is enable.
//
// Check what button was pressed:
if(vab.val==4) // if button 4 was pressed:
{
click b4,1 // simulate a press event on button b4
} // end of “if button 4 was pressed”
if(vab.val==10) // if button 10 was pressed:
{
click b10,1 // simulate a press event on button 10
} // end of “if button 10 was pressed”
if(vab.val==5) // if button 5 was pressed:
{
click b5,1 // simulate a press event on button b5
} // end of “if button 5 was pressed”
if(vab.val==11) // if button 11 was pressed:
{
click b11,1 // simulate a press event on button b11
} // end of “if button 11 was pressed”
if(vab.val==6) // if button 6 was pressed:
{
click b6,1 // simulate a press event on button b6
} // end of “if button 6 was pressed”
if(vab.val==12) // if button 12 was pressed:
{
click b12,1 // simulate a press event on button b12
} // end of “if button 12 was pressed”
if(vab.val==1) // if button 1 was pressed:
{
click b1,1 // simulate a press event on button b1
} // end of “if button 1 was pressed”
if(vab.val==7) // if button 7 was pressed:
{
click b7,1 // simulate a press event on button b7
} // end of “if button 7 was pressed”
if(vab.val==2) // if button 2 was pressed:
{
click b2,1 // simulate a press event on button b2
} // end of “if button 2 was pressed”
if(vab.val==8) // if button 8 was pressed:
{
click b8,1 // simulate a press event on button b8
} // end of “if button 8 was pressed”
if(vab.val==3) // if button 3 was pressed:
{
click b3,1 // simulate a press event on button b3
} // end of “if button 3 was pressed”
if(vab.val==9) // if button 9 was pressed:
{
click b9,1 // simulate a press event on button b9
} // end of “if button 9 was pressed”