GL.iNet6416 and I2C RTC DS1307 AT24C32 RTC

Redo of this post.

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

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

maybe you can ask paul. His article is here Various Ramblings and half-truths.: AR9331 + PPS + GPS + NTP = AWESOME!

remove me

I got the RTC clock running fine using GPIO 19,20 ports.

Question: I am currently tapping in the 5VDC trace on the motherboard for powering the RTC.

Is this the correct place to get the 5VDC power?

I want to install a tiny 12VDC to 5VDC power supply inside of the box. Where is the best place to connect the 5VDC / ground wires to the mother board. Note I prefer not to use the USB port for powering device for my current little project.

Part 1 bit banging modes for RTC

root@ICS-GLiNet:~# opkg install kmod-i2c-gpio-custom Installing kmod-i2c-gpio-custom (3.18.23-2) to root…
Downloading
hxxp://dl.eko.one.pl/chaos_calmer/ar71xx/packages/kmod-i2c-gpio-custom_3.18.23-2_ar71xx.ipk.

Multiple packages (kmod-i2c-core and kmod-i2c-core) providing same name marked HOLD or PREFER. Using latest.

Installing kmod-i2c-core (3.18.23-1) to root…
Downloading
hxxp://dl.eko.one.pl/chaos_calmer/ar71xx/packages/kmod-i2c-core_3.18.23-1_ar71xx.ipk.
Installing kmod-i2c-gpio (3.18.23-1) to root…
Downloading
hxxp://dl.eko.one.pl/chaos_calmer/ar71xx/packages/kmod-i2c-gpio_3.18.23-1_ar71xx.ipk.
Installing kmod-i2c-algo-bit (3.18.23-1) to root…
Downloading
hxxp://dl.eko.one.pl/chaos_calmer/ar71xx/packages/kmod-i2c-algo-bit_3.18.23-1_ar71xx.ipk.
Configuring kmod-i2c-core.
Configuring kmod-i2c-algo-bit.
Configuring kmod-i2c-gpio.
Configuring kmod-i2c-gpio-custom.

root@ICS-GLiNet:~# insmod i2c-gpio-custom bus0=0,20,19

root@ICS-GLiNet:~# opkg install kmod-rtc-ds1307 Multiple packages (kmod-rtc-ds1307 and kmod-rtc-ds1307) providing same name marked HOLD or PREFER. Using latest.
Installing kmod-rtc-ds1307 (3.18.23-1) to root…
Downloading
hxxp://dl.eko.one.pl/chaos_calmer/ar71xx/packages/kmod-rtc-ds1307_3.18.23-1_ar71xx.ipk.
Multiple packages (kmod-i2c-core and kmod-i2c-core) providing same name marked HOLD or PREFER. Using latest.
Configuring kmod-rtc-ds1307.

root@ICS-GLiNet:~# insmod rtc-ds1307
module is already loaded - rtc-ds1307

root@ICS-GLiNet:~# echo ds1307 0x68 > /sys/bus/i2c/devices/i2c-0/new_device

root@ICS-GLiNet:~# hwclock -s
root@ICS-GLiNet:~# hwclock -w
root@ICS-GLiNet:~# hwclock -r

Fri Nov 13 16:33:37 2015 0.000000 seconds

Part 2 autobooting RTC

1 - Configure module creating a file called /etc/modules.d/99gpio-i2c-rtc

i2c-gpio-custom bus0=0,20,19
rtc-ds1307

2 - Create a script, /etc/init.d/rtc-driver to load the device driver and set the time.
#!/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

3 - Create a symlink to #2

ln -s /etc/init.d/rtc-driver /etc/rc.d/S11rtc-driver

4 - reboot, ssh to device and type hwclock at prompt to validate.
OpenWrt Chaos Calmer 15.05 (r47466)

Build time: 2015-11-13 19:55 CET</div>
root@ICS-GLiNet:~# hwclock
Sat Nov 14 11:21:39 2015 0.000000 seconds

Next connecting a 1-wire DS18A20 to GPIO bit banging for temperature inside of case.

Sorry that I can’t get the attachment.The GL.iNet6416 has a 5V and a 3.3V hole.you can get the voltage from there.Our gpio voltage is 2.5V,so if possible I suggested you connect the power supply to 3.3V .

And if you want to add a tiny 12V to 5V,you can connect the 5V to the 5V hole on our board,and Ground connect to the Square pin of component J8 (beside the RJ45 jack).

Thank you.

So here utilizing a small 12VDC to 5VDC board. So it will not be an issue to connect the 5VDC power supply to the 5VDC hole?

I am using same 5VDC hole for the RTC board.

Can I link pictures here to Google or Microsoft?

Β 

Β 

Β 

the popup script of the forum seems a bit weird. I managed to attach a few images the other day, had to use the tab key, and then enter.

Β 

http://postimg.org

else: give that one a try to upload images and then post a link here…

Thank you.

Redid first post now that everything is working.

Very nice write-up petey!

I hope they put it on the blog.

Thank you frietpan!

I do have it posted on a blog on a forum called Cocoontech. I am pete_c there.

I couldn’t post a picture or picture link here.

That said now adding more to the GLi device.

I am going to install an Arduino Nano inside of the case. I purchased the Nano last week. It will fit fine inside of the GLiNet router.

It is running automation software talking via one serial port out and talking to another serial port from the GliNet router.

I like to tinker with stuff. This is the first time that I am tinkering with the Arduino stuff.

The GLiNet device will be my smallest automation server to date. It will very simple and just mostly functional.

1 Like

The image link function is corrected.

Can I cite and copy the content of your post to our blog?

Thank you alzhao.

I have added two pictures to the first post. I had no issues uploading the two JPG files.

Can I cite and copy the content of your post to our blog?

Yes.

Going really slow now with the Arduino stuff as I have never played with an Ardunio anything.

Transport will be like this:

GLi.Net (openwrt)==> serial ==> Arduino ==> multiprotocal automation combination controller. (IE: X10, UPB, Z-Wave (Zigbee))

While the automation controller has network connectivity it utilizes a serial bus similar to say an automotive serial bus for communications.

Network transport is similar to the serial com except that the network com is encrypted and the serial com is not.

Β 

The arduino things should be easy and quick, I guess.

It is easy because someone already has written the code for the Arduino that is easy to modify. Ideally converting this code to Lua would be better. .

This morning installed PHP and a MySQL DB server on the GLiNet router.

Trying a little test here and asking for suggestions or help?

Bypassing the Arduino stuff I want to add a second serial port to the GLiNet microrouter and just have the GLiNet router talk on this serial port and not have to use the Arduino.

For connectivity can I just purchase a tiny TTL to serial board (without the RS-232 port on it)?

What is the best mechanism for connecting the TTL to the GLiNet board?

Is it recommended to use the GPIO ports to create a second serial port?

I do want it to be separate.

This thread and others like it in the openwrt forum refer to kmod-rtc-ds1307, but I can’t find that file in the CC or trunk repositories for ar71xx packages or in the provided software on the domino qi ("opkg list-installed and opkg install kmod-rtc-ds1307), or for the Gl.inet 6408. Where is this to be found?

There are other i2c devices for which there appear to be drivers, like pcf857x or pca953x, but I cant find them. Does someone know where they are located? Any driver available for mcp23017?

Β 

Your message is difficult for me to read.

Personally my search took to the eastern parts of the EU; specifically Poland. That is where I got the drivers I needed to do the doo of what I did above.

I do not speak polish but was able to communicate with the Open-WRT guru relating to my drivers and needs and he knew exactly what I was asking for. The guy there is an OpenWRT obi wan kenobi.

IE: hxxp://dl.eko.one.pl/chaos_calmer/ar71xx/packages/kmod-i2c-gpio-custom_3.18.23-2_ar71xx.ipk.

Switched gears a bit and still playing with the GL.iNet6416. Trying a new faster CPU, more flash and RAM microrouter in a next few weeks.

Β 

@petey, if you want to add 2nd serial, you need to use GPIO to simulate. But some people said it is better to use USB-UART adapter.

Thank you alzhao.

Yes I am doing two USB to RS-232 (UART) devices with no issues.

I am also looking to expand play space (RAM). What would you recommend? A microSD would be ideal but I am already using the GPIO pins.

Would a USB to MicroSD card then be recommended?

Just noticed you are selling the GL M7620N board. I didn’t know you were selling it.

Today purchased a dual port microrouter using the 7620 CPU and getting ready to test a similiar device though with 128Mb of DDR RAM.

Β 

One bad news:

  1. We will not modify GL.iNet6416 or GL-AR150 to have more RAM and ROM.

Β 

Three good news:

  1. We will push our GL-MT300A into production soon, which has 128MB DDR and have a daughter board which can mount MicroSD card. This one will be available in 1 month.

  2. We will have another Atheros mini router soon which will have 128MB Nand flash and 128M DDR so you even don’t need a MicroSD card. This router will be available in 2 months.

  3. You can use our MiFi board, which use the same IC as 6416 and AR150, with MicroSD slot. It will have a case available in two months.