Amanduino - Arduino's clone

Libraries‎ > ‎

RTC

Summary

RTC (Real Time Clock) library supports built-in DS1307 clock.

Include

#include <RTC.h>

Structures

struct RTCTime
{
  uint8_t second;
  uint8_t minute;
  uint8_t hour;
  uint8_t day;
  uint8_t month;
  uint8_t year;
  uint8_t dayOfWeek;
};

Procedures

RTC.set(year, month, day, dayOfWeek, hour, minute, second)

RTC.set(tm)

RTC.set allows you set current date and time in DS1307 chip. If you use a backup battery, the time in the chip will be saved, otherwise you have to set time always after power cut.

Example #1
#include <RTC.h>

void setup()
{
  // Set 2009-05-11 14:10:00
  RTC.set(9, 5, 11, 0, 14, 10, 0);
}

Example #2
#include <RTC.h>

void setup()
{
  RTCTime tm;
  
  tm.year = 9;
  tm.month = 5;
  tm.day = 11;
  tm.dayOfWeek = 0;
  tm.hour = 14;
  tm.minute = 10;
  tm.second = 0;
 
  RTC.set(tm);
}

Functions

RTCTime RTC.time()

Allows you to get the current time (returns RTCTime structure). You need to set the time before using that. 

Example #1
#include <RTC.h>

void setup()
{
  Serial.begin(9600);
  
  RTCTime tm = RTC.time();
  
  // Print current hour
  Serial.println(tm.hour, DEC);
}

Download

You can download the RTC library from our Libraries repository.

Advanced

Addressing

The RTC chip communicates with processor using I2C protocol. The address of DS1307 is hard-written as DS1307_I2C_ADDRESS macro constant (in RTC.h file) - default it is 0x68. If you need you can change value using a code similar to that one.

Example #1 (advanced)
// ..
#include <RTC.h>

// Change address
#undef DS1307_I2C_ADDRESS
#define DS1307_I2C_ADDRESS 0x53

// ...

Amanduino

Amanduino is a clone of popular Arduino platform. It has 30kB for user program, 2kB RAM and 1kB EEPROM, 14 digital input/output pins (1 UART, 6 PWM ports) and 6 analog inputs, built-in Real Time Clock. It's really small just 5.4x5.4 cm (2.1x2.1"). Amanduino is breadboard ready and Arduino shields compatible.

Twitter

Follow Amanduino on Twitter!

Pre-order

You can pre-order Your new Amanduino. Just $25 via Paypal. Starting production in July!

Libraries

Recent site activity

License