RTC using DS1307 on RASPI
I have built an app which needs to be useable offline and obviously had a problem with the RTC on the Pi as it doesn't have one. So bought a DS1307 and followed the instructions in this thread:
https://forum.emteria.com/discussion/comment/4238#Comment_4238
Hardware is working fine and I can set, read and change the date as su on an ADB shell so am nearly there. I tried to use the following script in /data/init.d
#!/system/bin/sh
### BEGIN INIT INFO
# Exec: boot
# Type: permanent
### END INIT INFO
insmod /boot/modules/rtc-ds1307.ko
ln -s /dev/rtc0 /dev/rtc
hwclock -t
I have changed the owner, group and file permissions (744 on my device) on my file to be the same as the other two files in init.d but nothing seems to work. It doesn't load the boot module thus doesn't create the symlink.
I program using a high level language so am winging it on the script and have run out of ideas. Can anyone point to what I am doing wrong?
I am thinking that I haven't written the script properly....
https://forum.emteria.com/discussion/comment/4238#Comment_4238
Hardware is working fine and I can set, read and change the date as su on an ADB shell so am nearly there. I tried to use the following script in /data/init.d
#!/system/bin/sh
### BEGIN INIT INFO
# Exec: boot
# Type: permanent
### END INIT INFO
insmod /boot/modules/rtc-ds1307.ko
ln -s /dev/rtc0 /dev/rtc
hwclock -t
I have changed the owner, group and file permissions (744 on my device) on my file to be the same as the other two files in init.d but nothing seems to work. It doesn't load the boot module thus doesn't create the symlink.
I program using a high level language so am winging it on the script and have run out of ideas. Can anyone point to what I am doing wrong?
I am thinking that I haven't written the script properly....
0
Comments
Made sure that config.txt had the following lines:
dtparam=i2c1=on
dtparam=i2c_arm=on
dtoverlay=i2c-rtc,ds1307
su'd and changed directory to /data/init.d and entered
cat > SetHWTime.sh
then pasted in
#!/system/bin/sh
### BEGIN INIT INFO
# Exec: boot
# Type: permanent
### END INIT INFO
insmod /boot/modules/rtc-ds1307.ko
ln -s /dev/rtc0 /dev/rtc
hwclock -l
hwclock -t
hwclock -s
Then CTL c and chmoded the file to 777
For whatever reason a file edited in Windows using notepad was the problem. I also found that to set the date to work correctly in the UK I had to use the date command to set the time 1 hour earlier than it really was, then use hwclock -w
Then a reboot set the system time correctly.
Note that I could have saved a line in the script by using hwclock -f /dev/rtc0 before each of the other options and not used the ln command
Just a little addon on this thread about my experience with rtc1307.
in my case, with the latest 5.15 kernel (emteria 11.8), the system wants hwmon before loading rtc-ds1307.ko, so :
insmod hwmon.ko
insmod rtc-ds1307.ko
If you don't insert hwmon before, it gives you : Uknown symbol devm_hwmon_device_register_with_groups (err-2)