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

https://www.banggood.com/Geekcreit-45-In-1-Sensor-Module-Board-Kit-Upgrade-Version-For-Arduino-p-1137050.html?p=W214159476515201703B

https://www.banggood.com/Orange-Pi-Zero-H2-Quad-Core-Open-source-512MB-Development-Board-p-1110210.html?p=W214159476515201703B

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

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 pinout 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 https://github.com/xpertsavenue/WiringOP-Zero .

git clone https://github.com/xpertsavenue/WiringOP-Zero
cd WiringOP-Zero
chmod +x ./build
./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

$./ds1302
    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.

One thought on “Setting up DS1302 RTC Geekcreit kit with Orange Pi Zero

Leave a Reply

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