kriswiner / MPU9250

Arduino sketches for MPU9250 9DoF with AHRS sensor fusion
1.03k stars 472 forks source link

Could not connect to MPU9250: 0xFF #58

Closed John-Val closed 8 years ago

John-Val commented 8 years ago

Hi Kris, I try to use read data from a 9 dof which has written MPY 92/65 on the breakout board. On the back it has written 9250/9255/6500/6555. So I think I should be able to use your example code. But testing it on two Arduino Uno's and with 3 different breakout boards I keep on getting:

Could not connect to MPU9250: 0xFF.

Both with or without the suggested alterations: We have disabled the internal pull-ups used by the Wire library in the Wire.h/twi.c utility file. We are also using the 400 kHz fast I2C mode by setting the TWI_FREQ to 400000L /twi.h utility file.

The uno boards have separate SCL SDA pins. I used those but I also used A4 and A5 as in the sketch. I use the 3.3 V power supply.

Am I doing something wrong or did I just buy some useless plastic and ceramics?

I hope you can help me out.

kriswiner commented 8 years ago

If you bought the purple boards from China then yes, they are junk.

Make sure the SDA and SCL lines both show 3V3 with a voltmeter when powered on.

It is likely you don't have the I2C address of the MPU9250 right. It can be either 0x68 or 0x69. If you run an I2C scan, what do you get? Here's how:

` // I2C scan function

 void I2Cscan()
 {
// scan for i2c devices
 byte error, address;
 int nDevices;

 Serial.println("Scanning...");

 nDevices = 0;
 for(address = 1; address < 127; address++ ) 
{
  // The i2c_scanner uses the return value of
   // the Write.endTransmisstion to see if
  // a device did acknowledge to the address.
  Wire.beginTransmission(address);
  error = Wire.endTransmission();

  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("Unknow 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");

  }

`

John-Val commented 8 years ago

Dear Kris, Thank you very much for your extremely quick response. Yes I did buy them in China, but tomorrow I certainly will try your other suggestions. Sincerly yours, John Val

John-Val commented 8 years ago

Hi Kris, It seems I got it working. The MPU9255 rc2 is on 0x68 Who Am I should return 73. I also forgot to change the intPin to 2. Many thanks again for your help.

sakshirawal14 commented 7 years ago

@kriswiner Hi I am facing the same issue. I tried running the I2Cscan(), but the serial monitor shows no output whatsoever. How do I know if the address is correct in the code?

kriswiner commented 7 years ago

The serial monitor should at least show Scanning...

I think there is an error in your setup.

What is the voltage on SDA and SCL?

What MCU are you using?

Which pins are you using for SDA/SCL?

Does the board have power?

Which board are you using?

Can't help much without some more info.

On Sun, May 21, 2017 at 9:18 AM, sakshirawal14 notifications@github.com wrote:

@kriswiner https://github.com/kriswiner Hi I am facing the same issue. I tried running the I2Cscan(), but the serial monitor shows no output whatsoever. How do I know if the address is correct in the code?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/58#issuecomment-302946634, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qnCRYpnIAH1gPtT28HBOR3H5lqWQks5r8GPhgaJpZM4H_-WG .

sakshirawal14 commented 7 years ago

Hi..I'm using the Arduino Uno and the MPU 9250. I have made the following connections VDD---3.3V GND---GND SCL---A5 SDA---A4

kriswiner commented 7 years ago

Mpu9259 is 3v3 only; you need to use a logic level converter?

Do you have pullup resistors on the mpu9250 board? On Sun, May 21, 2017 at 9:03 PM sakshirawal14 notifications@github.com wrote:

Hi..I'm using the Arduino Uno and the MPU 9250. I have made the following connections VDD---3.3V GND---GND SCL---A5 SDA---A4

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/58#issuecomment-302994194, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qkggCAmMoTq5wtSAPJi8CSeVEj2Xks5r8Qj9gaJpZM4H_-WG .

sakshirawal14 commented 7 years ago

It works on 3.3V. Haven't used it before but the forums and posta I have referrred to say that only the above 4 connections are needed for it to work. I'm not using any external pull-ups either.

kriswiner commented 7 years ago

What is the voltage on sda and scl?

You need pullups. On Sun, May 21, 2017 at 9:16 PM sakshirawal14 notifications@github.com wrote:

It works on 3.3V. Haven't used it before but the forums and posta I have referrred to say that only the above 4 connections are needed for it to work. I'm not using any external pull-ups either.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/58#issuecomment-302995459, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qpjartel6J4P6EtjU1m60rUBBUH8ks5r8QwWgaJpZM4H_-WG .

sakshirawal14 commented 7 years ago

Will the voltage on SDA and SCL not be 3.3 V only? I don't have much hands on experience with thw hardware. How do I use pull-ups?

kriswiner commented 7 years ago

Connect a 10 kOhm resistor between 3V3 and SDA. Do the same for SCL.

On Sun, May 21, 2017 at 10:16 PM, sakshirawal14 notifications@github.com wrote:

Will the voltage on SDA and SCL not be 3.3 V only? I don't have much hands on experience with thw hardware. How do I use pull-ups?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/58#issuecomment-303001280, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qnVnP1l83MocVX1mAziFnmUFfcx7ks5r8RpJgaJpZM4H_-WG .

sakshirawal14 commented 7 years ago

Okay..thank you. Will do that and try running the code. Will get back to you then.

sakshirawal14 commented 7 years ago

Okay..so the I2C scanner detects the device at 0x68. But when I try to run the code, it says "MPU9250 connection failed" Any idea..why?

kriswiner commented 7 years ago

Not without more info

AcidPrank commented 7 years ago

Hi kriswiner, and thank you very much for all what you did :)

I'm facing a similar problem. It seems it appears when my Arduino Due reset.. When the MPU is found, it works very well and I get serial data for a while, no crash nothing, but when I close the serial monitor, and reopen it (I think it means that Arduino Due is restarted) then one every ~3-4, the MPU will not be found. Then I need to restart the Arduino IDE unplug my USB plug again, without warranty it works.

Here is my wiring diagram, I use 2K resistors, do you think it's enough ? plan_cablage_mpu9250

kriswiner commented 7 years ago

Maybe too much, you have pullups already on the breakout no?

AcidPrank commented 7 years ago

yes I think this 1,5 k that's what I measured on SDA0 and SDA1 (20 and 21)

kriswiner commented 7 years ago

Looks like you have GND connected to 3V3 in your diagram too.

kriswiner commented 7 years ago

Huh?

AcidPrank commented 7 years ago

Excuse me, I didn't understand your sentence the first time. this is a mistake in my diagram but I didn't did it in real (fortunately !)... I tought you were saying me to change of GND ... I removed the pullup resistors, It seems better now...

AcidPrank commented 7 years ago

I think I solved my problem, two things :

first, I removed theses useless pullup resistors, that improved it. second, it happened again sometimes so I found that interesting link that described a problem really similar : https://github.com/esp8266/Arduino/issues/1025

so I implemented the solution :

void I2C_recovery() {
 Serial.println("Starting I2C bus recovery");
  delay(2000);
  int SDAPIN = 70;
  int CLKPIN = 71;
  //try i2c bus recovery at 100kHz = 5uS high, 5uS low
  pinMode(SDAPIN, OUTPUT);//keeping SDA high during recovery
  digitalWrite(SDAPIN, HIGH);
  pinMode(CLKPIN, OUTPUT);
  for (int i = 0; i < 10; i++) { //9nth cycle acts as NACK
    digitalWrite(CLKPIN, HIGH);
    delayMicroseconds(5);
    digitalWrite(CLKPIN, LOW);
    delayMicroseconds(5);
  }

  //a STOP signal (SDA from low to high while CLK is high)
  digitalWrite(SDAPIN, LOW);
  delayMicroseconds(5);
  digitalWrite(CLKPIN, HIGH);
  delayMicroseconds(2);
  digitalWrite(SDAPIN, HIGH);
  delayMicroseconds(2);
  //bus status is now : FREE

  Serial.println("bus recovery done, starting scan in 2 secs");
  //return to power up mode
  pinMode(SDAPIN, INPUT);
  pinMode(CLKPIN, INPUT);
  delay(2000);
  //pins + begin advised in https://github.com/esp8266/Arduino/issues/452
  //Wire1.pins(SDAPIN, CLKPIN); //this changes default values for sda and clock as well
  Wire1.begin();
  //only pins: no signal on clk and sda
  //only begin: no signal on clk, no signal on sda

  //no further processing in case of error
  /*
  while(true)
  {
    i2c_scan(); 
  }
  */
}

I'm using an Arduino Due with SDA1 and SCL1 that's why I use Wire1 ( and SDAPIN = 70 , CLKPIN = 71...)

And use it in the begining of my setup like this :

 if (!I2Cscan()) {
    I2C_recovery();
    I2Cscan();
  }

I modified the I2C scan so it returns true if a device has been detected, false if this is not the case...

Looks like it helps :)

Scanning...
No I2C devices found
Starting I2C bus recovery
bus recovery done, starting scan in 2 secs
Scanning...
I2C device found at address 0x0C  !
I2C device found at address 0x68  !
sakshirawal14 commented 7 years ago

@kriswiner Hi..What info can I help you with?

kriswiner commented 7 years ago

No idea what your problem is

sakshirawal14 commented 7 years ago

I2Cscanner detects the device at 0x68, but when I try to run my sketch to get raw data from the IMU, it says "MPU9250 connection failed" Also, I get 2 warning messages in the terminal window as: Invalid library found in C:\Users\sakshi\Documents\Arduino\libraries\i2cdevlib-master: C:\Users\sakshi\Documents\Arduino\libraries\i2cdevlib-master Invalid library found in C:\Users\sakshi\Documents\Arduino\libraries\i2cdevlib-master: C:\Users\sakshi\Documents\Arduino\libraries\i2cdevlib-master

kriswiner commented 7 years ago

Why use i2cdev? Maybe need to ask them? On Mon, May 22, 2017 at 9:46 PM sakshirawal14 notifications@github.com wrote:

I2Cscanner detects the device at 0x68, but when I try to run my sketch to get raw data from the IMU, it says "MPU9250 connection failed" Also, I get 2 warning messages in the terminal window as: Invalid library found in C:\Users\sakshi\Documents\Arduino\libraries\i2cdevlib-master: C:\Users\sakshi\Documents\Arduino\libraries\i2cdevlib-master Invalid library found in C:\Users\sakshi\Documents\Arduino\libraries\i2cdevlib-master: C:\Users\sakshi\Documents\Arduino\libraries\i2cdevlib-master

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/58#issuecomment-303289251, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qkfwbu4ed1588K31W2pAPvxsz01_ks5r8mSRgaJpZM4H_-WG .

sakshirawal14 commented 7 years ago

I tried using your code, but it had some errors. So I just wanted to do a basic raw data read and check first.

kriswiner commented 7 years ago

OK,

What MCU are you using?

Which code did you try?

On Mon, May 22, 2017 at 10:51 PM, sakshirawal14 notifications@github.com wrote:

I tried using your code, but it had some errors. So I just wanted to do a basic raw data read and check first.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/58#issuecomment-303297177, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qjbDk1-T_Om1wFsSKibfAsyO3maTks5r8nPkgaJpZM4H_-WG .

sakshirawal14 commented 7 years ago

I'm using the Arduino Uno and trying to get the raw values using I2C

kriswiner commented 7 years ago

Try here: http://www.lucidarme.me/?p=5057

On Mon, May 22, 2017 at 11:45 PM, sakshirawal14 notifications@github.com wrote:

I'm using the Arduino Uno and trying to get the raw values using I2C

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/58#issuecomment-303305471, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1ql5_GQz3ZyzS7UxooA6UAmslkV1Uks5r8oCGgaJpZM4H_-WG .

John-Val commented 7 years ago

To my knowledge MPU9250 is on 73. Try the MPU9150 library instead since is MPU9150 on 68.

John


Van: Kris Winer notifications@github.com Verzonden: dinsdag 23 mei 2017 08:53:19 Aan: kriswiner/MPU9250 CC: John Val; State change Onderwerp: Re: [kriswiner/MPU9250] Could not connect to MPU9250: 0xFF (#58)

Try here: http://www.lucidarme.me/?p=5057

On Mon, May 22, 2017 at 11:45 PM, sakshirawal14 notifications@github.com wrote:

I'm using the Arduino Uno and trying to get the raw values using I2C

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/58#issuecomment-303305471, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1ql5_GQz3ZyzS7UxooA6UAmslkV1Uks5r8oCGgaJpZM4H_-WG .

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHubhttps://github.com/kriswiner/MPU9250/issues/58#issuecomment-303306865, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AJ2sJmJj7PctY-q3HAeoqnuOJIBHwJc0ks5r8oJfgaJpZM4H_-WG.

kriswiner commented 7 years ago

You can't use an MPU9150 library for the MPU9250, the register addresses are different.

If you can get an ACK from the MPU9250 at I2C address 0x68, then what does the WHO_AM_I register show? Should be 0x71 for the MPU9250 or 0x73 for the MPU9255.

On Tue, May 23, 2017 at 3:18 AM, John Val notifications@github.com wrote:

To my knowledge MPU9250 is on 73. Try the MPU9150 library instead since is MPU9150 on 68.

John


Van: Kris Winer notifications@github.com Verzonden: dinsdag 23 mei 2017 08:53:19 Aan: kriswiner/MPU9250 CC: John Val; State change Onderwerp: Re: [kriswiner/MPU9250] Could not connect to MPU9250: 0xFF (#58)

Try here: http://www.lucidarme.me/?p=5057

On Mon, May 22, 2017 at 11:45 PM, sakshirawal14 notifications@github.com wrote:

I'm using the Arduino Uno and trying to get the raw values using I2C

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/58#issuecomment-303305471, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1ql5_ GQz3ZyzS7UxooA6UAmslkV1Uks5r8oCGgaJpZM4H_-WG .

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHubhttps://github.com/ kriswiner/MPU9250/issues/58#issuecomment-303306865, or mute the thread< https://github.com/notifications/unsubscribe-auth/AJ2sJmJj7PctY- q3HAeoqnuOJIBHwJc0ks5r8oJfgaJpZM4H_-WG>.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/58#issuecomment-303355451, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qpsMGzRwljHs2CALzxxT-pdRrlw-ks5r8rJqgaJpZM4H_-WG .

Patrickyp commented 6 years ago

Kris can you help me I'm trying to write high to the AD0/SDO pin of my sparkfun 9250 but the address is staying at 0x68 even though I made the pin high.

my wiring.. https://i.imgur.com/jaw8rxF.jpg

void setup()
{
    Wire.begin();
    //  TWBR = 12;  // 400 kbit/sec I2C speed
    Serial.begin(38400);

    // Set up the interrupt pin, its set as active high, push-pull
    pinMode(intPin, INPUT);
    digitalWrite(intPin, LOW);
    pinMode(myLed, OUTPUT);
    digitalWrite(myLed, HIGH);

     //  I have pin 12 connected to AD0 and writing high (~3v)
    pinMode(12, OUTPUT);
    digitalWrite(12, HIGH);

    delay(2000);
    I2Cscan();

and returns

Scanning... I2C device found at address 0x68 ! done

MPU9250 9-DOF 16-bit motion sensor 60 ug LSB MPU9250 I AM FF I should be 71 Could not connect to MPU9250: 0xFF

img_1763

kriswiner commented 6 years ago

Is pin 12 connected to ADO or not? Is pin 12 showing 3.3 V?

On Wed, May 23, 2018 at 3:30 PM, Patrickyp notifications@github.com wrote:

Kris can you help me I'm trying to write high to the AD0/SDO pin of my sparkfun 9250 but the address is staying at 0x68 even though I made the pin high.

https://i.imgur.com/jaw8rxF.jpg http://url

void setup() { Wire.begin(); // TWBR = 12; // 400 kbit/sec I2C speed Serial.begin(38400);

// Set up the interrupt pin, its set as active high, push-pull pinMode(intPin, INPUT); digitalWrite(intPin, LOW); pinMode(myLed, OUTPUT); digitalWrite(myLed, HIGH);

pinMode(12, OUTPUT); digitalWrite(12, HIGH);

delay(2000); I2Cscan();

and returns

Scanning... I2C device found at address 0x68 ! done

MPU9250 9-DOF 16-bit motion sensor 60 ug LSB MPU9250 I AM FF I should be 71 Could not connect to MPU9250: 0xFF

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/58#issuecomment-391517727, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qp5Oheq1jjrlt6doLyUEg4CW5xMRks5t1eLogaJpZM4H_-WG .

MitalPattani commented 6 years ago

@Patrickyp You need to soldier your sj2 centre pad to the right one for and then connect AD0 to 3v3 or gnd for 0×69 or 0×68 respectively. Check the sparkfun hookup guide for more information.

Patrickyp commented 6 years ago

@MitalPattani are you talking about the white little rectangle next to the square that looks like it has solder on it? SHould I be connecting solder from the square to the the white rectangle?

Patrickyp commented 6 years ago

@kriswiner I checked it (ADO) once with a volt meter and it seems to be showing around 3v I will double check again when I get a chance to work on it again but it seems like the sparkfun board needs to have some connection to get the address switchin function that I missed from their guide like Mital mentioned.

Patrickyp commented 6 years ago

https://www.tindie.com/products/onehorse/ultimate-sensor-fusion-solution/#product-reviews

@kriswiner would you recommend buying this as alternative to the sparkfun mpu9250? I'm thinking of trying your version to see if it works well for me.

kriswiner commented 6 years ago

This has both the MPU9250 (in a better design than that offered by Sparkfun) and the EM7180 motion co-processor. With the latter, you can read quaternions or Euler angles (yaw, pitch, roll) directly from the EM7180 via I2C register reads . It typically offers 2 degree rms heading accuracy with proper calibration as well as warm start capability; starting from power on in a previously calibrated state. It is a relatively low-power solution providing quaternion updates at the rate of the gyro up to 400 Hz guaranteed.

Compared to the Sparkfun offering, it is an astounding bargain. So yes, I would recommend it.

On Tue, May 29, 2018 at 6:53 PM, Patrickyp notifications@github.com wrote:

https://www.tindie.com/products/onehorse/ultimate-sensor-fusion-solution/# product-reviews

@kriswiner https://github.com/kriswiner would you recommend buying this as alternative to the sparkfun mpu9250? I'm thinking of trying your version to see if it works well for me.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/58#issuecomment-393004773, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qoxyGQXCG1pdS6S1Ri69KXFavKKaks5t3fufgaJpZM4H_-WG .

MitalPattani commented 6 years ago

Yes the silver coloured pads below which sj2 is written. When you desoldier it you will see 3 rectangular pads, you need to connect one on the centre and right.