I’m trying to wrap my head around the two sets of I2C pins on the Electron, and see if there is a way to use two sensors with the same hardwired I2C address without having to resort to bitbashing.
Here’s my setup:
Two TCS34725 color sensors: let’s call them SensorA and SensorB. They have identical I2C addresses.
I’ve connected SensorA to D0 and D1, and SensorB to C4 and C5 on an Electron.
I don’t need to use SensorA and SensorB at the same time, but would like for both of them to use hardware I2C.
Seems like I should be able to do something like:
Wire.begin(); // initialize Sensor A // do some stuff like Wire.beginTransmission, Wire.read, Wire.write, etc. Wire.end();
The last call should release pins D0 and D1, which should allow me to then do something like:
Wire1.begin(); // initialize Sensor B // do some stuff like Wire1.beginTransmission, Wire1.read, Wire1.write, etc. Wire1.end();
But when I actually try to do this, it doesn’t work. It appears both sensors stay active, and a .read() actually takes the higher of the two sensors, which is kinda weird but that’s what it’s doing.
Seems like because SensorA and SensorB are on separate pins, I should be able to flip back and forth between the two interfaces (Wire and Wire1). But maybe even though the pins are released, the sensor on the released pins is still connected so it won’t work. Is there a way to do this? I dunno.
Anyway, I hope this makes sense and that there is some way to switch back and forth between I2C pin pairs. Any help would be greatly appreciated.