Help ... I can not set RTC - module with DS1302

Hello everyone
I bought this RTC module

http://www.hobbytronics.co.uk/raspberry-pi-real-time-clock

I can not boot the steps to compile and make working the clock, I'm trying to follow the guidance of the link, but I can not.

Kindly who can help me.

Happy New Year to all

Robert Wall's picture

Re: Help ... I can not set RTC - module with DS1302

"I'm trying to follow the guidance of the link, but I can not."
Why not? What does not work? Do you see errors - what are they?

[Edit]
I downloaded the code. There are two files in the zip download: "rtc-pi" and "rtc-pi.c".
"rtc-pi" is already compiled, therefore you copy the file to your SD card then do as the instructions tell you from here:


And make it executable using

chmod +x rtc-pi

Setting the Date and Time
To set the data and time on the module use


sudo ./rtc-pi CCYYMMDDhhmmss


And to read the date and time from the module and set the Raspberry Pi clock



sudo ./rtc-pi



You should set this command to run when the Raspberry Pi boots up. There are many ways to do this, so we will leave it up to you to decide which method is best for you.

serbat's picture

Re: Help ... I can not set RTC - module with DS1302

hello  Robert thanks for the reply

in fact the one you quoted is what you want to do, but while not giving the time errors if reboot the raspberry, it is not correct, then I wondered what mistake.

I copied the file rtc-pi.c in sd card in the "boot" partition and wondered if it was correct.

Since I have to change a few lines of the file rtc-pi.c seen that use the raspberry B + I also have to recompile the file, giving the command "" cc media / boot / rtc-pi.c "" but does not do anything.

So I follow the instructions but definitely something wrong, thanks again for the help

Robert Wall's picture

Re: Help ... I can not set RTC - module with DS1302

"" cc media / boot / rtc-pi.c ""
You should not have spaces in there!

Try changing to the directory where rtc-pi.c is located. First, find where it is:

  whereis rtc-pi.c

then cd to there.

Then try:

  cc rtc-pi.c

serbat's picture

Re: Help ... I can not set RTC - module with DS1302

hello  Robert thanks for the reply

On that partition I increased the space.
My main doubt is that each command does not give me any error but nothing works.
I wanted to be sure of the procedure and where to run

Robert Wall's picture

Re: Help ... I can not set RTC - module with DS1302

Do you have ANY response to ANY command?

what does this do?

  ls

serbat's picture

Re: Help ... I can not set RTC - module with DS1302

This is the screen.

The file rtc-pii, I created but I can not find it.

Robert Wall's picture

Re: Help ... I can not set RTC - module with DS1302

I see now where you are! In the 'boot' volume was the wrong place. Putty is looking (for me) at "/home/pi" inside "2.9 GB Volume" where you have bin, boot, dev, etc, home, lib... and you need to move the file rtc-pi.c into the directory /home/pi

Then you can see it using Putty.

Now the instructions will work. If you see the error: "Cannot open output file a.out: Read-only file system.... "

do rpi-rw (NOT rpi -rw)

when you have finished, do rpi-ro to make the file system read-only again.

serbat's picture

Re: Help ... I can not set RTC - module with DS1302

I do not understand I seem to do everything correctly, but if I turn off and turn on the raspberry the date is not updated.

 

ps: the screen in local emoncms, you can not see the time that used to record the data?

 

 

Robert Wall's picture

Re: Help ... I can not set RTC - module with DS1302

Are you doing
  rtc-pi
automatically when the RPi starts up?
Do a Google search (in Italian) for "execute command at startup Raspberry Pi"

serbat's picture

Re: Help ... I can not set RTC - module with DS1302

Thanks again for the answer

No, I think that once installed rtc would send automatic time, while I understand it I have to start all times the file "rtc-pi" with an automatic.
Then the command "chmod + x rtc-pi" what is it?

pb66's picture

Re: Help ... I can not set RTC - module with DS1302

Mmmmmmh, not the best product or instructions I've seen,

The DS1302 chip uses a slightly quirky serial interface which we won't go into here.

Isn't very reassuring to start with. Moving on to 

Note: If you find you cannot set the date and time, there is a write protect register value which needs to be cleared (register 0x8E). We have had a few of these modules where this write protect has been turned on. You can clear it by setting register 0x8E to 0 in code, or by simply removing the battery and re-inserting it (The default value for the register is off)

Have you tried removing the battery to reset it ?

There is a wiring diagram on the EPE magazine page, but unfortunately it is wrong as they have CLK connected to GPIO#17 and RST (CE) connected to GPIO#21. These two connections should be swapped.

Are you using the corrected connections?

And to read the date and time from the module and set the Raspberry Pi clock

sudo ./rtc-pi

This isn't clear if it will actually "show" the time and date or just set the Pi's time and date to match the rtc's behind the scene's, if you are not getting any confirmation try running the command " date " then changing the rtc's time & date to something obviously different, run " sudo ./rtc-pi " and then " date " again to see if you are getting a change.

You should set this command to run when the Raspberry Pi boots up. There are many ways to do this, so  we will leave it up to you to decide which method is best for you.

You will need to create a method of automating this command to run at start up or remember to manually run it every so often, it won't run at start up unless you set it up to do so.

In an earlier post you said

" Since I have to change a few lines of the file rtc-pi.c seen that use the raspberry B + "

If that is due to the "Changes for Raspberry Pi V2 boards" section at the end of the page, as it also says

I also found that a pullup resistor is needed between DAT and VCC (= 3.3V). A 10k..30k resistor seems to work fine.

did you also fit the pull-up resistor?

Paul

serbat's picture

Re: Help ... I can not set RTC - module with DS1302

I fear that it is complicated to my knowledge, anyway .... I will continue to do the tests.

I will try to disconnect the battery to reset the module, and in a second time I will get the resistance.

I'll try to find a way to start automatically when you start the file rtc-pi, eventually will change the connections as you suggested, I will check using the model raspberry B + so I edited the file as the guide advised.
I will keep you updated on the tests done, if you have other suggestions, in particular on how to start the file automatically, kindly inform me.

Thank you all for your cooperation.

pb66's picture

Re: Help ... I can not set RTC - module with DS1302

Adding the command to /etc/rc.local will run it at start up, use this line to insert it into the file before "exit 0"

sudo sh -c "sed -i '/^exit 0/i\sudo ./rtc-pi\n' /etc/rc.local"

 

 

Bill Thomson's picture

Re: Help ... I can not set RTC - module with DS1302

Not to complicate matters, but since adding an RTC to my Pi is one of the things I've been considering, I did some searching and found a few articles that mention removing fake-hwclock, and starting the add-on RTC by modifying /etc/init.d/hwclock.sh instead of adding a line to /etc/rc.local.

In addition to removing the fake-hwclock itself, the fake-hwclock cron jobs need to be removed too. (covered in the article linked to in step 3, below)

www.raspberrypi.org/forums/viewtopic.php?f=66&t=85683

Excerpt form the article at the link above:

SO .... here's what to do. I've only tried this using a ds1307 based RTC module, but it should work (with appropriate changes) for RTCs based on other I2C clock chips.

Step 1: Follow the instructions on the Adafruit site https://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi?view... to get your I2C RTC connected and tested, but DO NOT make the suggested changes to /etc/rc.local

Step 2:Make the changes to /etc/init.d/hwclock.sh as described here http://www.elevendroids.com/2012/12/setting-up-hardware-rtc-in-raspbian/

Step 3: Ignore the first part of http://blog.remibergsma.com/2013/05/08/ ... pberry-pi/ but do follow the instructions on removing the fake-hwclock.
 

serbat's picture

Re: Help ... I can not set RTC - module with DS1302

Thanks paul feel for the first suggestion that seems to me the simplest .

I just want to ask you which folder should be the file rtc -pi

serbat's picture

Re: Help ... I can not set RTC - module with DS1302

Well a step forward has been made ...
I removed the battery
starting with "startx" the graphic terminal and typing "./rtc-pi" shows me the correct time.

Except that if you restart the raspberry gives me an error of which I include photos, maybe put in the syntax file "rc.local" is wrong

This is my text in the file "rc.local"

*********************************************
#! / bin / sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure That the script will "exit 0" on success or any other
# Value on error.
#
# In order to enable or disable this script just change the execution
# Bits.
#
# By default this script does nothing.

# Print the IP address
_IP = $ (Hostname -I) || true
if ["$ _IP"]; then
   printf "My IP address is% s \ n" "$ _IP"
fi

#riga inserted to start rtc-pi startup 02/02/15-sergio
  sudo ./rtc-pi

sudo sh -c "sed -i '/ ^ exit 0 / i \ sudo ./rtc-pi\n' /etc/rc.local"

exit 0

********************************************
The line of code highlighted "sudo ./rtc-pi" has included him automatically, I just inserted
that which thou hast attached

I enclose also has pictures of the screen with error

 

 

pb66's picture

Re: Help ... I can not set RTC - module with DS1302

serbat, My fault for not specifying the location. and the command I suggested was intended to do the edit for you not to be put in the rc.local itself, sorry I should of been clearer. If you edit /etc/rc.local so the last lines are

#riga inserted to start rtc-pi startup 02/02/15-sergio
sudo /home/pi/data/rtc-pi

exit 0

This should get you running at least.

The location of rtc-pi isn't great and using an init script is preferable to using rc.local. But this was the simplest way for now. 

Hi Bill - I also looked into this when tackling the read-only sd card issues and found a wide variety of info, this article is a good example of a compilation of facts and is quite common, there is also a lot of good info out there but it's not always clear which is which.

Using init scripts is the preferred method for any daemon, However I wouldn't recommend editing the fake-hwclock's init script to suit as A) if you have fully removed fake-hwclock correctly it shouldn't exist and B) any edits you do make could easily be overwritten if there is an update to fake-hwclock.

​I too prefer the idea of an I²C connected rtc and the type I favor can work with fake-hwclock, The rtc is added as a ntp server and the Pi is none the wiser to the fact ntp is contacting the connected rtc rather than a remote server. So the fake-hwclock is still used in the moments prior to establishing the correct time during boot up and will continue to operate long after the battery has expired on the rtc.

Some rtc's can also perform minor ongoing corrections and/or be corrected by ntp so they need to be kept running. I did buy a couple to play with but haven't done anything with them yet.

Regards serbats device I do not know exactly how it works so advice is vague and less specific, will it work in a read only file-system? does it use "ntp standard commands" and fit in with raspbian's existing ntp system? or does it just fetch the time at start up?  there are many possibilities.

Paul

Bill Thomson's picture

Re: Help ... I can not set RTC - module with DS1302

Hello Paul,

Using init scripts is the preferred method for any daemon, However I wouldn't recommend editing the fake-hwclock's init script

The script the article talks about editing is /etc/init.d/hwclock.sh, as opposed to /etc/init.d/fake-hwclock

As you mentioned, if /etc/init.d/fake-hwclock is removed properly, (purged) it wont exist.

Regards,

Bill

 

 

serbat's picture

Re: Help ... I can not set RTC - module with DS1302

thanks Paul

Now everything is working.

Thanks again ...

pb66's picture

Re: Help ... I can not set RTC - module with DS1302

Excellent news serbat :-)

Hi Bill - I had indeed missed the fact it was the hwclock init rather than the fake-hwclock init but (IMHO) it still isn't good practice as an update to hwclock could easily overwrite the changes, it would be better to write an additional one as it's not too difficult.

Paul

Bill Thomson's picture

Re: Help ... I can not set RTC - module with DS1302

it would be better to write an additional one as it's not too difficult.

If nothing else, a renamed copy of the original file would be a reasonable starting point to write one's own, wouldn't it?

 

pb66's picture

Re: Help ... I can not set RTC - module with DS1302

You could definitely go that route, however I haven't compared the init scripts to see how much that helps. There is also a basic template included in raspbian /etc/init.d/skeleton.

rjmsr's picture

Re: Help ... I can not set RTC - module with DS1302

Problems with RPi2

Have use the DS1302 module and software with good success on RPi B ver 2 and also RPi B+. Now that I have a new RPi 2, I cannot get the unit to update my time.

Setting time to the module seems OK, no errors indicated.

In reading time /rtc $ sudo ./rtc-pi

I get the message"Unable to change the system time. Did you run the program as administrator? The operation returned the message "Invalid Argument"".

The module works fine on the B+ and RPi B ver 2.

I re-compiled the .c program on the RPi2 as I did on the original unit thinking that was the problem..No change.

Am I overlooking something?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.