Skip to content

Instantly share code, notes, and snippets.

@davidebettio
Forked from Lahorde/0_README.md
Created July 12, 2016 12:26
Show Gist options
  • Save davidebettio/b1321ac38ad163f0bcb2887e4401f6f4 to your computer and use it in GitHub Desktop.
Save davidebettio/b1321ac38ad163f0bcb2887e4401f6f4 to your computer and use it in GitHub Desktop.
Initialize an external I2C RTC module on raspberry using udev and systemd
# /etc/udev/rules.d/rtc-i2c.rules
#
#
#I2C hardware device driver
ACTION=="add", KERNEL=="i2c_bcm2708", SUBSYSTEM=="module", TAG+="systemd"
# /etc/udev/rules.d/rtc-i2c.rules
#
#
ACTION=="add", SUBSYSTEM=="rtc", ATTRS{hctosys}=="0", RUN+="/usr/bin/hwclock -s --utc"
# /etc/systemd/system/i2c_rtc.service
[Unit]
Description=Initialize i2c hardware RTC device driver
DefaultDependencies=no
Requires=sys-module-i2c_bcm2708.device
After=sys-module-i2c_bcm2708.device
Conflicts=shutdown.target
[Service]
Type=oneshot
RemainAfterExit=yes
EnvironmentFile=/etc/conf.d/rtc-i2c
ExecStart=/bin/sh -c "echo ${CHIP} ${ADDRESS} > /sys/class/i2c-adapter/i2c-${BUS}/new_device"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment