RTC - Use NTP to rectify DS1307/DS3231 RTC

Preparation

  • Ameba x 1
  • DS1307/DS3231 RTC x 1

Example

In this example, we use NTP to rectify the time of DS1307/DS3231 RTC module.
The following libraries are required:
RTL8195 Wiring Diagram as follows:

1

RTL8710 Wiring Diagram as follows:
1

Open the sample code from “File” -> “Examples” -> “AmebaDS1307RTC” -> “SetTimeNtp”
In the sample code, please provide the ssid/password for WiFi connection. Then compile and upload the sample to Ameba and press reset button. You should see similar log in the Serial Monitor, which means the recification has completed:
1

Code Reference

After the WiFi connection is established, we use NTP to rectify the time of Time library:
setSyncProvider(getNtpTime);

Next, use the time value from Time library to setup the tmElements_t variable, and give the variable to RTC.write()

RTC.write(tm);

Finally, we read RTC time value in loop() every second.

Please confirm that QQ communication software is installed