RTC Module of Linker Kit for pcDuino/Arduino

LinkSprite
$6.50
Be the first to leave a review
SKU LINKER_RTC_O18
Weight 0.10 LBS
Stock
Wishlist

Create Wishlist

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.

 

Download:

 

 

 

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.

 

Wiring Diagram:

photo

 

Wiring Instructions:

  • 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:

  1. $sudo apt-get install git

 

Use the following command to get the repo:

  1. #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)

  1. ubuntu@ubuntu:~/c_enviroment/sample$ more dateset_linker_rtc.c
  2. /*
  3. * RTC test program
  4. */
  5. #include
  6. #include"Wire.h"
  7.  
  8. #define DS1307_I2C_ADDRESS 0x68// This is the I2C address
  9.  
  10. int command =0;// This is the command char, in ascii form, sent from the seria
  11. l port
  12. int zero =0;
  13. //long previousMillis = 0; // will store last time Temp was updated byte second,
  14. minute, hour, dayOfWeek, dayOfMonth, month, year;byte test;
  15. //Convert normal decimal numbers to binary coded decimal
  16. byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  17. byte test;
  18.  
  19. byte decToBcd(byte val)
  20. {
  21. return((val/10*16)+(val%10));
  22. }
  23. // Convert binary coded decimal to normal decimal numbers
  24. byte bcdToDec(byte val)
  25. {
  26. return((val/16*10)+(val%16));
  27. }
  28.  
  29. void setDateDs1307()
  30. {
  31. Wire.beginTransmission(DS1307_I2C_ADDRESS);
  32. Wire.write(zero);
  33. Wire.write(decToBcd(second));// 0 to bit 7 starts the clock
  34. Wire.write(decToBcd(minute));
  35. Wire.write(decToBcd(hour));// If you want 12 hour am/pm you need to set
  36. // bit 6 (also need to change readDateDs1307)
  37. Wire.write(decToBcd(dayOfWeek));
  38. Wire.write(decToBcd(dayOfMonth));
  39. Wire.