However, I’m sure you know there’s a “but” coming…. If we left the –systz uncommented in the /lib/udev/hwclock-set it would even do this automagically (the –systz is shorthand for sys to rtc). If you are connected to a network, the RPI will go and get the time from the Net and you can then copy it across to the RTC with a “sudo hwclock -s”. If you set-up the RTC as decided above then by-and-large things should be tickety-boo. You can directly set the time of the hardware RTC with: sudo hwclock -set -date=" 16:45:05" Running the RTC Off-Grid # To copy the time from the hardware RTC to the RPi system (RTC – RPi): sudo hwclock -s To copy the time from the RPi system to the hardware RTC (RPi-> RTC): sudo hwclock -w To read the time from the hardware RTC you can issue the following commands. Note: from Buster onwards you need to use a battery with RTC for reasons explained here. Next reboot and the configuration is done. This will stop that script exiting early and will update the clock on boot. sbin/hwclock -rtc=$dev -hctosys -badyear # /sbin/hwclock -rtc=$dev -systz -badyear These update the RTC from the RPi and can cause issues. It’s also a good idea to comment out all the –systz lines too (as shown below). Now comment out some lines in hwclock-set: sudo nano /lib/udev/hwclock-setĪnd comment out the following lines (using the #). That’s a comma, not full stop, between i2c-rtc and pcf8523! And it’s a “dash” not “equals” between i2c and rtc!īTW: if you have another RTC that you are trying to get working and want to know whether out is supported and what the overlay is called, have a look here and see if yours is listed. Scroll down to the bottom and add the line: dtoverlay=i2c-rtc,pcf8523 To tell the Raspberry Pi that we have a hardware clock, we need to add the following line to config.txt. If you see “UU” instead of “68” it means that the RPi has loaded a driver for it and it is in use – see below. If you are using a Sleepy Pi 1, then the listing is the same but without the 0x24 listing. If you’ve got one of the original Raspberry Pi’s, then the bus was 0 so you would type: i2cdetect -y 0 To give you a warm cuddly feeling, it’s always a good idea to check the i2c bus with this command: i2cdetect -y 1 This will install some handy utilities for the i2c and then reboot: sudo reboot Detect the RTC # Next install the i2ctools by typing: sudo apt-get install i2c-tools Scroll down until you find the line: #dtparam=i2c_arm=onĪnd uncomment by removing the # then exit & save (Ctrl-X then y). This will enable the i2c bus (well it will on your next reboot). Here are the magic incantation in a command window: sudo nano /boot/config.txt The first order of business is to setup / enable the i2c bus on the Rpi. You can do this by uncommenting a line in config.txt. Note: If you have used the Sleepy Pi setup script you can skip straight to “Detect the RTC”. Although this page describes setting up the RTC on Sleepy Pi 2, this same method can actually apply to any supported RTC – you just need to change the overlay as explained below. For the new way under Jessie / Stretch or Buster read on. For the old way of doing things see this page. Things are constantly moving forward in Raspberry Pi land and setting up a Real-Time Clock (RTC) on the RPi is no exception.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |