-1

I would like to integrate ds1307 clock module as a part of my 'garden automation project' to raspberry pi. The concept of the project is the servo will rotate in a specific time.

So

  1. should I install ds 1307 via terminal first?
  2. after installing via terminal how I can access that time from my Python code?

Working solutions will be appreciated.

  • why don't you just update the system time from an NTP server? – jsotola Feb 24 '19 at 6:11
  • I would like to do an offline project,so cannot access the current time right? – Aboo Sidhu Feb 24 '19 at 6:24
  • When you get the DS1307 set-up correctly it simply provides /dev/rtc0. If you want to read that with python you open that file. This tutorial learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi/… tells you how to get it running (on Jessie, Stretch & Buster). – Dougie Mar 21 at 15:21
0

If you don't have one ds1307 is not the best available module for the Pi. I recommend ds3231 which is a better performer and works from 3.3V

The ONLY thing you have to do is include in /boot/config.txt:

dtoverlay=i2c-rtc,ds1307

While you can access the RTC time, there is little point - just use any means of accessing system time which is synchronised to RTC.

timedatectl will show status of RTC as well as system.

      Local time: Sun 2019-02-24 17:19:42 AEDT
  Universal time: Sun 2019-02-24 06:19:42 UTC
        RTC time: Sun 2019-02-24 06:19:42
       Time zone: Australia/Sydney (AEDT, +1100)
 Network time on: yes
NTP synchronized: yes
 RTC in local TZ: no

sudo hwclock -r will show

2019-02-24 17:21:02.099784+1100
| improve this answer | |
  • So using just 'timedatectl' in python code will get time?,no need to import any library?and how about after power failure – Aboo Sidhu Feb 24 '19 at 6:26
  • You could probably do this and parse the output (if you like doing things the hard way) but it is better to just use any of the normal python time functions. – Milliways Feb 24 '19 at 6:28
  • Excuse me what is my confusion is using normal python time fucntions how i can access ds1307 time(so it will be updated even power off).for example I would like to rotate my servo from 0 to 180 degree on morning 7.am so how will my code looks like ? – Aboo Sidhu Feb 24 '19 at 6:32
  • So you says after modifiying config.txt ,the ds1307 will take care of raspberry system time,so i can access the current time using normal Python time functions right?so will i get the advantage of ds1307(up to date time after power failure)? – Aboo Sidhu Feb 24 '19 at 6:36
  • The whole point of a RTC is to synchronise system time to the RTC - this is done automatically by the support module. There is no need to access the RTC directly. It can be done by reading the RTC registers if really necessary, but you will have to write your own code. – Milliways Feb 24 '19 at 6:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.