Start a new topic

Options avaiable to set RTC variables (Enhanced)

Hello, I have found how to access the RTC values, but how can I set or sync.

I have the battery inserted.


1 person likes this idea

Found it, on the simulator page.

What are the RTC values you are using? I can't get anything to work! Thank you

using the following to display on the form, using timer, set to 1000ms,


 

//
// get Day
cov rtc2,va0.txt,0
t0.txt=va0.txt
// ? rtc.dow
//  get Month
if(rtc1==1)
{
  t0.txt=t0.txt+" JAN"
}
if(rtc1==2)
{
  t0.txt=t0.txt+" FEB"
}
if(rtc1==3)
{
  t0.txt=t0.txt+" MAR"
}
if(rtc1==4)
{
  t0.txt=t0.txt+" APR"
}
if(rtc1==5)
{
  t0.txt=t0.txt+" MAY"
}
if(rtc1==6)
{
  t0.txt=t0.txt+" JUN"
}
if(rtc1==7)
{
  t0.txt=t0.txt+" JUL"
}
if(rtc1==8)
{
  t0.txt=t0.txt+" AUG"
}
if(rtc1==9)
{
  t0.txt=t0.txt+" SEP"
}
if(rtc1==10)
{
  t0.txt=t0.txt+" OCT"
}
if(rtc1==11)
{
  t0.txt=t0.txt+" NOV"
}
if(rtc1==12)
{
  t0.txt=t0.txt+" DEC"
}
//  get Year
cov rtc0,va0.txt,0
t0.txt=t0.txt+" "+va0.txt
// get Hour
cov rtc3,va0.txt,0
t0.txt=t0.txt+" "+va0.txt
// get Min
if(rtc4<10)
{
  cov rtc4,va0.txt,0
  t0.txt=t0.txt+":0"+va0.txt
}else
{
  cov rtc4,va0.txt,0
  t0.txt=t0.txt+":"+va0.txt
}
// get Sec
if(rtc5<10)
{
  cov rtc5,va0.txt,0
  t0.txt=t0.txt+":0"+va0.txt
}else
{
  cov rtc5,va0.txt,0
  t0.txt=t0.txt+":"+va0.txt
}

 


But what do I fill in here for "???" ?


// Loop and print the time every second.
void loop() {
  myNextion.setComponentText("t0", ???);  //Time
  delay(2000);
 printTime();
  delay(2000);//



Thanks agan..

ok so in my case I used "rtc.getTimeStr() to isolate the time.


myNextion.setComponentText("t0", rtc.getTimeStr());


and it worked.

@Hml9083


You can shorten your code a little as leading zeros can be accomplished to fill two spaces with

cov hr.val,t1.txt,2


Thanks Patrick,  I will apply the changes. 

If my MCU has access to a real time for initial setup and for adjustment, then how to set Nextion RTC time from MCU ? Can those "rtc0, rtc1..." be set from MCU over UART ? Like sending "rtc0=2016" to Nextion as initial setup ?

 

That should work Vlad.


(rtc0=yyyy rtc1=mm rtc2=dd rtc3=hh rtc4=mm rtc5=ss)



Thanks Patrick,  did anybody try it? Although it is logical to use that way but it has to be implemented to allow that ... so far I see only people use nextion editor for setup.

 

Anthony above was doing it from the Arduino side with success.


> ok so in my case I used "rtc.getTimeStr() to isolate the time.

> myNextion.setComponentText("t0", rtc.getTimeStr());

> and it worked.

In this code he is updating Text Component , not rtc0...rtc5 variables...

Did anybody try to set rtc global variables and then read them been updated by Nextion?

Okay I see what you mean


If the Nextion accepts rtc0=2016 inside Event Code then it accepts rtc0=2016 over serial.

There is no code in the firmware checking the source of where variables are being set from.

(Though I don't personally have the enhanced model)

 Patrick, how do you know that?

Code never checks "where global variables update come from", most probably code is driven by the event of that update (unless reads it periodically in the loop... ). The event of setting RTC could be triggered either from HMI event code alone, or from UART event alone or from both. Have you seeing the nextion code to know that?

Login or Signup to post a comment