kriswiner / MPU9250

Arduino sketches for MPU9250 9DoF with AHRS sensor fusion
1.04k stars 471 forks source link

Can not connect to MPU9250 with another I2C device connected #291

Open itayrosenml opened 6 years ago

itayrosenml commented 6 years ago

Hi,

I have no problem connecting to MPU9250 when it's the only I2C device connected. But if another device is connected, I'm getting the following error: Could not connect to MPU9250: 0x0.

My code right now is:

#include "MPU9250.h"
MPU9250 myIMU;
void setup()
{
  Wire.begin();
  Serial.begin(115200);

  // check IMU communication
  byte c = myIMU.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250);
  if (c == 0x71)
  {
    myIMU.calibrateMPU9250(myIMU.gyroBias, myIMU.accelBias); // Calibrate gyro and accelerometers, load biases in bias registers
    myIMU.initMPU9250(); // Initialize device for active mode read of acclerometer, gyroscope, and
  }
  else
  {
    Serial.print("Could not connect to MPU9250: 0x");
    Serial.println(c, HEX);
    while(1) ; // Loop forever if communication doesn't happen
  }
}

Scanning for I2C devices results in the following: Scanning... I2C device found at address 0x68 ! done

I'm using Arduino mini pro (5v version) and I use a power regulator (by polulu) to provide 3.3v to mpu9250.

kriswiner commented 6 years ago

No idea. The MPU9250 is not 5 V tolerant, so you likely need logic level translation for the I2C bus. What is the I2C address of the other device?

On Sun, Jun 24, 2018 at 1:50 AM, itayrosenml notifications@github.com wrote:

Hi,

I have no problem connecting to MPU9250 when it's the only I2C device connected. But if another device is connected, I'm getting the following error: Could not connect to MPU9250: 0x0.

My code right now is: `

include "MPU9250.h"

MPU9250 myIMU; void setup() { Wire.begin(); Serial.begin(115200);

// check IMU communication byte c = myIMU.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250); if (c == 0x71) { myIMU.calibrateMPU9250(myIMU.gyroBias, myIMU.accelBias); // Calibrate gyro and accelerometers, load biases in bias registers myIMU.initMPU9250(); // Initialize device for active mode read of acclerometer, gyroscope, and } else { Serial.print("Could not connect to MPU9250: 0x"); Serial.println(c, HEX); while(1) ; // Loop forever if communication doesn't happen } } `

Scanning for I2C devices results in the following: Scanning... I2C device found at address 0x68 ! done

I'm using Arduino mini pro (5v version) and I use a power regulator (by polulu) to provide 3.3v to mpu9250.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/291, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qp2apf7C_sVExVSp-r_0EZXRBhEUks5t_1LTgaJpZM4U1E80 .

itayrosenml commented 6 years ago

Hi, thanks for your reply! Turns out they have the same address. After reading the datasheet, looks like I can change MPU92750's address by connecting AD0 to 3.3v. I tried doing so but it's still set to 0x68 rather than 0x69. Am I doing it correctly?

kriswiner commented 6 years ago

This is sparkfun so you might have to change a solder jumper. Or ask them.

On Sun, Jun 24, 2018 at 7:36 AM, itayrosenml notifications@github.com wrote:

Hi, thanks for your reply! Turns out they have the same address. After reading the datasheet, looks like I can change MPU92750's address by connecting AD0 to 3.3v. I tried doing so but it's still set to 0x68 rather than 0x69. Am I doing it correctly?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/291#issuecomment-399761226, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qpWKId7eHZQ1xLjqWII1n8mW52_Sks5t_6P4gaJpZM4U1E80 .

itayrosenml commented 6 years ago

Hi, I managed to change the device address to 0x69. However, it works only when the address is 0x68. I believe there's some change I should make in the code? I added the following line to my code: #define MPU9250_ADDRESS 0x69. The problem that I'm facing is that the readings are always 0.00 (there's no error).

itayrosenml commented 6 years ago

I should also note that for some reason it takes 5161 milliseconds to initialize the device now

  byte c = myIMU.readByte(0x69, WHO_AM_I_MPU9250);
  if (c == 0x71)
  {
    myIMU.calibrateMPU9250(myIMU.gyroBias, myIMU.accelBias); // Calibrate gyro and accelerometers, load biases in bias registers
    myIMU.initMPU9250(); // Initialize device for active mode read of acclerometer, gyroscope, and
  }
kriswiner commented 6 years ago

That's because the program is actually running and you are calibrating the sensors, which takes some time.

On Mon, Jun 25, 2018 at 5:00 AM, itayrosenml notifications@github.com wrote:

I should also note that for some reason it takes 5161 milliseconds to initialize the device now byte c = myIMU.readByte(0x69, WHO_AM_I_MPU9250); if (c == 0x71) { myIMU.calibrateMPU9250(myIMU.gyroBias, myIMU.accelBias); // Calibrate gyro and accelerometers, load biases in bias registers myIMU.initMPU9250(); // Initialize device for active mode read of acclerometer, gyroscope, and }

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/291#issuecomment-399926977, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1quDFEOVRbXjET1Dt9gdCLWkC7rbDks5uANDigaJpZM4U1E80 .

itayrosenml commented 6 years ago

Hi, thanks for the reply but it only answers part of my question. I still can't get it to work when using 0x69 address. Am I missing a piece of code I should change?

kriswiner commented 6 years ago

Probably. What part doesn;t work?

On Mon, Jun 25, 2018 at 11:29 PM, itayrosenml notifications@github.com wrote:

Hi, thanks for the reply but it only answers part of my question. I still can't get it to work when using 0x69 address. Am I missing a piece of code I should change?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/291#issuecomment-400194123, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qk3gQ23--HmN3F5LmANj0WwLWJ1Vks5uAdTGgaJpZM4U1E80 .

itayrosenml commented 6 years ago

I'm getting values of 0 when using address 0x69.

kriswiner commented 6 years ago

OK, link to sketch being used. At what line do you run into trouble?

On Tue, Jun 26, 2018 at 11:45 PM, itayrosenml notifications@github.com wrote:

I'm getting values of 0 when using address 0x69.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/291#issuecomment-400561222, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qsQzbB9SMBSLGWuQmTPSbYRmIHfWks5uAyoegaJpZM4U1E80 .

itayrosenml commented 6 years ago
#include "MPU9250.h"
MPU9250 myIMU;
void setup()
{
  Wire.begin();
  Serial.begin(115200);

  // check IMU communication
  byte c = myIMU.readByte(0x69, WHO_AM_I_MPU9250);
  if (c == 0x71)
  {
    myIMU.calibrateMPU9250(myIMU.gyroBias, myIMU.accelBias); // Calibrate gyro and accelerometers, load biases in bias registers
    myIMU.initMPU9250(); // Initialize device for active mode read of acclerometer, gyroscope, and
  }
  else
  {
    Serial.print("Could not connect to MPU9250: 0x");
    Serial.println(c, HEX);
    while(1) ; // Loop forever if communication doesn't happen
  }
}

void loop() {
 Serial.println(myIMU.ax);
}

Serial prints 0's (in void loop).

kriswiner commented 6 years ago

No idea

On Thu, Jun 28, 2018 at 12:01 AM, itayrosenml notifications@github.com wrote:

include "MPU9250.h"

MPU9250 myIMU; void setup() { Wire.begin(); Serial.begin(115200);

// check IMU communication byte c = myIMU.readByte(0x69, WHO_AM_I_MPU9250); if (c == 0x71) { myIMU.calibrateMPU9250(myIMU.gyroBias, myIMU.accelBias); // Calibrate gyro and accelerometers, load biases in bias registers myIMU.initMPU9250(); // Initialize device for active mode read of acclerometer, gyroscope, and } else { Serial.print("Could not connect to MPU9250: 0x"); Serial.println(c, HEX); while(1) ; // Loop forever if communication doesn't happen } }

void loop() { Serial.println(myIMU.ax); }

Serial prints 0's (in void loop).

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/291#issuecomment-400933239, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qsjmWqUZCEQDKRWe5KHropSH5f_0ks5uBH86gaJpZM4U1E80 .