How do I give my Pi system a Real Time Clock (RTC)? Is this possible? As each time when I power off my Pi, and the next time when it boots, it displays the previous power off time.
Can someone explain me how to initalise or setup a RTC in my Pi?
How do I give my Pi system a Real Time Clock (RTC)? Is this possible? As each time when I power off my Pi, and the next time when it boots, it displays the previous power off time.
Can someone explain me how to initalise or setup a RTC in my Pi?
The Raspberry Pi doesn't include a hardware clock out of the box. You will need to purchase such a module (relatively cheap), install it, setup a battery and then set up the software, which is a pretty straightforward procedure.
Something like the JBtek DS3231 RTC Real Time Clock Module for Raspberry Pi.
EDIT
I can post the setup process if you need me to, but there are plenty tutorials you can find with a google search that document the process extensively.
I elected to use a DS1307 hw clock on mine since it was i2c based and I have several other i2c devices on mine already. You can purchase them via Adafruit or various 3rd party locations on eBay/Amazon/etc in a small break-out board ready to plug into your breadboard with on-board battery, etc. They're all pretty cheap. If the break-out board does what you need, then you can always order just the DS1307 chip and do your own supporting circuitry later for your final build even cheaper.
HERE is the one I used for my build.
As far as getting it running, the process is pretty well documented HERE to get the kernel modules loaded, set the time on the RTC, and set Linux to pull the OS time from the RTC upon each boot.
/etc/rc.local
won't work without a short 'sleep' between them. When I set mine up I removed 'fake-hwclock', but I'm not sure if that' essential.
A hardware RTC may or may not be the best solution.
If your RasPi has no network connecition, then yes a hardware RTC is about your only option. But, if you are connecting via ethernet (wifi or wired) you can do a sudo apt-get install ntpdate
which will install a daemon that runs on boot when the ethernet connection is established. This will set the RasPi internal clock each time it boots and its network connection establishes.
Most Raspian distros already do this. If yours already does, the above command won't do anything. But if yours does not, it should hook you up to a NTP (Network Time Protocol) server. Settings are contained in /etc/default/ntpdate
.
Also check /etc/ntp.conf
for proper configuration.
With those two, you shouldn't ever need any hardware RTC module.