RTC - Read from DS1307/DS3231 RTC module


  • Ameba x 1
  • DS1307/DS3231 RTC x 1


DS1307 is a common RTC IC, and is used in TinyRTC. If you higher precision is required, DS3231 can be used instead.
Please download following libraries first,
DS1307 RTC library:
Follow the tutorial to install the .zip library to Ameba:


The RTC library supports DS1307, DS1337 and DS3231. It uses I2C interface, and works at 3.3V.
Please open the sample code from “File” -> “Examples” -> “AmebaDS1307RTC” -> “ReadTest”
In this example, we read time value from DS1307/DS3231.
If you are using TinyRTC (DS1307), please do the wiring as the figure below:

If you use DS3231, please refer to the wiring diagram:

RTL8710,wiring diagram as follows:

Then compile and upload the sample to Ameba and press reset button. You should see similar log in the Serial Monitor:

Code Reference

In loop(), we declare a variable with type struct tmElements_t to store the time-related data.

tmElements_t tm;

Next, call RTC.read() to store the data into the tmElements_t variable.


The data structure in tmElements_t:

typedef struct  { 
  uint8_t Second; 
  uint8_t Minute; 
  uint8_t Hour; 
  uint8_t Wday;   // day of week, sunday is day 1
  uint8_t Day;
  uint8_t Month; 
  uint8_t Year;   // offset from 1970; 
}  tmElements_t, TimeElements, *tmElementsPtr_t;
Please confirm that QQ communication software is installed