I'm looking at communicating with sensors via Adafruit TCA9548A breakout.

Mr Wood posted this great class: How to use Adafruit TCA9548A 1-to-8 I2C Multiplexer Breakout in C#?

It seems to be selecting the device and channels fine, my issue is after a successful connection, how would I address the device i would like to communicate with?

I have 3 of the same sensor connected to different channels on the multiplexer.

From Python or Arduino C, each transmission of communication states the address to communicate with, however in C# I have to define this before any read/write is done.

The problem I have is that it seems to me when I communicate with my sensor, I am sending a byte which is switching the channel on the multiplexer and then communicating with the wrong sensor. I'm getting data just its coming from the wrong sensor. The sensor I seem to continuously get data from is the sensor on channel 2.

I am completely stuck. I have tried initialing the I2C device each time I want to communicate with it, I tried sharing the I2C device between all the sensors (current setup) nought.

This is my current code https://pastebin.com/pSQXTdEm MainPage code https://pastebin.com/C0pLT80r

| improve this question | | | | |
  • Your code is too long and too complicated for such an application, so I didn't really go through it. But I think if you are using Tca9548a.SelectAddress(0x70, 0x01) to select the multiplexer, it is what you get, i.e. Channel 2. To address Channel 1, you need to pass in 0x00, or Channel 3 with 0x10. – hcheung Oct 4 '17 at 15:16
  • Yes, i understand that part. It seems to be selecting the correct channel, but from what I understand, I need to open a new I2CDevice with the sensors I2c address after this selection. The library in C# says I cannot change this 'on the fly'. So I initalise a new I2CDevice with the sensors address, this seems to then reset the whole port selection on the multiplexer. I want to i2c though the i2c multiplexer. I've already done this in another language, its converting it in C# is my issue. – Rozée Oct 4 '17 at 15:41
  • Just reading your comment further, 0x01 = 2? 0x00 = 1? 0x10 = 3? What am I missing here? I thought 0-7 for the 8 channels on the multiplexer. 0x00 would be channel 0 upto 0x07 would be channel 7? – Rozée Oct 4 '17 at 16:27
  • Sorry, my mistake, I mistaken it as binary (0x10 as binary 3).... You are correct in channel selection. – hcheung Oct 5 '17 at 0:15
  • I'm voting to close this question as off-topic because this is code related and not Raspberry Pi specific. – Piotr Kula Oct 14 '17 at 18:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.