pete_c
Guru
Openwrt hardware/software mods to utilize an RTC and a DS-18B20 1-Wire temperature sensor.


Hardware:
1 - OpenWRT OS micro router using GPIO pins 19,20 and 5VDC and Ground (Atheros AR9331 @ 400MHz) - Gl.iNet microrouter model 6416A - Atheros AR9331 @ 400MHz - RAM 64MiB and Flash 16MiB
2 - RTC clock that uses a DS1307 - 5VDC, Ground, SDA, SCL - SainSmart Tiny RTC I2C DS1307 AT24C32 24C32 memory Real Time Clock Module for Arduino - module has 1-wire pins for temperature sensor
3 - DS18B20 1-Wire temperature sensor.
Steps...
1 - Solder using right side of board pins Gnd, Vcc, Sda and Scl to GL.iNet microrouter Gnd, 5VDC, GPIO 20 and GPIO 19 - see attached picture.
2 - Download Openwrt firmware
Generic GL.Inet firmware
3 - Using the default modded LuCi web interface update Microrouter with firmware downloaded above.
4 - SSH to the microrouter
5 - type the following stuff
# opkg update
# opkg install kmod-i2c-gpio-custom
# insmod i2c-gpio-custom bus0=0,20,19
# opkg install kmod-rtc-ds1307
# insmod rtc-ds1307
# echo ds1307 0x68 > /sys/bus/i2c/devices/i2c-0/new_device
# hwclock -s
# hwclock -w
# hwclock -r
If all is ok you will see the current time.
Fri Nov 13 16:33:37 2015 0.000000 seconds
Installing ic2-tools is optional
# opkg install hxxps://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/packages/oldpackages/libi2c_2013-12-15-1_ar71xx.ipk
# opkg install hxxp://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/packages/oldpackages/i2c-tools_2013-12-15-1_ar71xx.ipk
# i2cdetect -y 0 will show UU for address 68 because address is being utilized by RTC clock
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: 50 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
side note: The RTC will be detected with the address 0x68.
Note: just about all RTC’s have the same i2c address of 0x68!
5 - Auto starting hardware clock
# opkg update
# opkg install nano
# create a script called /etc/init.d/rtc-driver
#!/bin/sh /etc/rc.common
logger "Setup i2c RTC"
echo ds1307 0x68 > /sys/bus/i2c/devices/i2c-0/new_device
if hwclock | grep 'Jan' | grep -q 2000 ; then
logger "RTC appears to have a flat battery..."
else
logger "RTC set hwclock"
hwclock -s
fi
# chmod +x /etc/init.d/rtc-driver
Create a symlink
ln -s /etc/init.d/rtc-driver /etc/rc.d/S11rtc-driver
reboot and ssh to device and type hwclock at prompt to validate autostarting hwclock.
# hwclock
Sat Nov 14 11:21:39 2015 0.000000 seconds
DS-18B20 1-Wire temperature sensor add
Software package installation for 1-WIre Temps.
1 - #opkg update
2 - # opkg install kmod-w1 kmod-w1-master-gpio kmod-w1-gpio-custom
3 - # insmod w1-gpio-custom bus0=0,18,0
4 - # echo "w1-gpio-custom bus0=0,18,0" > /etc/modules.d/59-w1-gpio-custom
5 - # opkg install kmod-w1-slave-therm
6 - # cat /sys/bus/w1/drivers/w1_slave_driver/*/w1_slave
d4 01 4b 46 7f ff 0c 10 6f : crc=6f YES
d4 01 4b 46 7f ff 0c 10 6f t=29250
* crc=6f YES means its working and 29250 is the temperature in Celsius
7 - # awk -F= '/t=/ {printf "%.02f\n", $2/1000}' /sys/bus/w1/drivers/w1_slave_driver/*/w1_slave
29.25
8 - # reboot
9 - # cat /sys/bus/w1/drivers/w1_slave_driver/*/w1_slave - should be the same as above.


Hardware:
1 - OpenWRT OS micro router using GPIO pins 19,20 and 5VDC and Ground (Atheros AR9331 @ 400MHz) - Gl.iNet microrouter model 6416A - Atheros AR9331 @ 400MHz - RAM 64MiB and Flash 16MiB
2 - RTC clock that uses a DS1307 - 5VDC, Ground, SDA, SCL - SainSmart Tiny RTC I2C DS1307 AT24C32 24C32 memory Real Time Clock Module for Arduino - module has 1-wire pins for temperature sensor
3 - DS18B20 1-Wire temperature sensor.
Steps...
1 - Solder using right side of board pins Gnd, Vcc, Sda and Scl to GL.iNet microrouter Gnd, 5VDC, GPIO 20 and GPIO 19 - see attached picture.
2 - Download Openwrt firmware
Generic GL.Inet firmware
3 - Using the default modded LuCi web interface update Microrouter with firmware downloaded above.
4 - SSH to the microrouter
5 - type the following stuff
# opkg update
# opkg install kmod-i2c-gpio-custom
# insmod i2c-gpio-custom bus0=0,20,19
# opkg install kmod-rtc-ds1307
# insmod rtc-ds1307
# echo ds1307 0x68 > /sys/bus/i2c/devices/i2c-0/new_device
# hwclock -s
# hwclock -w
# hwclock -r
If all is ok you will see the current time.
Fri Nov 13 16:33:37 2015 0.000000 seconds
Installing ic2-tools is optional
# opkg install hxxps://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/packages/oldpackages/libi2c_2013-12-15-1_ar71xx.ipk
# opkg install hxxp://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/packages/oldpackages/i2c-tools_2013-12-15-1_ar71xx.ipk
# i2cdetect -y 0 will show UU for address 68 because address is being utilized by RTC clock
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: 50 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
side note: The RTC will be detected with the address 0x68.
Note: just about all RTC’s have the same i2c address of 0x68!
5 - Auto starting hardware clock
# opkg update
# opkg install nano
# create a script called /etc/init.d/rtc-driver
#!/bin/sh /etc/rc.common
logger "Setup i2c RTC"
echo ds1307 0x68 > /sys/bus/i2c/devices/i2c-0/new_device
if hwclock | grep 'Jan' | grep -q 2000 ; then
logger "RTC appears to have a flat battery..."
else
logger "RTC set hwclock"
hwclock -s
fi
# chmod +x /etc/init.d/rtc-driver
Create a symlink
ln -s /etc/init.d/rtc-driver /etc/rc.d/S11rtc-driver
reboot and ssh to device and type hwclock at prompt to validate autostarting hwclock.
# hwclock
Sat Nov 14 11:21:39 2015 0.000000 seconds
DS-18B20 1-Wire temperature sensor add
Software package installation for 1-WIre Temps.
1 - #opkg update
2 - # opkg install kmod-w1 kmod-w1-master-gpio kmod-w1-gpio-custom
3 - # insmod w1-gpio-custom bus0=0,18,0
4 - # echo "w1-gpio-custom bus0=0,18,0" > /etc/modules.d/59-w1-gpio-custom
5 - # opkg install kmod-w1-slave-therm
6 - # cat /sys/bus/w1/drivers/w1_slave_driver/*/w1_slave
d4 01 4b 46 7f ff 0c 10 6f : crc=6f YES
d4 01 4b 46 7f ff 0c 10 6f t=29250
* crc=6f YES means its working and 29250 is the temperature in Celsius
7 - # awk -F= '/t=/ {printf "%.02f\n", $2/1000}' /sys/bus/w1/drivers/w1_slave_driver/*/w1_slave
29.25
8 - # reboot
9 - # cat /sys/bus/w1/drivers/w1_slave_driver/*/w1_slave - should be the same as above.