How can I get the hardware clock synced on the raspberry pi?

Thaidog
Thaidog used Ask the Experts™
on
I just bought a raspberry pi, installed arch linux and every time I reboot the system none of my services start due the clock always reporting the year 1969. I have read a few articles on getting  is synced but none of them so far seem to work.

Anyone know a good way to make sure the time is correct? (The other problem is networking does not seem to want to come up either using netcl)
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2015
Commented:
Raspberry pi does not contain permanent hardware clock. You must use ntpdate or allow huge initial step for ntpd/chrony.
I think Raspberry's clock is not battery buffered.
The usual way, that I know is to synchronize with an ntp server.

For this you have to have:
- an enabled network connection
- the command ntpdate installed

If this is the case try to execute for example
ntpdate ntp.ubuntu.com (other ntp server, that you now shall do as well)

U use Raspian on my Raspberrry and the startup script synchronizes the clock automatically with the net.
Top Expert 2015

Commented:
Chrony is much better as you can command it to synchronize when network is up, and stop when it is down...
don't know chrony but I agree the idea to synchronize whenever you get a network sounds reasonable.
Top Expert 2015

Commented:
http://chrony.tuxfamily.org/manual.html#Chrony-compared-to-other-programs
It is default in fedora and even integrated in ifup/down scripts

Author

Commented:
Well my main problem is that my system will not come up with an IP.... if I can't get an ip I might as well set everything from the command line anyway after I hook up a console and set the date.... I have been adding it manually with ifconfig and the route command because  both netcl following this wiki:

https://wiki.archlinux.org/index.php/netctl

Is not bringing my network up :(
Depending on what you want to do with your pi I guess, that not having the network is your most important problem.
As soon as you have an working network solving the issue with setting the time will be easy.

Perhaps you should post a separate question for this and indicate which linux distribution you installed.

Depending on the distribution or on the way you installed your linux on your pi you might have different peole helping you out.
Top Expert 2015

Commented:
At least you should tell if you have sort of DHCP, like home router and most importantly - if you have any network card plugged into your raspberry....

Unless that is solved... the answer is.... Raspbery Pi has no RTC hardware, which means that you must acquire time from the network (or USB GPS, or solder a RTC etc) on each system startup.

As a side note - Raspberry Pi bears no similarity to MacOSX that is unable to connect wifi before year 2000.

Author

Commented:
DHCP or static does not seem to work... have not really had time to dig in to it... might just buy a hw clock if there is one I can pick up close by...
Top Expert 2015

Commented:
What is the use of whole thing without network?
Gerwin Jansen, EE MVETopic Advisor
Most Valuable Expert 2016

Commented:
Try installing Raspbian instead, just get another SD card and have a go.
Gerwin Jansen, EE MVETopic Advisor
Most Valuable Expert 2016

Commented:
@gheist - There are a lot of fun projects out there for RPI dat don't need network ;)
Top Expert 2015

Commented:
Yes, but if one complains they have no network, probably they want the not-so-fun projects like kodi etc...
That's what I suggested, a Real Time Clock:
"Or add an RTC module ($5): http://store.linksprite.com/ds3231-raspberry-pi-rtc-board-real-time-clock-module-for-arduino/ "

Author

Commented:
Yep - ordered one :) it's on the way!

Author

Commented:
@ Gerwin Jansen - Raspbian was actually doing the same thing. I had that installed first. DHCP is being broadcast on the vlan and all the other devices don't have a problem... but the link on the switch takes a while to come back up on reboot and I think the pi is too fast - maybe the network daemon gives up? Maybe I can narrow it down better once I put the RTC in.
Gerwin Jansen, EE MVETopic Advisor
Most Valuable Expert 2016

Commented:
I never have any DHCP problems with RPI or BPI devices. You may want to investigate your network setup, something must be wrong there. Or setup a fixed ip for testing on your device and reserve the same ip on your DHCP server.

Author

Commented:
This morning I rebooted the pi after I ran:

 systemctl disable network@.service

...and the pi evidently came up with no issues. Looks like I had two competing services, network@.service and netctl.service or the switch timing was not a problem at this point... not sure... I'll look in to it later when I have the chance.
Top Expert 2015

Commented:
welcome to the blind world of systemd...
network@ is target that consists of multiple services. It is very likely that it wants networkmanager by default.
It is al about symlinks in /etc/systemd. They have some crumbles of documentation there and /usr/share/doc/systemd*

While your clock circuit is with postman - check if ntpd or chrony better fits your needs..

Author

Commented:
Well... I am not sure why my system came back up ok last time. I rebooted it again after configuring ntpd and the root filesystem is read only and there was no ip address again, and ntpd did not start up... all the other services looked messed up too. I  think I'll just buy and Intel nuc so I can at least have the hardware ruled out....

@gheist - yeah systemd is going to take some time to get used to.... I guess I can at least take a little experience using it here as the positive side...
Gerwin Jansen, EE MVETopic Advisor
Most Valuable Expert 2016

Commented:
>> I'll just buy an Intel nuc
You could try a new SD card first and that RTC module, could save you some money ;)
Top Expert 2015

Commented:
Better try something like debian or fedora that at least are easy to configure and with significant user base.
Gerwin Jansen, EE MVETopic Advisor
Most Valuable Expert 2016

Commented:
@gheist, asker can try Debian or Fedora of course but Raspian is working just fine out of the box (Debian based).

Author

Commented:
@Gerwin Jansen - yep that's on the way :)
Top Expert 2015

Commented:
As always Gerwin with his shortcuts :)
Gerwin Jansen, EE MVETopic Advisor
Most Valuable Expert 2016

Commented:
LOL ;)

Author

Commented:
Ok so the RTC came today but I'm not sure how to get it going.... I've got it installed exactly like this:

http://ecx.images-amazon.com/images/I/61XtSzFMn3L._SY355_.jpg

Not sure if that is really the right pins... and the the directions do not seem to work.... echoing in to sys like this does not work:

[root@pi ~]# echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device
-bash: /sys/class/i2c-adapter/i2c-0/new_device: No such file or directory

The directions I saw were at the bottom of the link you provided:

http://www.element14.com/community/community/raspberry-pi/blog/2012/07/19/what-time-is-it-adding-a-rtc-to-the-raspberry-pi-via-i2c

Maybe I'm missing a driver or software package?
Top Expert 2015

Commented:
modprobe rtc-ds1307 ?

Author

Commented:
[root@pi i2c-adapter]# modprobe rtc-ds1307
[root@pi i2c-adapter]# echo ds3231 0x68 >/sys/bus/i2c/devices/i2c-1/
-bash: /sys/bus/i2c/devices/i2c-1/: Is a directory
[root@pi i2c-adapter]# lsmod
Module                  Size  Used by
evdev                   9900  0
iptable_filter          1505  0
ip_tables              11645  1 iptable_filter
x_tables               16509  2 ip_tables,iptable_filter
leds_gpio               3492  0
led_class               4066  1 leds_gpio
uio_pdrv_genirq         3238  0
uio                     8753  1 uio_pdrv_genirq
sch_fq_codel            7611  2
snd_bcm2835            19740  0
snd_pcm                86628  1 snd_bcm2835
snd_timer              20697  1 snd_pcm
snd                    61799  3 snd_bcm2835,snd_timer,snd_pcm
bcm2708_rng             1044  0
rng_core                5666  1 bcm2708_rng
ipv6                  327533  0
[root@pi i2c-adapter]# hwclock -r
hwclock: Cannot access the Hardware Clock via any known method.
hwclock: Use the --debug option to see the details of our search for an access method.

Open in new window


I've installed i2c-tools as well...
Top Expert 2015

Commented:
You need to load the driver called rtc-ds1307
There should be respective .ko file in
/lib/modules/`uname -r`/kernel/drivers/rtc directory (maybe you need some package with extra kernel modules)
raspbian has it for sure...

you do not need i2c tools. you need kernel rtc driver that works over i2c bus

filename:       /lib/modules/3.16.7-7-desktop/kernel/drivers/rtc/rtc-ds1307.ko
license:        GPL
description:    RTC driver for DS1307 and similar chips
srcversion:     F17ED99F15021067E33AC58
alias:          i2c:rx8025
alias:          i2c:pt7c4338
alias:          i2c:mcp7941x
alias:          i2c:m41t00
alias:          i2c:ds3231
alias:          i2c:ds1340
alias:          i2c:ds1388
alias:          i2c:ds1339
alias:          i2c:ds1338
alias:          i2c:ds1337
alias:          i2c:ds1307
depends:        
intree:         Y
vermagic:       3.16.7-7-desktop SMP preempt mod_unload modversions 

Open in new window


On the orther hand only module that works over i2c bus is rtc_isl12057 (on a normal PC, not ARM, or something as exquisite)
Gerwin Jansen, EE MVETopic Advisor
Most Valuable Expert 2016

Commented:
You need both i2c-dev and rtc-ds1307 modules loaded into your kernel - check with lsmod to see which modules are loaded. Try i2cdetect -F if you can see the module, if so then:

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

Check if you can read the clock: hwclock -r - when it works, set the correct date/time and then save to the clock: hwclock -w
Top Expert 2015

Commented:
... and then add module names to /etc/modprobe.conf or /etc/modules (really me no expert in arch linux)
and then ntpd/chrony will catch up easily
Gerwin Jansen, EE MVETopic Advisor
Most Valuable Expert 2016

Commented:
Forgot: you are trying this on Raspbian right?

Author

Commented:
Not on Raspbian on Arch ARM. Both models are loaded... there is a /sys/class/i2c-adapter/ directory but nothing after that... because of that echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device does not work :(
Top Expert 2015

Commented:
Do you have the rtc-ds1307 module loaded?
Gerwin Jansen, EE MVETopic Advisor
Most Valuable Expert 2016

Commented:
Would you do us a favor and get a spare SD card and try the same using Raspbian?

Author

Commented:
Sorry I have not responded back but its going to be a while before I have time to try this....
Sean OhlrichIT Manager

Commented:
Over at http://www.uugear.com they have a product called "Witty Pi" which is a RTC with the added benefit of being able to schedule startup and shutdown in its memory.

Author

Commented:
I am going to buy that - thanks!!!

Author

Commented:
I've requested that this question be deleted for the following reason:

I found the answer at another forum.
Top Expert 2015

Commented:
Can you post a link to it? This is kind of forum too.
Top Expert 2015

Commented:
Either acquire hardware clock or live with long step time sync

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial