[arm-allstar] Real time clock

vweddige at gmail.com vweddige at gmail.com
Wed Apr 7 03:04:59 EDT 2021



#############################################################################
#############################################################################
#!/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

#############################################################################
#############################################################################

Is this the most current script for the rtc or was there one added as part of a software update?
Thanks,
Von  W5COW 


Sent from my iPhone


More information about the ARM-allstar mailing list