RTC - Using DS1307/DS3231 RTC as time source
Preparation
- Ameba x 1
- DS1307/DS3231 RTC x 1
Example
In this example we use DS1307/DS3231 RTC module as time source. The main difference between DS1307 and DS3231 is that DS3231 provides higher precision. The following two libraries are required:
Time:
https://github.com/ambiot/amb1_arduino/raw/master/Arduino_libraries/Time-1.0.1.zip
Time:
https://github.com/ambiot/amb1_arduino/raw/master/Arduino_libraries/Time-1.0.1.zip
DS1307RTC:
https://github.com/ambiot/amb1_arduino/raw/master/Arduino_libraries/DS1307RTC-1.0.0.zip
Follow the tutorial to install the .zip library to Ameba: https://www.arduino.cc/en/Guide/Libraries#toc4
https://github.com/ambiot/amb1_arduino/raw/master/Arduino_libraries/DS1307RTC-1.0.0.zip
Follow the tutorial to install the .zip library to Ameba: https://www.arduino.cc/en/Guide/Libraries#toc4
The detailed description of DS1307/DS3231 please refer to the example of DS1307/DS3231.
If you are using TinyRTC, please connect the wires as follows:
As for DS3231, please refer to the figure below:
RTL8710 wiring diagram:
Open the sample code in “File” -> “Examples” -> “AmebaTime” -> “TimeRTC”, compile and upload the sample to Ameba and press reset button. Then open the serial monitor, you should see messages similar to the figure:
Code Reference
This example uses RTC as time source:
setSyncProvider(RTC.get)
RTC.get() returns current time in unix-like format, and the returned value would be the time source of Time library.
Copyrights ©瑞晟微电子(苏州)有限公司 2021. All rights reserved. Terms of Use