User Tools

Site Tools


digispark:tutorials:rtc

Real Time Clock Shield Kit Tutorial

Product Description:

rtc1.jpg rtc7.jpgrtc8.jpg

The Real Time Clock Shield Kit allows you to build a Digispark shield which connects a DS1307 Real Time Clock to the Digispark development board. The DS1307 communicates with the Digispark over the I²C bus. The Real Time Clock Shield can be used to keep accurate time even after the device is powered off. This shield allows the Digispark to be used to make clocks, alarms, or add time and date data to any project.

Note: Due to shipping regulations we are not able to include the CR1220 battery this shield requires. You can pick one up at your local supermarket or very cheap on ebay (for example 5 for $1.39).

This is an unassembled kit and requires basic soldering. This is designed for use with the Digispark development board, which is not included.

Parts:

Part Quantity Identification
Real Time Clock Shield PCB1
4.7K (4K7) Ohm 1/4W resistor 1% or 5%2 Yellow - Violet - Red
8 pin DIP socket 1
DS1307 IC1
CR1220 Battery Clip1
32.768kHz Crystal1
1x40pin male 0.1“ pitch header 9 pins worth
Not Included, but required:
CR1220 Battery

Resistor Values: For more information on how to identify the value of the resistors we recommend these sites: A nice simple resistor calculator: http://www.ealnet.com/m-eal/resistor/resistor.htm A comprehensive article on identification: http://www.diyaudioandvideo.com/Electronics/Color/

Soldering: If you are new to soldering we recommend the following tutorials: Soldering Basics (http://www.sparkfun.com/tutorials/106) and Soldering Crash Course from the folks at Sparkfun (http://www.sparkfun.com/tutorials/354). How to solder from the Curious Inventor: http://store.curiousinventor.com/guides/How_to_Solder

Adafruit has this excellent guide that starts with the tools needed and then shows detailed pictures, including some of the common problems that beginners experience (http://learn.adafruit.com/adafruit-guide-excellent-soldering)

We assume for these assembly instructions that you know the basics of thru-hole soldering. If you don't check out the links above, these boards are very easy to solder - we promise!

Assembly:

NOTE: If you have a “Model B” board you may need to cut the trace to the onboard LED before using any I2C devices - Find out how to tell which board you have and what to do here: modelbi2c

Empty kit bag (or if using a raw PCB, aquire parts) and verify contents. Note for Digistump.com: Headers are not included in each kit bag, but the entire order came with more than enough headers for all kits.

rtc1.jpg

Solder resistors one at a time. Solder the leads and clip off the excess. Repeat for all resistors.

rtc3.jpg

Insert the 8 pin DIP socket into the board matching the indention cut out on one end with the indention printed on the board.

rtc4.jpg

Insert the leads of the crystal - while which lead goes in which hole does not matter, you must ensure the leads do not cross each other. Solder leads and clip off excess.

rtc5.jpg

Insert the battery clip on the bottom of the board - solder where the two tabs come through on the front.

rtc6.jpg

Cut a length of male headers 6 pins long and one 3 pins long. Insert into corresponding positions (on the bottom of the board) and solder each pin.

Tip: Inserting the headers into a breadboard and then placing the board on top can make this process easier.

Note: If you are using stackable headers, use them here instead of the standard male headers.

Insert the DS1307 IC into the 8 pin DIP socket matching the indention cut out on one end with the indention on the socket.

rtc7.jpg

Insert a CR1220 battery into the battery clip. your shield is complete!

rtc8.jpg

Programming:

The pin connections are as follows:

Digispark P0 → SDA

Digispark P2 → SCL

The TinyRTC library is included with the newest copy of the Digispark version of the Arduino IDE - the following examples will work with that version:

Example Clock with LCD Shield

#include <TinyWireM.h>                  // I2C Master lib for ATTinys which use USI - comment this out to use with standard arduinos
#include <LiquidCrystal_I2C.h>          // for LCD w/ GPIO MODIFIED for the ATtiny85
#include <TinyRTClib.h>

RTC_DS1307 RTC;
#define GPIO_ADDR     0x27             // (PCA8574A A0-A2 @5V) typ. A0-A3 Gnd 0x20 / 0x38 for A - 0x27 is the address of the Digispark LCD modules.


LiquidCrystal_I2C lcd(GPIO_ADDR,16,2);  // set address & 16 chars / 2 lines


void setup(){
  
  TinyWireM.begin();                    // initialize I2C lib - comment this out to use with standard arduinos
  RTC.begin();

  if (! RTC.isrunning()) {
    // following line sets the RTC to the date & time this sketch was compiled only for the first run
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
  
  lcd.init();                           // initialize the lcd 
  lcd.backlight();                      // Print a message to the LCD.
  lcd.print("Digispark!");
  delay(1000);
}


void loop(){
DateTime now = RTC.now();

    
    lcd.home();
    
    lcd.print(now.year(), DEC);
    lcd.print('/');
    if(now.month()<10)
    lcd.print("0");
    
    lcd.print(now.month(), DEC);
    
    lcd.print('/');
    
    if(now.day()<10)
    lcd.print("0");
    
    lcd.print(now.day(), DEC);
    
    lcd.setCursor(0, 1);
    
    if(now.hour()<10)
    lcd.print("0");
    
    lcd.print(now.hour(), DEC);
    lcd.print(':');
    
    if(now.minute()<10)
    lcd.print("0");
    
    lcd.print(now.minute(), DEC);
    lcd.print(':');
    
    if(now.second()<10)
    lcd.print("0");
    
    lcd.print(now.second(), DEC);
    
    delay(1000);
}

Example - Output Time over USB using DigiUSB

#include <TinyWireM.h>                  // I2C Master lib for ATTinys which use USI - comment this out to use with standard arduinos
#include <DigiUSB.h>          
#include <TinyRTClib.h>

RTC_DS1307 RTC;

void setup(){
  
  TinyWireM.begin();                    // initialize I2C lib - comment this out to use with standard arduinos
  RTC.begin();

  if (! RTC.isrunning()) {
    // following line sets the RTC to the date & time this sketch was compiled only for the first run
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
  
  DigiUSB.begin();
}


void loop(){
DateTime now = RTC.now();
    DigiUSB.print(now.hour(), DEC);
    DigiUSB.print(":");
    DigiUSB.print(now.minute(), DEC);
    DigiUSB.print(':');
    DigiUSB.println(now.second(), DEC);
    DigiUSB.delay(1000);
}
digispark/tutorials/rtc.txt · Last modified: 2016/06/09 12:03 (external edit)