BobT1300
Posts: 13
Joined: Sun Sep 04, 2016 8:34 am

Wanted - i2c code to use HDC1080's via TCA9548 multiplexer

Sat Oct 08, 2016 10:46 pm

I found that the i2c Python code to read temperature and humidity data from the TI HDC1080 written by baf2000_1 works perfectly, for a single sensor, many thanks.

However, when I tried to run it through a TI TCA9548 multiplexer, for which the Python code uses a smbus command to set the port e.g. "bus.write_byte_data (0x70,0x01,0x02)" which in this case sets the multiplexer at address 0x70, to use the device connected to port 2, it would not work.

Using the multiplexer with other i2c sensors (Si7051) that use smbus code, works OK.

I could not work out what would be the appropriate non-smbus code to set the multiplexer ports.

Could someone suggest some Python code that would enable the multiplexer port to be set without using smbus, or is there now some smbus Python code that can operate the HDC1080?

Any help would be greatly appreciated.

Bob.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 9232
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Wanted - i2c code to use HDC1080's via TCA9548 multiplex

Sun Oct 09, 2016 8:44 am

Use the Linux kernel driver for the TCA9548 to remove all the mux control from your application. There's even an overlay to make configuration easy.

Code: Select all

dtoverlay=i2c-mux,pca9548
and you should get a load of extra devices show up under /dev/i2cN, one for each port.
The multiplexer I2C control address (default 0x70) is obviously not available on any of the slave ports, but i2c-detect should reflect that.

viewtopic.php?f=44&t=141517 for fuller discussion of the mux support.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

BobT1300
Posts: 13
Joined: Sun Sep 04, 2016 8:34 am

Re: Wanted - i2c code to use HDC1080's via TCA9548 multiplex

Sun Oct 09, 2016 4:57 pm

Thanks for the rapid response, but I've not moved forward.
Having put "dtoverlay=i2c-mux,pca9548" into config.txt and re-booting, the "ls" command is only showing the one device, instead of a list of several, and i2cdetect is only showing the multiplexer at 0x70, with no sign of any of the sensors at 0x40.
I'm guessing that the multiplexer may need a command to open up the ports, as on power up, none are open, and if a command is needed - I do not know how to do it.
What do I need to do?

Bob.

User avatar
joan
Posts: 14985
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Wanted - i2c code to use HDC1080's via TCA9548 multiplex

Sun Oct 09, 2016 5:42 pm

What is reported by

dmesg|grep pca

BobT1300
Posts: 13
Joined: Sun Sep 04, 2016 8:34 am

Re: Wanted - i2c code to use HDC1080's via TCA9548 multiplex

Sun Oct 09, 2016 9:48 pm

"dmesg|grep pca" does not report anything, which I presume means that something called pca is missing or has not started correctly?

User avatar
joan
Posts: 14985
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Wanted - i2c code to use HDC1080's via TCA9548 multiplex

Sun Oct 09, 2016 10:15 pm

After adding dtoverlay=i2c-mux,pca9548 to /boot/config.txt I get

Code: Select all

dmesg|grep pca
[    4.749071] pca954x 1-0070: probe failed
I don't have a PCA9548 so that is expected.

I would have thought some message would be present in your case.

BobT1300
Posts: 13
Joined: Sun Sep 04, 2016 8:34 am

Re: Wanted - i2c code to use HDC1080's via TCA9548 multiplex

Sun Oct 09, 2016 11:26 pm

Moving forward, thanks...

I found a typo - I had added an "a" after pca9548, copied from one of the earlier versions of mux support listed by 6by9.

Using dmesg|grep pca I now see that it is working.

When I use i2cdetect -y 1 I can see the multiplexer as UU at 0x70.

What do I need to put into my code to read data from the correct port, as with no changes - I get an Input/output error.

Bob.

BobT1300
Posts: 13
Joined: Sun Sep 04, 2016 8:34 am

Re: Wanted - i2c code to use HDC1080's via TCA9548 multiplex

Mon Oct 10, 2016 6:13 am

I think I'm getting close to a result, the port addresses are from 3 to 10, whilst on the device they are labelled 0 to 7, so ports 1 & 2 came up with errors. I'll try again after work...

This leads to another question, when such an input error occurs, is there a way to record the data as say XX.XX °C or YY.YY %RH and continue running, instead of simply stopping due to the lack of input - or should this be a new post?

Bob.

User avatar
joan
Posts: 14985
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Wanted - i2c code to use HDC1080's via TCA9548 multiplex

Mon Oct 10, 2016 8:23 am

I think you are meant to get a new I2C device per port, so perhaps devices /dev/i2c-2, to /dev/i2c-9 should now be present.

To read the device connected to the lowest multiplexor port just open/read/write /dev/i2c-2, etc.

I'm not a fan of this software model. I think it's far simpler just to use the multiplexor directly.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 9232
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Wanted - i2c code to use HDC1080's via TCA9548 multiplex

Mon Oct 10, 2016 8:48 am

The 8 ports show up as /dev/i2c-3 to /dev/i2c-10, as they are the first 8 undefined bus numbers.
i2c-0 is the bus used by the GPU to talk to the camera, display, HATs, etc.
i2c-1 is the parent bus.
i2c-2 is the bus up the HDMI cable for reading the monitor EDID, but is normally controlled by the GPU except with the new OpenGL driver.

The advantage of letting the kernel do this is that it allows multiple clients to use the outputs of the mux. Otherwise you have a HUGE race condition where two different processes could be switching the mux around without the other's knowledge. All your client code can also be totally platform agnostic once given the i2c bus to talk on.

Address 0x70 being listed as UU in i2cdetect is correct - the kernel driver has reserved the address for it to talk to the mux, and should block out all other users trying to talk to it.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

BobT1300
Posts: 13
Joined: Sun Sep 04, 2016 8:34 am

Re: Wanted - i2c code to use HDC1080's via TCA9548 multiplex

Mon Oct 10, 2016 9:37 pm

Problems solved - many thanks to joan and 6by9.

Bob.

User avatar
Gavinmc42
Posts: 4547
Joined: Wed Aug 28, 2013 3:31 am

Re: Wanted - i2c code to use HDC1080's via TCA9548 multiplex

Tue Oct 11, 2016 12:01 am

i2c-2 is the bus up the HDMI cable for reading the monitor EDID, but is normally controlled by the GPU except with the new OpenGL driver.
The OpenGL driver now has control of i2c2?
Is this done by changes in config.txt when enabling OpenGL with raspi-config?
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

Lomax
Posts: 212
Joined: Wed May 20, 2015 9:43 pm

Re: Wanted - i2c code to use HDC1080's via TCA9548 multiplex

Mon Nov 28, 2016 1:27 pm

Gavinmc42 wrote:
i2c-2 is the bus up the HDMI cable for reading the monitor EDID, but is normally controlled by the GPU except with the new OpenGL driver.
The OpenGL driver now has control of i2c2?
Is this done by changes in config.txt when enabling OpenGL with raspi-config?
As I'm having trouble getting correct EDID from my monitor after switching to the (experimental) OpenGL driver I'm also interested in this. Can anyone shed some light?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 9232
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Wanted - i2c code to use HDC1080's via TCA9548 multiplex

Mon Nov 28, 2016 1:38 pm

Lomax wrote:
Gavinmc42 wrote:
i2c-2 is the bus up the HDMI cable for reading the monitor EDID, but is normally controlled by the GPU except with the new OpenGL driver.
The OpenGL driver now has control of i2c2?
Is this done by changes in config.txt when enabling OpenGL with raspi-config?
As I'm having trouble getting correct EDID from my monitor after switching to the (experimental) OpenGL driver I'm also interested in this. Can anyone shed some light?
Going well off topic, but https://github.com/raspberrypi/linux/bl ... ay.dts#L47
It's automatic when you've added dtoverlay=vc4-kms-v3d to config.txt. You should have /dev/i2c2 and be able to run "i2c-detect -y 2" with that overlay.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Return to “Interfacing (DSI, CSI, I2C, etc.)”