Go Down

Topic: Multiplexing With a Shield (Read 111 times) previous topic - next topic

mmoniot

I am using an Arduino MEGA 2560 and working on a project that involves taking and logging data from 4 distance sensors. The distance sensors I am using are VL53L0X and operate on I2C with an address of 0x27. Given that these sensors have the same address, I am using a TCA9548A multiplexer to handle using multiple sensors.

My issue: my code fails when I use an Adafruit Datalogging Shield, but succeeds when I do not use one. To troubleshoot, I have run a handy scanner script that Adafruit hosts on their website:

Code: [Select]
/**
 * TCA9548 I2CScanner.pde -- I2C bus scanner for Arduino
 *
 * Based on code c. 2009, Tod E. Kurt, http://todbot.com/blog/
 *
 */
 
#include "Wire.h"
extern "C" {
#include "utility/twi.h"  // from Wire library, so we can do bus scanning
}
 
#define TCAADDR 0x70
 
void tcaselect(uint8_t i) {
  if (i > 7) return;
 
  Wire.beginTransmission(TCAADDR);
  Wire.write(1 << i);
  Wire.endTransmission(); 
}
 
 
// standard Arduino setup()
void setup()
{
    while (!Serial);
    delay(1000);
 
    Wire.begin();
   
    Serial.begin(115200);
    Serial.println("\nTCAScanner ready!");
   
    for (uint8_t t=0; t<8; t++) {
      tcaselect(t);
      Serial.print("TCA Port #"); Serial.println(t);
 
      for (uint8_t addr = 0; addr<=127; addr++) {
        if (addr == TCAADDR) continue;
     
        uint8_t data;
        if (! twi_writeTo(addr, &data, 0, 1, 1)) {
           Serial.print("Found I2C 0x");  Serial.println(addr,HEX);
        }
      }
    }
    Serial.println("\ndone");
}
 
void loop()
{
}


When I run this with the shield, here is what my console shows:

TCAScanner ready!
TCA Port #0
Found I2C 0x29
Found I2C 0x68
TCA Port #1
Found I2C 0x29
Found I2C 0x68
TCA Port #2
Found I2C 0x29
Found I2C 0x68
TCA Port #3
Found I2C 0x29
Found I2C 0x68
TCA Port #4
Found I2C 0x68
TCA Port #5
Found I2C 0x68
TCA Port #6
Found I2C 0x68
TCA Port #7
Found I2C 0x68

done

Without the shield:

TCAScanner ready!
TCA Port #0
Found I2C 0x29
TCA Port #1
Found I2C 0x29
TCA Port #2
Found I2C 0x29
TCA Port #3
Found I2C 0x29
TCA Port #4
TCA Port #5
TCA Port #6
TCA Port #7

done

The multiplexer seems to be "finding" the address of my datalogging shield (which Adafruit confirms is 0x68) on every port in addition to the sensors of interest on ports 0, 1, 2, and 3. Is there a way around this? Searching the forums has given conflicting answers.

1) From this thread, it seems like I cannot do this with the selected multiplexer.

2) However, this thread suggests a project where the individual was successfully able to use the multiplexer and record data using the datalogging shield I am also using (albeit at an undesirable speed).

This all brings me to my question - is it possible to use the hardware I have selected? If there is a way to "probe" the multiplexer for a prescribed address and ignore those populated by the datalogging shield that would be fantastic. I can post my code if desired, but I don't think that's the current issue (as I successfully use the multiplexer when the shield is not present).

PaulRB

#1
Jul 05, 2018, 10:17 am Last Edit: Jul 05, 2018, 10:40 am by PaulRB
You didn't include a schematic, so I assume the shield is plugged into the Arduino and the i2c lines are also fed to a breadboard with the multiplexer and other sensors connected to the multiplexer's branch channels 0 to 3?

If so, what you see is exactly what I would expect, and does not indicate a problem. Why are you concerned about it? Was it simply unexpected?

The scanner sketch is perhaps not as clever as you were expecting. It cannot differentiate between i2c devices on the main bus and those on the 8 branches. So it reports any devices on the main bus as though they are on all 8 branches, along with any devices that are on each branch. Your data logger shield is on the main bus.

The multiplexer chip is capable of switching off all 8 branches. The sketch could be re-written to do that and scan the main bus first, before it begins scanning the branches. It could report the devices on the main bus, and then ignore those same devices when scanning the branches.

But is it really worth re-writing the sketch to do that? Can't you just live with it, now you know?

Wawa

Which VL53L0X breakout board do you have.
If it has onboard level converters then you might not need an I2C muxer.
Because the VL53L0X has a shutdown pin, you can temporary disable three of the four sensors.
See page 8 of the datasheet.

The chip's address is 0x52 according to the datasheet.
Leo..

Go Up