Displaying External RTC values on Nextion Display

Hello, I currently have a 'Basic' Nextion NX3224T028 display that I am using with an Arduino Uno connected to a DS3231 RTC.

I am a little experienced with Arduino but am inexperienced with Nextion, for now I am trying to display the time and date values from the RTC to the display. Could anyone point me in the right direction? Or to a similar project?

Thank you in advance.

End game I hope to create a data logger (SD) with a few sensor values that I can calibrate with values stored to the Uno eeprom and adjust with the Nextion HMI. Also including a realtime graph to display the sensor values.

Hello @steady96 ,
In my tutorial Using Nextion displays with Arduino i use a clock as an example. My clock does not use an RTC and isn't accurate. Take my clock as a starting point and modify it to use an RTC.

Hi @PerryBebbington,

Thank you, I have had a quick look, I will have a proper bash at it soon enough and will likely have some more questions XD

Hi @PerryBebbington,

I had a look at your code and went through the demonstration which helped understand Nextion (thank you).

With that I created a super simple RTC display which displays the time and date, however upon commenting out:

//rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

To prevent the values resetting, the time disappears from the screen...

Any ideas?

#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 rtc;
void setup() {

 
  Serial.begin(9600);
  rtc.begin();
  //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}

void loop() {
 
  DateTime now = rtc.now();


  char timestring2[9];
  char datestring[10];
  sprintf(timestring2, "%02d:%02d:%02d", now.hour(), now.minute(), now.second());
  sprintf(datestring, "%02d/%02d/%04d", now.day(), now.month(), now.year());

  Serial.print(F("t2.txt=\""));
  Serial.print(timestring2);
  Serial.print(F("\""));
  Serial.print(F("\xFF\xFF\xFF"));
  Serial.print(F("t3.txt=\""));
  Serial.print(datestring);
  Serial.print(F("\""));
  Serial.print(F("\xFF\xFF\xFF"));
}

Thanks again!

Never mind, I cant count :joy:

char datestring[10];

Should have been

char datestring[11];

2 things for you to learn:

Take the code out of loop() and put it into separate functions, like in my example code. Having separate functions makes code easier to read and easier to fix problems.

Only update a display when something changes, in this case the time changes every second so check the value of now.second() and only send an update when it changes.

2 Likes

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