arm2
Posts: 253
Joined: Thu Dec 15, 2011 3:46 pm

Instructions to Configure DS1307 or DS1338 RTC

Tue Dec 11, 2012 9:25 pm

To enable support for the RTC in Raspbian Wheezy' (2012-10-28 or later),
the following lines need to be added to /etc/rc.local above the exit0 line:

modprobe i2c-bcm2708
echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device
modprobe rtc-ds1307
hwclock -s

These instructions should work with any DS1307 or DS1338 Real Time Clocks, it has been tested with CJE Micro's/4D RTC http://www.cjemicros.co.uk/micros/indiv ... eClock-RTC

If anyone has any problems or suggestions re this please post here.

Chris Evans (CJE Micros's & 4D)

repton
Posts: 93
Joined: Sat Mar 17, 2012 6:06 pm
Location: Aberdeenshire, UK
Contact: Website

Re: Instructions to Configure DS1307 or DS1338 RTC

Wed Dec 12, 2012 12:35 am

arm2 wrote:To enable support for the RTC in Raspbian Wheezy' (2012-10-28 or later),
the following lines need to be added to /etc/rc.local above the exit0 line:

modprobe i2c-bcm2708
echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device
modprobe rtc-ds1307
hwclock -s
It's important to note that if you are using a Rev2 RasPi then you need to replace i2c-0 with i2c-1.

Paul
UK Supplier of 1-Wire components, kits and modules:
http://www.sheepwalkelectronics.co.uk/

arm2
Posts: 253
Joined: Thu Dec 15, 2011 3:46 pm

Re: Instructions to Configure DS1307 or DS1338 RTC

Tue Dec 18, 2012 8:29 pm

Thanks for that info:

Not elegant but would

modprobe i2c-bcm2708
echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device
echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
modprobe rtc-ds1307
hwclock -s

work?

I'm used to RISC OS where you could have a utility that sets a system variable and then you can have conditional execution in the boot script like:
modprobe i2c-bcm2708
IF Rev$Pi=0 THEN echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device
IF Rev$Pi>0 THEN echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
modprobe rtc-ds1307
hwclock -s

Schorschi
Posts: 255
Joined: Thu Nov 22, 2012 9:38 pm

Re: Instructions to Configure DS1307 or DS1338 RTC

Sat Apr 13, 2013 3:44 pm

On Fedora ARM on Pi...

# echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
-bash: echo: write error: Invalid argument

Does not seem to work on my Model 2. However, I am still able to set and query the RTC clock. So new_device is set somehow.

Schorschi
Posts: 255
Joined: Thu Nov 22, 2012 9:38 pm

Re: Instructions to Configure DS1307 or DS1338 RTC

Sat Apr 13, 2013 4:13 pm

Thinking more about this... I pulled my older Model 2 with only 256 MB out of obsolete drawer... and tried the same steps, making sure the Fedora ARM image was pristine... since my work bench Model 2 Fedora image has I2C, SPI, and more goodies support already loaded. Long story short the steps as document work, I don't get the invalid write error.

# echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
# echo $?
0

Schorschi
Posts: 255
Joined: Thu Nov 22, 2012 9:38 pm

Re: Instructions to Configure DS1307 or DS1338 RTC

Wed Jun 12, 2013 3:40 am

Just an update... Fedora 18 ARM... support ds1307 has been dropped. This is a real disappointment, because I have i2c ds1307 add-on boards for a few of my Pi devices, and now it appears I have to remain on Fedora 17, or change distributions. Best I can determine, Fedora ARM team decided that since ds1307 based RTCs are not a consistent feature of ARM devices, there was no need to continue support because it establishes what they called an inconsistent platform? Whatever that means.

Reference...
https://lists.fedoraproject.org/pipermail/arm/2013-January/005066.html

jwasch
Posts: 12
Joined: Wed May 01, 2013 3:10 pm

Re: Instructions to Configure DS1307 or DS1338 RTC

Mon Nov 04, 2013 1:54 am

Is anyone aware of any updates to this issue relating to DS1307 support in Fedora 18 (Pidora)?

It appears only the command:

echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_devices

is failing, but that other commands are working okay, such as:

hwclock -r ... to "read" contents of RTC
hwclock -s ... to "set" time/date from contents of RTC
hwclock -w ... to "write" current date into RTC


This presumes performing a "modprobe rtc-ds1307".

Is the "echo ds1307 0x68" command needed for anything?

MarkoSiroki
Posts: 11
Joined: Sun Jun 22, 2014 9:03 am

Re: Instructions to Configure DS1307 or DS1338 RTC

Thu Feb 05, 2015 11:05 am

I cannot run

Code: Select all

echo "ds1307 0x68" > /sys/class/i2c-adapter/i2c-1/new_device
inside bash script because it gives me error:
line 3: echo: write error: Invalid argument
. Why?!

DirkS
Posts: 10618
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Instructions to Configure DS1307 or DS1338 RTC

Thu Feb 05, 2015 12:46 pm

MarkoSiroki wrote:I cannot run

Code: Select all

echo "ds1307 0x68" > /sys/class/i2c-adapter/i2c-1/new_device
inside bash script because it gives me error:
line 3: echo: write error: Invalid argument
. Why?!
What model pi do you have?
Which OS and OS version?
Which kernel version?

JamesT42
Posts: 1
Joined: Mon Feb 09, 2015 9:55 pm

Re: Instructions to Configure DS1307 or DS1338 RTC

Mon Feb 09, 2015 9:57 pm

Try

Code: Select all

echo "ds1307 0x68" | sudo tee /sys/class/i2c-adapter/i2c-1/new_device

jchernus
Posts: 5
Joined: Fri Mar 13, 2015 3:16 pm
Location: Saskatoon, Saskatchewan

Re: Instructions to Configure DS1307 or DS1338 RTC

Wed Apr 29, 2015 7:50 pm

I'm having the same problem.

Details:

Raspberry Pi Model B
Linux raspberrypi 3.18.7+ #755 PREEMPT Thu Feb 12 17:14:31 GMT 2015 armv6l GNU/Linux

Thank in advance!

Julia

User avatar
DougieLawson
Posts: 41047
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Instructions to Configure DS1307 or DS1338 RTC

Wed Apr 29, 2015 9:50 pm

Take a look at /boot/overlays/README if dtoverlay=i2c-rtc is documented in there then you've got kernel support.

If it's not there run sudo rpi-update (to get to 3.18.12).

Add

Code: Select all

dtoverlay=i2c-rtc,ds1307
to /boot/config.txt then reboot and your RTC will be running with nothing needed. No strange echo commands are needed.
Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

jchernus
Posts: 5
Joined: Fri Mar 13, 2015 3:16 pm
Location: Saskatoon, Saskatchewan

Re: Instructions to Configure DS1307 or DS1338 RTC

Fri May 01, 2015 3:32 pm

Thank you,

I do indeed have the following in the /boot/overlays/README

File: ds1307-rtc-overlay.dtb
Info: Configures the DS1307 Real Time Clock
Load: dtoverlay=ds1307-rtc
Params: <none>


I am able to query and set the hwclock. However, for some reason the hwclock is being set by the system clock on bootup (instead of the other way around).

It's behaviour is the following:

I set the system time to ‘Fri May 1 2015, 7:10AM’.
I set the hwclock time to ‘Fri May 1 2015, 7:10AM’.

I wait five minutes.

Times have moved forward 5 minutes appropriately (‘Fri May 1 2015, 7:15AM’).

I shut the RPi down, wait 5 minutes.

Boot up, and both are set to ‘Fri May 1 2015, 7:15AM’.
Ideally, both would show ‘Fri May 1 2015, 7:20AM’.


Do you have any idea what startup script could be causing this?

Thank you,

Julia

User avatar
DougieLawson
Posts: 41047
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Instructions to Configure DS1307 or DS1338 RTC

Fri May 01, 2015 5:13 pm

You need to get rid of fake-hwclock and ensure that hwclock gets run at shutdown and again at restart.
Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

retknow
Posts: 16
Joined: Fri Jan 31, 2014 10:56 am

Re: Instructions to Configure DS1307 or DS1338 RTC

Thu Oct 22, 2015 9:44 pm

I am having the same problem.
When I do

Code: Select all

sudo i2cdetect -y 1
it shows my DS3231 as 68

Code: Select all

pi@raspberrypi ~ $ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --                         
. But when I do the

Code: Select all

oech ds1307 0x68 >>  /sys/class/i2c-adapter/i2c-1/new_device
command I get the "permission denied" message.

Code: Select all

echo ds3231 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
bash: /sys/class/i2c-adapter/i2c-1/new_device: Permission denied
I have a model B+
I am quite new here, so please answer in laymen terms

haccks
Posts: 15
Joined: Thu Aug 11, 2016 12:39 pm

Re: Instructions to Configure DS1307 or DS1338 RTC

Fri Aug 12, 2016 3:52 pm

DougieLawson wrote:Take a look at /boot/overlays/README if dtoverlay=i2c-rtc is documented in there then you've got kernel support.

If it's not there run sudo rpi-update (to get to 3.18.12).

Add

Code: Select all

dtoverlay=i2c-rtc,ds1307
to /boot/config.txt then reboot and your RTC will be running with nothing needed. No strange echo commands are needed.
Thanks for this. I added

Code: Select all

dtoverlay=i2c-rtc,ds1307
to /boot/config.txt and after reboot I checked hardware clock with

Code: Select all

sudo hwclock -r
. It's showing correct time but the system clock is not set with hardware clock time. What to do now?

Return to “Interfacing (DSI, CSI, I2C, etc.)”