humanpowered
Member
I am trying to connect two MPU6050s to my T4.1 but can't get the i2c scanner to recognize both of them. I'm using the standard bus Wire(SCL 19 and SDA 18) and the second Wire1(SCL 16 SDA 17). With my current sketch, it doesn't recognize Wire only Wire1 (when I disconnect Wire1 it says no i2c). If I go back to the original it recognizes Wire, but not Wire1. I've done a lot of searching but couldn't find a solution to my problem.
Here is the code I am using with some comments where I think I've gone wrong. Any help is greatly appreciated.
Here is the code I am using with some comments where I think I've gone wrong. Any help is greatly appreciated.
Code:
#include <Wire.h>
void setup()
{
Wire.setSCL(19);
Wire.setSDA(18);
Wire1.setSCL(16);
Wire1.setSDA(17);
Wire.begin();
Wire1.begin();
Serial.begin(9600);
while (!Serial);
Serial.println("\nI2C Scanner");
}
void loop()
{
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ ) //I'm guessing I haven't updated this correctly
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
Wire1.beginTransmission(address); // same thing here
error = Wire.endTransmission();
error = Wire1.endTransmission(); // and here
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknown error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(5000);
}