0

I'm using ESP32 and 1 sensor mpu9250(only for test) with tca9548a, connections are:

TCA <-> ESP

VIN - VCC

GND - GND

SDA - GPIO21

SCL - GPIO22

TCA <-> MPU

SD2 - SDA

SC2 - SCL

VIN - VIN

GND - GND

And my code here:

#include <SparkFunMPU9250-DMP.h>
#include <Wire.h>
#define TCAADDR 0x70
void tcaselect(uint8_t i) {
 if (i > 7) return;
 
 Wire.beginTransmission(TCAADDR);
 Wire.write(1 << i);
 Wire.endTransmission(); 
}
MPU9250_DMP imu;
void setup() 
{
 Serial.begin(115200);
 Wire.begin();
 tcaselect(2);
 if (imu.begin() != INV_SUCCESS)
 {
 while (1)
 {
 Serial.println("Unable to communicate with MPU-9250");
 Serial.println("Check connections, and try again.");
 Serial.println();
 delay(5000);
 }
 }
 
 imu.dmpBegin(DMP_FEATURE_6X_LP_QUAT | // Enable 6-axis quat
 DMP_FEATURE_GYRO_CAL, // Use gyro calibration
 10); // Set DMP FIFO rate to 10 Hz
 delay(10000);
}
void loop() 
{
 tcaselect(2);
 imu.dmpUpdateFifo();
 float q0 = imu.calcQuat(imu.qw);
 float q1 = imu.calcQuat(imu.qx);
 float q2 = imu.calcQuat(imu.qy);
 float q3 = imu.calcQuat(imu.qz);
 Serial.println("Q: " + String(q0, 4) + ", " +
 String(q1, 4) + ", " + String(q2, 4) + 
 ", " + String(q3, 4));delay(10);
}

I need to get quaternions from the MPU sensor but I'm only getting zeros on the output.

enter image description here

Library that I used: https://github.com/rupin/SparkFun_MPU-9250-DMP_Arduino_Library

What could be wrong, my connection or library?

asked Oct 8, 2021 at 10:36
4
  • 1
    did you read the answer to this question? arduino.stackexchange.com/questions/70834/… Commented Oct 8, 2021 at 14:04
  • You could try adapting the I2C Scanner sketch to use the TCA9548a like you do. Then you can check if the MPU is really visible on the bus. I would think, that the Arduino cannot reach the MPUn thus giving only zeros Commented Oct 8, 2021 at 18:56
  • @Juraj yes, I will try this method later. But now I'd like to figure out why my method doesn't work Commented Oct 8, 2021 at 21:50
  • @chrisl It`s true, TCA scanner cannot find any addresses of MPU9250. Seems like clock stretching(idk). But now I use method of changing address of MPU that i use in 1 tick. Commented Oct 11, 2021 at 16:30

1 Answer 1

0

The solution is that I just removed the tca9548a from the circuit. Then I connected each AD0 pin to the corresponding GPIO ESP32 pins to turn on the sensor, I send a low signal to it, and a high signal to all the others. Thus, the library only works with a sensor whose address is 0x68.

There is example function from my sketch:

#include <SparkFunMPU9250-DMP.h>
/*INIT SENSORS*/
MPU9250_DMP imu;
MPU9250_DMP imu1;
const int sensor1 = 18;
const int sensor2 = 19;
String IMU_1Update(){
 String res;
 digitalWrite(sensor1, LOW); // 1st sensor enable - 0x68
 digitalWrite(sensor2, HIGH); // 2nd sensor disable - 0x69
 if ( imu1.fifoAvailable() ){
 if ( imu1.dmpUpdateFifo() == INV_SUCCESS){
 float q0 = imu1.calcQuat(imu1.qw);
 float q1 = imu1.calcQuat(imu1.qx);
 float q2 = imu1.calcQuat(imu1.qy);
 float q3 = imu1.calcQuat(imu1.qz);
 Serial.print("G1|");
 Serial.print(q0);
 Serial.print("|");
 Serial.print(q1);
 Serial.print("|");
 Serial.print(q2);
 Serial.print("|");
 Serial.print(q3);
 Serial.println("|");
 }
 }
 return res;
}
answered Oct 11, 2021 at 16:37

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.