RTC (Real Time Clock)

Intro

Every NEXTuino has a built-in RTC of the type RV-2123-C2-TA-QC-020 with buffered power supply. The RTC also runs without external power supply for about 2 weeks. So after a loss of supply voltage you do not have to reconfigure the time. In the user program you can set the hour, minute, second, day, weekday, month and year. These values can be prompted and can be used directly or in logical combination with other conditions as a trigger for specific operations.

IMPORTANT: Please select the proper target board in Tools > Board > NEXTuino RISE/MAXI/MEGA before uploading to your NEXTuino.

Hardware Required

  • NEXTuino RISE/MAXI/MEGA
  • 12/24V DC Power supply

Circuit

On NEXTuino RISE the “RTC” switch is made for switching the internal RTC (Real Time Clock) onto the SPI bus. If you use the RTC in your program, the switch has to be in the “1” position, otherwise there would be no data connection to the RTC.

Note: Pin header is working on 5V TTL levels. Voltage levels over 5.5V can damage the NEXTuino permanently.

Code

To set initial values to the RTC chip use the function from the NEXTuino Library:

NEXTuino_SetTimeDate(31,2,1,17,8,37,23); // (Day of the month, Day of the week, Month, Year, Hour, Minute, Second)
#include <SPI.h>
#include <NEXTuino.h>

void setup() {
  Serial.begin(9600);
  NEXTuino_RTC_init(0);
  NEXTuino_SetTimeDate(31,2,1,17,8,37,23); // set initial values to the RTC chip
}

void loop() {
  int n;
  Serial.print("Day: "); n = NEXTuino_GetDay(); Serial.println(n);
  Serial.print("WeekDay: "); n = NEXTuino_GetWeekDay(); Serial.println(n);
  Serial.print("Month: "); n = NEXTuino_GetMonth(); Serial.println(n);
  Serial.print("Year: "); n = NEXTuino_GetYear(); Serial.println(n);
  Serial.print("Hour: "); n = NEXTuino_GetHour(); Serial.println(n);
  Serial.print("Minute: "); n = NEXTuino_GetMinute(); Serial.println(n);
  Serial.print("Second: "); n = NEXTuino_GetSecond(); Serial.println(n);
  delay(5000);
}