This is a RTC module with Linker kit standard connection. It has an I2C interface.
Note: The battery is NOT included, and the button battery model is CR1225.
pcDuino does’t have on-board RTC. It will automatically sync its time when it gets network connection. What if we want to run pcDuino without network connection? If you still want your pcDuino to have the capability to correct date and time, consider to add a RTC to your pcDuino!
In this post, we will show how to interface Linker RTC module to pcDuino, and have pcDuino automatically sync its date/time from Linker RTC.
Linker RTC module uses DS1307 RTC chip, and interfaces to pcDuino using I2C.
- GND of Linker RTC module -> GND of pcDuino
- VCC of Linker RTC module -> 5V of pcDuino
- SDA of Linker RTC module -> SDA of pcDuino
- SCL of Linker RTC module -> SCL of pcDuino
Obtain pcDuino’s Arduio-ish C environment:
If you don’t have git installed, please do:
- $sudo apt-get install git
Use the following command to get the repo:
- #git clone https://github.com/pcduino/c_enviroment
C code to test Linker RTC module:
Under the c_enviroment/sample directory, there is a file named “linker_rtc_test.c”. The executable is located at “c_enviroment/output/test”.
To set the date/time, please using:
a) ./linker_rtc_test [Year] [Month] [Date] [Hour] [Minute] [Second].
b) Check the outputs on you terminal.
Note: [Year] [Month] [Date] [Hour] [Minute] [Second] are optional parameters.
C code to set date/time:
When pcDuino boots, it will automatically run script /etc/rc.local. We call a program which will read the date/time from Linker RTC and set the system date.
The C code to read date/time from Linker RTC module, and set date/time is as following:
dateset_linker_rtc( download here)
- ubuntu@ubuntu:~/c_enviroment/sample$ more dateset_linker_rtc.c
- * RTC test program
- #define DS1307_I2C_ADDRESS 0x68// This is the I2C address
- int command =0;// This is the command char, in ascii form, sent from the seria
- l port
- int zero =0;
- //long previousMillis = 0; // will store last time Temp was updated byte second,
- minute, hour, dayOfWeek, dayOfMonth, month, year;byte test;
- //Convert normal decimal numbers to binary coded decimal
- byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
- byte test;
- byte decToBcd(byte val)
- // Convert binary coded decimal to normal decimal numbers
- byte bcdToDec(byte val)
- void setDateDs1307()
- Wire.write(decToBcd(second));// 0 to bit 7 starts the clock
- Wire.write(decToBcd(hour));// If you want 12 hour am/pm you need to set
- // bit 6 (also need to change readDateDs1307)