[arm-allstar] Adding a real-time clock (i2c etc)---script update
David McGough
kb4fxc at inttek.net
Wed Oct 16 15:42:26 EDT 2019
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
#############################################################################
#############################################################################
More information about the ARM-allstar
mailing list