humanpowered
Member
Sensors not found through Multiplexer on T4.1?
Hi All, and thanks for the help so far!
I'm trying to connect two MPU6050s to a T4.1 via i2c and the Adafruit TCA9548A. I am able to use a modified i2c scanner and see the sensors, but when I use the following sketch it fails to connect to the sensors. I've meticulously checked the wiring so I don't think that's it (but I've included a fritzing just in case). I'm also including the i2c scanner I used that was able to detect the sensors.
Thank you for any help!!!
Sketch that is not working:
Modified i2c scanner:
Hi All, and thanks for the help so far!
I'm trying to connect two MPU6050s to a T4.1 via i2c and the Adafruit TCA9548A. I am able to use a modified i2c scanner and see the sensors, but when I use the following sketch it fails to connect to the sensors. I've meticulously checked the wiring so I don't think that's it (but I've included a fritzing just in case). I'm also including the i2c scanner I used that was able to detect the sensors.
Thank you for any help!!!
Sketch that is not working:
Code:
#include "MPU6050.h"
#include <Wire.h>
#define TCAADDR 0x70
MPU6050 mpu1;
MPU6050 mpu2;
int16_t ax, ay, az;
int16_t gx, gy, gz;
void tcaselect(uint8_t i) {
if (i > 7) return;
Wire.beginTransmission(TCAADDR);
Wire.write(1 << i);
Wire.endTransmission();
}
void setup(void)
{
Serial.begin(38400);
Serial.println("2 MPU 6050s on multiplexer Test"); Serial.println("");
Serial.println("Initializing I2C devices...");
/* Initialise the sensors */
tcaselect(2);
mpu1.initialize();
Serial.println(mpu1.testConnection() ? "MPU1 connection successful" : "MPU1 connection failed"); // returns connection failed
tcaselect(6);
mpu2.initialize();
Serial.println(mpu2.testConnection() ? "MPU2 connection successful" : "MPU2 connection failed"); // returns connection failed
Serial.println("");
delay(3000);
}
void loop(void)
{
tcaselect(2);
mpu1.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
Serial.print("Sensor 1 accel:\t");
Serial.print(ax); Serial.print("\t");
Serial.print(ay); Serial.print("\t");
Serial.print(az); Serial.print("\t");
Serial.print(gx); Serial.print("\t");
Serial.print(gy); Serial.print("\t");
Serial.println(gz);
tcaselect(6);
mpu2.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
Serial.print("Sensor 2 accel:\t");
Serial.print(ax); Serial.print("\t");
Serial.print(ay); Serial.print("\t");
Serial.print(az); Serial.print("\t");
Serial.print(gx); Serial.print("\t");
Serial.print(gy); Serial.print("\t");
Serial.println(gz);
delay(500);
}
Modified i2c scanner:
Code:
/**
* 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"
uint8_t twi_writeTo(uint8_t address, uint8_t* data, uint8_t length, uint8_t wait, uint8_t sendStop)
{
if (!wait) return 4;
Wire.beginTransmission(address);
while (length) {
Wire.write(*data++);
length--;
}
return Wire.endTransmission(sendStop);
}
#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()
{
}
Last edited: