Setting up DS1302 RTC Geekcreit kit with Orange Pi Zero

As part of a Geekcreit sensor kit which I recently got from banggood, there was this RTC aka Real Time Clock module. Out of the list of 45 sensors  , I picked this one as my first to get it working with Arduino and Orange Pi Zero.

The Real Time Clock module is used in projects where you need to know the date and the time. Now there are many methods to fetch time to a system. Some of the common methods depending on the location of the project are Network Time Server, GPS and if you are in Germany you can also use DCF77. In these methods it depends on wireless or Internet communication and depending on your project it might be an unreliable source of time keeping. So here comes the RTC, where there is a small chip which is always run by a coin cell battery to maintain the time. If you ever open your PC or laptop you can see BIOS battery which does keep your RTC running and that is how you get the right date and time even after you shutdown.

Hardware Required:

If you want to setup Orange Pi Zero from scratch then follow my earlier post on How to setup Orange Pi Zero.

Real Time Clock Module:

The RTC Module is using the chip DS1302 from Dallas. In the first glance its deceivingly looking like a chip which supports  I2C  and then later after reading the datasheet it was clear that it does not use I2C instead it uses a simple serial interface.The DS1302  provides seconds, minutes, hours, day, date, month, and year information. The end of the month date is automatically adjusted for months with fewer than 31 days, including corrections for leap year. The clock operates in either the 24 hour or 12 hour format with an AM/PM indicator. The chip pin out looks like this.

The Vcc2 and GND are the power supply to the chip, X1 and X2 are connected to oscillator, Vcc1 and GND is used by 3V CR2032 coin cell battery and the pins CLK, IO and CE are part of the simple serial interface or otherwise called 3-wire interface. Basically its much similar to SPI just that MISO and MOSI are multiplexed in to a single IO line.




Orange Pi Zero Connection:

I used Orange Pi Zero  for this connection. I used Pin 2, 0 and 6 for CLK , IO and CE. The pin numbering I use is based on Wiring Pi and not Orange Pi for better understanding refer to the images below.













DS1302 Library:

I am using wiringPi library for Orange Pi Zero. you can get it from here, .

git clone
cd WiringOP-Zero
chmod +x ./build

I have modified the example code, which exist in WiringOP-Zero/examples/ds1302.c

cd WiringOP-Zero/examples/
###open the ds1302.c
vi ds1302.c
####replace ds1302setup   (0, 1, 2) ;
ds1302setup(2, 0, 6) ;
#### recompile
make ds1302


The output of the code,

    0: 12:45:21 22/03/2017
    1: 12:45:22 22/03/2017
    2: 12:45:23 22/03/2017
    3: 12:45:24 22/03/2017

You can use this module for making project such as alarm clock, stop watch, pomodoro timer, scheduled timer for task like watering plant and many more.

2 thoughts on “Setting up DS1302 RTC Geekcreit kit with Orange Pi Zero

  • Pingback: Awesome Geeky Sensor Kit for Arduino and Pi boards – Codelectron

  • August 13, 2019 at 5:04 pm

    all good so far but what about fake-hwclock (it is installed on most o/s by default now) ?
    I call the ds1302 during boot up to set the time then later during boot fake-hwclock jumps in saying the time is set in the past bla bla and I also have a shutdown script that then writes the time back to the ds1302 as the system is powering off so in theory the time should be saved correctly.

    p.s re-write your txt as it is a bit misleading about plugging it to 3.3+v and gnd, it reads as if only the 3 wires need to be connected (clk,Dat & rst)

    nice work tho you saved me a few hours of brain power.


Leave a Reply

Your email address will not be published. Required fields are marked *