1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Getting a Raspberry Pi to read a Real Time Clock

Discussion in 'General Computer Discussions' started by Yellow Fang, 18 May 2016.

  1. Yellow Fang

    Yellow Fang Veteran Geek

    Location:
    Reading
    At work I have been trying to get a Raspberry Pi to load up the system clock from a small RTC module that fits on some of the GPIO pins. The major problem, which I was not aware of at first, is that it has to set the system clock before another service starts. If the other service starts first, it overwrites the previous logs with a 1970 date. First I amended the shell file to update the system clock from \etc\init.d\rc.local. That did update the system clock from the RTC, but only after a minute or two. Then I changed the shell files to update the system clock from rc2.d using the update-rc.d commands. This did not seem to work particularly well; I did not really understand what it was doing, but eventually I got it so that the Pi loaded the system time immediately on booting up. Unfortunately, it still had not beaten the other service, so the log files still had the wrong date. Then I heard that there are two (maybe more) ways of configuring Raspberry Pi services (and on other Linux systems) to boot up, and that the service I was trying to beat was booted up via Upstart. This relies on the .conf files in /etc/init (not init.d). I gather Upstart tries to load up the .conf files in parallel, but you can code them to wait until another service has stopped or started, which is what I did.

    Gotta say I am finding all this Raspberry Pi operating system stuff very difficult.
     
  2. amusicsite

    amusicsite dn ʎɐʍ sᴉɥ┴ Staff Member

    Location:
    UK
    There is more than one choice of OS.

    https://thepihut.com/blogs/raspberr...96-alternative-raspberry-pi-operating-systems

    You could try RISC OS, Android or even Windows on it. Though working through the problems and becoming a master of Linux will be rewarding in the end.
     
  3. Yellow Fang

    Yellow Fang Veteran Geek

    Location:
    Reading
    I am stuck with Linux as it is for work.

    I thought I had done it, but I hadn't <sigh>. The RTC is updated from the system time I reboot the Pi or halt it, but not if I just pull the power cable out. I have to find some way of synchronising the RTC to the system time once the system time has been updated by the internet.

    Edit: seems to do this anyway every 5 to 10 mins, so worry over.
     
    Last edited: 19 May 2016
    amusicsite likes this.
  4. beanz

    beanz Staff Member Staff Member

    Yellow Fang and amusicsite like this.
  5. Yellow Fang

    Yellow Fang Veteran Geek

    Location:
    Reading
    That all looks horribly familiar.

    There are more worms in the can. Do we go for a battery or a super capacitor to charge the chip. How long might the Pi be without power: several hours, a day, a week? How long might the internet be down? If we go for a battery, it needs to last about ten years and there will be extra regulations to comply with. Also, inserting the battery would be an extra step in the commissioning of the product. If we go for a super capacitor, that will only supply enough charge for several hours. The electronics engineers says that the DS3231 chip consumes quite a lot of power. He says he knows of a more efficient chip, but that that chip is controlled via the SPI bus, and is presumably programmed in a different way.