[arm-allstar] Adding a real-time clock (i2c etc)---script update

David McGough kb4fxc at inttek.net
Sun Jan 12 11:36:54 EST 2020


Larry,

After running the script, reboot your RPi board.  At that point, it should 
automatically set the clock at boot using the RTC module.

You can test the RTC module using the hwclock command. If the RTC module 
is NOT working, you'll see this:

[root at RPi4B-dev ~]# hwclock
hwclock: Cannot access the Hardware Clock via any known method.


...Otherwise the date/time will be returned. Check the man page for the 
hwclock program for more info.

73, David KB4FXC



On Sun, 12 Jan 2020, "Larry Aycock via ARM-allstar" wrote:

> Hello All,
> 
> I tried to find the original message below to respond to, but I think it was permanently deleted.  David updated the script below for HamVOIP to install an RTC.  I ran this script and have some questions.
> 
> 
>   1.  After running the script, how can I tell if the RTC is working correctly?
>   2.  Do I need to add anything to other files to get the system to use the RTC when rebooting the Pi?
>      *   I've seen other guides online mention adding some lines to the RC.LOCAL file to find and read from the RTC on boot.  Do I need to do something like this?
>      *   The last two lines in the script below enables and starts the RTC.  Do I need to do that each time the node reboots?
> 
> I'm still learning the Linux system and how it all works.  I'm just not sure if the script below sets everything for me so that when the node reboots, it uses the RTC, or if there are additional steps I need to do to make that happen.  More clarification would be greatly appreciated.
> 
> 73,
> Larry
> N6LKA
> 
> 
> 
> Below is the post from David with the script.
> 
> Here is that setup script sortof customized to HamVoIP. It runs okay on my
> dev RPi4B....
> 
> 73, David KB4FXC
> 
> #############################################################################
> #############################################################################
> #!/bin/bash
> 
> cp /boot/config.txt /tmp/config.tmp
> echo 'device_tree_param=i2c_arm=on' >> /tmp/config.tmp
> 
> j=$(grep 'device_tree_param=i2c_arm=on' /tmp/config.tmp | wc | awk '{print $1}')
> 
> if [ "$j" == "1" ] ; then
>         cp /tmp/config.tmp /boot/config.txt
> else
>         echo -e "\n\ndevice_tree_param NOT SET CORRECTLY!\n"
>         echo "Check your /boot/config file and manually correct:"
>         echo -e "\n\tdevice_tree_param=i2c_arm=on"
>         echo -e "\n\nThen, run this script again....\n\n"
>         exit 1
> fi
> 
> pacman -S --needed --noconfirm i2c-tools
> 
> modules_file="/etc/modules-load.d/raspberrypi.conf"
> cp "$modules_file" /tmp/rtc.tmp
> echo rtc-ds1307 >> /tmp/rtc.tmp
> echo i2c-dev >> /tmp/rtc.tmp
> sort /tmp/rtc.tmp | uniq > "$modules_file"
> 
> mkdir -p /usr/lib/systemd/scripts/
> cat > /usr/lib/systemd/scripts/rtc << END
> #!/bin/bash
> # create an i2c device DS1307 (works also for DS3231)
> # set systemclock from external i2c-rtc
> echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
> hwclock -s
> END
> 
> chmod 755 /usr/lib/systemd/scripts/rtc
> 
> cat > /etc/systemd/system/rtc.service << END
> [Unit]
> Description=RTClock
> Before=network.target
> 
> [Service]
> ExecStart=/usr/lib/systemd/scripts/rtc
> Type=oneshot
> [Install]
> WantedBy=multi-user.target
> END
> 
> systemctl enable rtc
> systemctl start rtc
> 
> #############################################################################
> #############################################################################
> 
> _______________________________________________
> 
> ARM-allstar mailing list
> ARM-allstar at hamvoip.org
> http://lists.hamvoip.org/cgi-bin/mailman/listinfo/arm-allstar
> 
> Visit the BBB and RPi2/3/4 web page - http://hamvoip.org
> 



More information about the ARM-allstar mailing list