ferme
June 22, 2021, 10:04am
1
Hi,
I try to make a datalogger using 3 different MPU6050. I use the TCA9548A multiplexer to communicate in I2C with my arduino (Leonardo or MKR1010, I use both but I have the same problem with each).
When I launch a scanner dedicated to find the devices linked to the TCA multiplexer I find all of my sensors. However when I launch the basic_reading script from adafruit (modified to use the multiplexer) I can't find any of the mpu.
My problem is exactly the same as this topic :
Hi All,
I've got two MPU6050s connected to a Mega via i2c and an Adafruit TCA9548A multiplexer. When I use an i2c scanner they are both found, but when I try to read data from them they don't connect. I'm using a modified version of Adafruit's example sketch. The only thing that is different is when assigning a unique ID to the sensors
Adafruit example excerpt:
Adafruit_HMC5883_Unified mag1 = Adafruit_HMC5883_Unified(1);
Adafruit_HMC5883_Unified mag2 = Adafruit_HMC5883_Unified(2);
My sketch …
If you have an answer I'll be very grateful .
Thank's for reading and have a nice day.
We need to see YOUR code, and YOUR wiring.
ferme
June 22, 2021, 1:46pm
3
Ok so here is my wiring
And this is my code
// Basic demo for accelerometer readings from Adafruit MPU6050
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
Adafruit_MPU6050 mpu;
//
//Connection avec le multiplexer
//
void tcaChannel(uint8_t i){
Wire.beginTransmission(0x70);
Serial.println("1");
Wire.write(1<<i);
Serial.println("2");
Wire.endTransmission();
Serial.println("3");
}
void setup(void) {
Serial.begin(115200);
while (!Serial)
delay(10); // will pause Zero, Leonardo, etc until serial console opens
Serial.println("Adafruit MPU6050 test!");
// Try to initialize!
tcaChannel(3);
if (!mpu.begin()) {
Serial.println("Failed to find MPU6050 chip");
while (1) {
delay(10);
}
}
Serial.println("MPU6050 Found!");
mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
Serial.print("Accelerometer range set to: ");
switch (mpu.getAccelerometerRange()) {
case MPU6050_RANGE_2_G:
Serial.println("+-2G");
break;
case MPU6050_RANGE_4_G:
Serial.println("+-4G");
break;
case MPU6050_RANGE_8_G:
Serial.println("+-8G");
break;
case MPU6050_RANGE_16_G:
Serial.println("+-16G");
break;
}
mpu.setGyroRange(MPU6050_RANGE_500_DEG);
Serial.print("Gyro range set to: ");
switch (mpu.getGyroRange()) {
case MPU6050_RANGE_250_DEG:
Serial.println("+- 250 deg/s");
break;
case MPU6050_RANGE_500_DEG:
Serial.println("+- 500 deg/s");
break;
case MPU6050_RANGE_1000_DEG:
Serial.println("+- 1000 deg/s");
break;
case MPU6050_RANGE_2000_DEG:
Serial.println("+- 2000 deg/s");
break;
}
mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
Serial.print("Filter bandwidth set to: ");
switch (mpu.getFilterBandwidth()) {
case MPU6050_BAND_260_HZ:
Serial.println("260 Hz");
break;
case MPU6050_BAND_184_HZ:
Serial.println("184 Hz");
break;
case MPU6050_BAND_94_HZ:
Serial.println("94 Hz");
break;
case MPU6050_BAND_44_HZ:
Serial.println("44 Hz");
break;
case MPU6050_BAND_21_HZ:
Serial.println("21 Hz");
break;
case MPU6050_BAND_10_HZ:
Serial.println("10 Hz");
break;
case MPU6050_BAND_5_HZ:
Serial.println("5 Hz");
break;
}
Serial.println("");
delay(100);
}
void loop() {
tcaChannel(2);
/* Get new sensor events with the readings */
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
/* Print out the values */
Serial.print("Acceleration X: ");
Serial.print(a.acceleration.x);
Serial.print(", Y: ");
Serial.print(a.acceleration.y);
Serial.print(", Z: ");
Serial.print(a.acceleration.z);
Serial.println(" m/s^2");
Serial.print("Rotation X: ");
Serial.print(g.gyro.x);
Serial.print(", Y: ");
Serial.print(g.gyro.y);
Serial.print(", Z: ");
Serial.print(g.gyro.z);
Serial.println(" rad/s");
Serial.print("Temperature: ");
Serial.print(temp.temperature);
Serial.println(" degC");
Serial.println("");
delay(500);
}
Thanks a lot
@ferme , your topic has been moved to a more suitable location on the forum.
Please edit your post #3 , select all code and click the </>
button to apply code tags; next save your post.
Can you please take some time to read How to get the best out of this forum .
Sorry but that is not a wiring diagram. It's a Fritzing impressing no helper. Please post code, not text. Use autoformat in the IDE and code tags when posting.
You should post code by using code-tags
There is an automatic function for doing this in the Arduino-IDE
just three steps
press Ctrl-T for autoformatting your code
do a rightclick with the mouse and choose "copy for forum"
paste clipboard into write-window of a posting
best regards Stefan
Here is a scanner-version for the I2C-multiplexer
//I2C-Scanner fuer TCA9548A
//Code fuer Arduino
//Author Retian
//Version 1.0
#include <Wire.h>
//Prototype
void scanneTCA(void);
byte tcaI2cAdd;
void setup() {
Serial.begin(115200);
Wire.begin();
Serial.println(F("I2C-Scanner fuer TCA9548A"));
Serial.println();
}
void loop() {
bool tcaGefunden = false;
Serial.print(F("Scanne TCA9548A-Adressen:"));
for (byte tcaI2cAdd = 0x70; tcaI2cAdd < 0x78; tcaI2cAdd++)
{
Wire.beginTransmission(tcaI2cAdd);
if (Wire.endTransmission() == 0)
{
tcaGefunden = true;
Serial.print(F(" 0x"));
Serial.print(tcaI2cAdd, HEX);
Serial.println(F(" gefunden"));
Serial.println(F("Scanne Kanaele:"));
scanneTCA(tcaI2cAdd);
}
}
if (!tcaGefunden) Serial.println(F("TCA9548A nicht gefunden"));
Serial.println();
delay(2000);
}
void scanneTCA(byte tcaAdd) {
bool adresseGefunden = false;
for (byte channel = 0; channel < 8; channel++)
{
Wire.beginTransmission(tcaAdd);
Wire.write(1 << channel);
Wire.endTransmission();
for (byte add = 1; add < 128; add++)
{
if (add != tcaAdd)
{
Wire.beginTransmission(add);
if (Wire.endTransmission() == 0)
{
adresseGefunden = true;
Serial.print(F("Kanal "));
Serial.print(channel);
Serial.print(F(": Adresse 0x"));
Serial.print(add, HEX);
Serial.println(F(" gefunden"));
}
}
}
}
if (!adresseGefunden) Serial.println(F("Keine Adresse gefunden"));
}
best regards Stefan
Thanks! That's code the best way it can be!
Sorry but that multiplexer calls for experience I haven't got.
ferme
June 23, 2021, 7:57am
9
Thanks for your advices, I changed it
Hi, @ferme
Welcome to the forum.
What MPU module do you have?
Does it have some address jumpers on it so you can give each MPU a different address and run them all of the same I2C bus without a multiplexer?
Tom...
ferme
June 23, 2021, 8:43am
11
Hi,
I have two MPU 6050. I know I could change the adress of each multiplexer (0x68 and 0x69) but in the long term I would like to make a system with three mpu. And these MPU have only two different adresses.
Thanks for your help
ferme
June 23, 2021, 8:59am
13
Hi,
I'll look at it.
I made a diagram, as you asked. I hope it is clear.
ferme
June 24, 2021, 10:22am
14
Hi,
Do anyone knows how to do with the TCA9548A ?
Thanks for your help
Hi,
Have you looked at this Adafruit tutorial and looked at and tried their example with two I2C units collected?
They even have a scanner.
You just found the perfect I2C sensor, and you want to wire up two or three or more of them to your Arduino when you realize "Uh oh, this chip has a fixed I2C address, and from what I know about I2C, you cannot have two devices with the same address...
Tom...
system
Closed
October 22, 2021, 10:44am
16
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.