OpenWrt Forum Archive

Topic: Glinet G4416 I2c with TI ADS1115

The content of this topic has been archived on 29 Mar 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi, I've been trying to connect the TI with the Glinet using the gpio using hxxps://wiki.openwrt.org/doc/hardware/port.i2c

I've installed using okpg the i2c gpio custom and core modules without issue. When doing "dmesg | grep gpio" I get ports 19 and 20 for SDA/SCL and connect them accordingly using soldered lines. The ethernet port is set to forwarding according to dmesg | tails. However when running i2cdetect -l on my laptop connected directly to the router LAN via ethernet I do not see the ADS1115. Is there something I specifically have to do to make the chip visible? Does the kernel in hxxps://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/hwmon/ads1015.c need special loading onto the router?

Here's the setup on imgur: [img]hxxps://imgur.com/a/OfoUc[/img]

(Last edited by i2cplease on 9 Nov 2017, 05:09)

Well, bad news first: the ads1015 driver is not included in Openwrt/LEDE. So, you would need to build your own firmware yourself. The only thing you would have to change is editing package/kernel/linux/modules/hwmon.mk: copy the entry for the ADT7475 (currently lines 65-79) and replace adt7475 with ads1015 (keep upper/lower case like in the original). Would be nice to send your change back to the project.

However, for the moment, if i2cdetect doesn't display the address of your sensor, this indicates a problem in the wiring (basically, that the sensors lines are not properly connected to the GPIOs). You need to provide more information on the sensor module, your schematics and the output of dmesg.

(Last edited by MBS on 28 Nov 2017, 11:19)

Thank you for the detailed reply. Two quick things:

1. With regards to the hwmon.mk, I'm guessing it's using git clone the chaos calmer branch and doing your coding before uploading it to the router?

2. imgur COM/a/ZyNa4 shows the dmesg output for i2c and what I see with i2cdetect -l from my laptop directly plugged in. As for schematics, with four wires and the photo, it is the VDD to the 3.3V of the router, gnd to gnd, and SDA and SCL to appropriate pins (I've since changed them from the original picture, but it's plugged in correctly). The rightmost block diagram is the chip; of the I2C ports I don't have ADDR plugged in (it was not mentioned in the wiki).

ti COM/ods/images/SBAS444C/pg1_fbd_new_bas444.gif

Chaos Calmer is pretty old now, so I mainly had LEDE in mind. Since you don't seem to have i2cdetect installed on your router (which was missing in Chaos Calmer, IIRC), I would recommend to start by installing LEDE 17.01.4 and install the i2c-tools package.
To get the source code, git clone is currently the way to go. See the wiki for instructions on building your own firmware image.
If you want to see, which I2C devices are connected to the bus, you invoke i2cdetect, with the number of your bus (as listed with the -l parameter) as parameter.
With your schematics, I am missing the pull-up resistors between SDA/SCL and Vcc. Are they on the sensor module?
Some I2C chips actually allow tri-states of the ADDR line, however I would prefer to connect it to GND for the moment, to be on the safe side.

Hi MBS. I've gotten i2cdetect working with LEDE , and am now trying to program the linux kernel so it'd recognize the chip.

hxxps://imgur.com/a/m6smq shows how I followed your firmware advice.

Downside is after make menuconfig (specifically for the Glinet 6416) I cannot get back to LuCI and have to reset the modem using the command line. make executes without an issue, and I'm flashing using LuCI's web interface. Below is how I set up menuconfig; the only not visible thing is me adding i2c kernel modules.

hxxps://imgur.com/a/i0hOE

As for the resistors, they are integrated on the chip. The SDA and SCL output solid DC at the moment since there's nothing wiggling it. Since it is the only device needing I2C, I'm not going to be using ADDR.

hxxps://pastebin.com/8rtGrHyB shows the command line output

(Last edited by i2cplease on 20 Nov 2017, 02:50)

I don't fully understand the issue about LuCI right now and could not see all the steps of your menuconfig. Basically, LuCI is not selected by default, and external packages need to be enabled first by running

./scripts/feeds update -a
./scripts/feeds install -a

Then you will find the required entries in menuconfig.
As an alternative, you could just install it as written in the wiki, but that will use a bit more storage over all.

You can actually drop the "+kmod-hwmon-vid" since your sensor doesn't need it.

Luci was part of a larger problem about external packages, which your script (executed in the LEDE/source folder for reference to other people) fixed. I got i2cdetect and 0x48 showing up. i2cdump 0 0x48 w works too.

     0,8  1,9  2,a  3,b  4,c  5,d  6,e  7,f
00: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
08: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
10: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
18: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
20: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
28: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
30: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
38: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
40: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
48: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
50: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
58: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
60: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
68: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
70: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
78: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
80: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
88: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
90: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
98: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
a0: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
a8: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
b0: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
b8: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
c0: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
c8: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
d0: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
d8: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
e0: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
e8: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
f0: 0000 8385 0080 ff7f 0000 8385 0080 XXXX
f8: 0000 8385 0080 ff7f 0000 8385 0080 XXXX

Other than that, did "echo ads1015 0x48 > /sys/class/i2c-dev/i2c-0/device/new_device" to instantiate the device following a gmane forum post.

If anything comes up, I'll let you know. Again, i can't thank you enough.


root@LEDE:~# dmesg | grep gpio
[   60.450234] i2c-gpio i2c-gpio.0: using pins 21 (SDA) and 22 (SCL)
root@LEDE:~# i2cdetect -l
i2c-0    i2c           i2c-gpio0                           I2C adapter
root@LEDE:~# i2cdetect -F 0
Functionalities implemented by /dev/i2c-0:
I2C                              yes
SMBus Quick Command              yes
SMBus Send Byte                  yes
SMBus Receive Byte               yes
SMBus Write Byte                 yes
SMBus Read Byte                  yes
SMBus Write Word                 yes
SMBus Read Word                  yes
SMBus Process Call               yes
SMBus Block Write                yes
SMBus Block Read                 yes
SMBus Block Process Call         yes
SMBus PEC                        yes
I2C Block Write                  yes
I2C Block Read                   yes

After instantiation, you should get some information on

dmesg | tail

. The device should then be available at /sys/class/hwmon/.

root@LEDE:~# dmesg | tail
[  114.300700] IPv6: ADDRCONF(NETDEV_CHANGE): br-lan: link becomes ready
[  126.253146] random: crng init done
[  146.413349] eth1: link down
[  146.415168] br-lan: port 1(eth1) entered disabled state
[  148.964201] eth1: link up (1000Mbps/Full duplex)
[  148.967428] br-lan: port 1(eth1) entered blocking state
[  148.972589] br-lan: port 1(eth1) entered forwarding state
[  225.964368] Custom GPIO-based I2C driver version 0.1.1
[  225.968606] i2c-gpio i2c-gpio.0: using pins 21 (SDA) and 22 (SCL)
[  250.906957] i2c i2c-0: new_device: Instantiated device ads1015 at 0x48


root@LEDE:/sys/class# ls
bdi           hidraw        mdio_bus      pci_bus       video4linux
block         i2c-dev       mem           power_supply
bluetooth     ieee80211     misc          ppp
firmware      input         mtd           spi_master
gpio          leds          net           tty


Last three questions:

1. I guess I use git push to add the code for the ads1015?

2. I'm guessing 59-i2c-gpio in /etc/modules.d is where I use vim to add in "insmod i2c-gpio-custom bus0=0,21,22" so those pins are loaded on startup?

3. And where is the digital output of the chip and is there a way to tell it to be a text file? I'm guessing the SDA output of the chip, between the 0x48 address bites, will output something that the router can capture and put into a text file. In the end, Matlab will read this and make sense of it.

hxxps://e2e.ti.com/cfs-file/__key/communityserver-discussions-components-files/73/2055.Capture.PNG

(Last edited by i2cplease on 28 Nov 2017, 01:45)

1. You can either send a patch to the mailing list or if you have got a Github account, you can send a pull request.
2. I have got that in /etc/modules.d/66-i2c-gpio-custom (I just appended my bus information).
3. It seems the hwmon-core module is not loaded, and that way even the ads1015 is missing. If you had built them as modules, you may have to install them with opkg.

The discussion might have continued from here.