Saturday, September 22, 2018

Arduino : Intermediate - OLED I2C with DS1302 RTC

Description
Demonstrates the use of 128x64 I2C OLED and DS 1302 RTC to display date and time. You can download OLED I2C and DS1302 library at Rinky-Dink Electronic.

List Item
  1. Arduino Uno 
  2. 128x64 I2C OLED  
  3. Pushbutton
  4. RTC DS1302
  5. Wire Jumper

Wiring Diagram

Video




Coding
#include <OLED_I2C.h>
#include <DS1302.h>

OLED  myOLED(SDA, SCL, 8);
DS1302 rtc(2, 3, 4);

extern uint8_t SmallFont[];

void setup()
{
  myOLED.begin();
  myOLED.setFont(SmallFont);
  rtc.halt(false);
  rtc.writeProtect(false);
  rtc.setDOW(FRIDAY);   
  rtc.setTime(12, 0, 0);   
  rtc.setDate(6, 8, 2010); 
}

void loop()
{
  myOLED.clrScr();
  myOLED.print(rtc.getTimeStr(), CENTER, 0);
  myOLED.print(rtc.getDOWStr(FORMAT_SHORT), CENTER, 24);
  myOLED.print(rtc.getDateStr(), CENTER, 50);
  myOLED.update();
  delay(1000);

}

1 comment:

  1. Hello, very interesting simple and fast, and its working out of the box.
    But i have question, how to do it for attiny85? (i mean this code)

    ReplyDelete