Last active
June 14, 2023 20:19
-
-
Save grubernd/aed721614b36aaa31fd97ef5ab1ec6be to your computer and use it in GitHub Desktop.
install & setup of an I2C RTC on RaspberryPi (both Arch Linux ARM and Raspbian)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#----------------------------------------------------------- | |
# Copyright (C) 2014-2016 GRUBERND http://grubernd.at | |
# released under a FreeBSD License | |
#----------------------------------------------------------- | |
# CATE installer module :: device RealTimeClock RPi | |
# | |
# !! needs to be run as root / sudo !! | |
# | |
# works both for DS1307 and DS3231 chips. | |
# this script is also designed to run standalone for | |
# both Arch Linux ARM and Raspbian installs. | |
#----------------------------------------------------------- | |
#_CATECONF__ # RTC service requires no configuration | |
if [[ "$(which pacman)" != "" ]]; then | |
echo -e "" | |
echo -e ".. installing I2C RTC for Arch Linux ARM" | |
echo -e "" | |
modules_file="/etc/modules-load.d/raspberrypi.conf" | |
pacman -S --needed --noconfirm i2c-tools | |
fi | |
if [[ "$(which apt-get)" != "" ]]; then | |
echo -e "" | |
echo -e ".. installing I2C RTC for Raspbian" | |
echo -e "" | |
modules_file="/etc/modules" | |
apt-get install --yes i2c-tools | |
fi | |
echo -e "" | |
echo -e ".. activating I2C devicetree in /boot/config.txt" | |
sed --in-place 's/^#device_tree_param=i2c_arm=on/device_tree_param=i2c_arm=on/' "/boot/config.txt" | |
#----------------------------------------------------------- | |
echo -e "" | |
echo -e ".. adding i2c and rtc modules to the 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" | |
#----------------------------------------------------------- | |
echo -e "" | |
echo -e ".. creating init script for the RTC" | |
mkdir -p /usr/lib/systemd/scripts/ | |
cat > /usr/lib/systemd/scripts/rtc << ENDRTCSCRIPT | |
#!/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 | |
ENDRTCSCRIPT | |
chmod 755 /usr/lib/systemd/scripts/rtc | |
echo -e "" | |
echo -e ".. creating service for the RTC" | |
cat > /etc/systemd/system/rtc.service << ENDRTCSERVICE | |
[Unit] | |
Description=RTClock | |
Before=network.target | |
[Service] | |
ExecStart=/usr/lib/systemd/scripts/rtc | |
Type=oneshot | |
[Install] | |
WantedBy=multi-user.target | |
ENDRTCSERVICE | |
#----------------------------------------------------------- | |
echo -e "" | |
echo -e ".. enabling and starting RTC service" | |
systemctl enable rtc | |
systemctl start rtc | |
#----------------------------------------------------------- | |
#_CATETEST__ echo -e "" | |
#_CATETEST__ echo -e ".. systemctl status rtc" | |
#_CATETEST__ systemctl status rtc | |
#_CATETEST__ echo -e "" | |
#_CATETEST__ echo -e ".. testing i2c activation in /boot/config.txt" | |
#_CATETEST__ grep "^device_tree_param=i2c_arm=on" /boot/config.txt | |
#_CATETEST__ echo -e "" | |
#_CATETEST__ echo -e ".. testing connection of i2c devices" | |
#_CATETEST__ i2cdetect -y 1 | |
#_CATETEST__ echo -e "" | |
#_CATETEST__ echo -e ".. testing rtc hwclock" | |
#_CATETEST__ hwclock |
“I’m sorry, Dave. I’m afraid I can’t do that.”
Besides, this script has neither been tested nor updated since 2016.
I have no idea if it still works. I have not used it for at least five years.
Ok Thank you for responding. I very much appreciate it.
Thanks
Dave
…On Wed, Jun 14, 2023 at 4:04 PM grubernd ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
“I’m sorry, Dave. I’m afraid I can’t do that.”
Besides, this script has neither been tested nor updated since 2016.
I have no idea if it still works. I have not used it for at least five
years.
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/grubernd/aed721614b36aaa31fd97ef5ab1ec6be#gistcomment-4599734>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AIEP3SLTCN6CPP2MB7JOHS3XLIKLNBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVAZTMNRVGY4DCNNHORZGSZ3HMVZKMY3SMVQXIZI>
.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I know this is simple. How do I execute this script on my rpi 4.? What is the cammand to do that? Can i retrieve the github script with 1 command and run it?
Thank you
Dave