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?

5
  • 1
    did you read the answer to this question? arduino.stackexchange.com/questions/70834/…
    – Juraj
    Oct 8 '21 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
    – chrisl
    Oct 8 '21 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 Oct 8 '21 at 21:50
  • @Juraj It works, thanks! Oct 11 '21 at 16:28
  • @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. Oct 11 '21 at 16:30
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;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.