Error initializing communication with IMU while using MPU 9250

Hello,
I've recently came back to arduino which I have barely touched at all due to lack of free time. I've aqquired a MPU9250 module for my project, thus I've been very keen to try it out. however after using the example given by Bolder Flight Systems InvenSense IMU (MPU9250 -> i2c) I have ran into a problem. Ive set my serial monitor to 115200 baud, just as it is given in the example code, however the only message i recieve is Error initializing communication with IMU. I have no idea how to fix this for I am a complete rookie, thus any and all help will be highly appreciated :). I will send the code I am using, together with the wiring below.

code:

/*
* Brian R Taylor
* brian.taylor@bolderflight.com
* 
* Copyright (c) 2021 Bolder Flight Systems Inc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the “Software”), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

#include "mpu9250.h"

/* Mpu9250 object */
bfs::Mpu9250 imu;

void setup() {
  /* Serial to display data */
  Serial.begin(115200);
  while(!Serial) {}
  /* Start the I2C bus */
  Wire.begin();
  Wire.setClock(400000);
  /* I2C bus,  0x68 address */
  imu.Config(&Wire, bfs::Mpu9250::I2C_ADDR_PRIM);
  /* Initialize and configure IMU */
  if (!imu.Begin()) {
    Serial.println("Error initializing communication with IMU");
    while(1) {}
  }
  /* Set the sample rate divider */
  if (!imu.ConfigSrd(19)) {
    Serial.println("Error configured SRD");
    while(1) {}
  }
}

void loop() {
  /* Check if data read */
  if (imu.Read()) {
    Serial.print(imu.new_imu_data());
    Serial.print("\t");
    Serial.print(imu.new_mag_data());
    Serial.print("\t");
    Serial.print(imu.accel_x_mps2());
    Serial.print("\t");
    Serial.print(imu.accel_y_mps2());
    Serial.print("\t");
    Serial.print(imu.accel_z_mps2());
    Serial.print("\t");
    Serial.print(imu.gyro_x_radps());
    Serial.print("\t");
    Serial.print(imu.gyro_y_radps());
    Serial.print("\t");
    Serial.print(imu.gyro_z_radps());
    Serial.print("\t");
    Serial.print(imu.mag_x_ut());
    Serial.print("\t");
    Serial.print(imu.mag_y_ut());
    Serial.print("\t");
    Serial.print(imu.mag_z_ut());
    Serial.print("\t");
    Serial.print(imu.die_temp_c());
    Serial.print("\n");
  }
}

wiring:
image_2024-01-09_193552530

Hi, do you have it hooked up correctly to SDA/SCL pins? wiring diag suggests not (if it's accurate)

update: actually noticed that those pins are also marked as D18/D19 in pinout https://docs.arduino.cc/hardware/uno-rev3. Maybe try the SDA/SCL on the other end of the board

hey, I've tried both, reconnecting the a4 and a5 pins, same as reconnecting the board to the other side of arduino uno to the designated sda and scl pins. nothing changed in both situations, still recieving Error initializing communication with IMU.

The MPU9250 is a 3.3V only device, and requires bidirectional level converters to work with 5V Arduinos. If your module doesn't have those level converters, get one like this, or use a 3.3V Arduino.

With a new I2C device, run the Arduino I2C address scanner program to verify the correct I2C address. There are two possibilities with the MPU9250.

my arduino has a 3.3V power output. cant i just use that instead?

You can certainly use the 3.3V power output, but the I/O pins work with 5V, which can cause a 3.3V sensor to malfunction or be damaged.

Most responsible manufacturers add the logic level converters, so the boards can be used with either 5V or 3.3V Arduinos.

I have risked it and changed it to 3.3V output however nothing has changed. so do you reckon i will require a level converter as you suggested? (I hope i didnt destroy th emodule in the process)

I do not "reckon". I made a professional, informed recommendation. Ignore the advice if you wish.

sorry, english is not my first language

alright then, I'll try that getting a level converter in this case, thanks but you gotta loosen up the attitude, I didnt mean to offend you :sweat_smile:

what about using the D18/D19 pins just as @anon6971307 suggested? or do they also work with 5V?

still, how come does it work for other people who are using the exact same arduino? or is it up to something else? (I am basing this on the youtube videos I've seen where other people use the exact same pin layout [yet a different code but that doesnt work for me because there's some problem with a library] but they dont have that issue [https://youtu.be/mzwovYcozvI?si=VBs1aL-LNh2IPdPF])

Sometimes it does work for a while, but no one who understands the problem follows the sort of advice you seem to prefer.

Good luck with your project.

I don't 'prefer' advice as you said it, I am simply choosing not blindly follow advice when I am seeing a different result at somebody elses case. All I am doing is questoning everything for I want to understand it. I truly dont understand from where does your passive agression is coming, all I did is ask questions, not insult you. You have to chill out a little bit, I have never had any intentions to attack you/undermine yuor knowledge on the topic

Hey,
I've been working on a project of mine and after some advice from others, I have realized that I was using wrong voltage for the MPU9250 module. In every single video I've watched people were using 5V but I've learnt today that you are actually supposed to use 3.3V for the module. Somehow the 5V works aswell but apparently not for everyone, hence I am writing this right now. Anyways, I decided to try using 3.3V pin in my arduino UNO for I didn't want to spend more money on the project. Turns out that it didn't help, I've still ran into the same problem that I've ran inb4 (talked about it in my previous post, if anyone is interested to help/add some of their advice I'll be more than glad to receive it). The only thing I am worried about is that I may have somehow damaged the module by doing so. I used a code for finding I2C address and it did say that it found the adress at 0x68 as its supposed to be. I don't know if that means nothing has been damaged or whatnot, I am a complete rookie in the subject, robotics has been a passion of mine I didn't really indulge much time into due to school. If you could let me know if that means that the module is still working fine/there is a way to check if it's still working properly I'd highly appreciate that :slight_smile:.
here's the code I've used to check the i2c address, together with the wiring.

 // --------------------------------------
//http://playground.arduino.cc/Main/I2cScanner
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// Version 6, November 27, 2015.
//    Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
// Watch Video explainign I2C address: https://www.youtube.com/watch?v=bqMMIbmYJS0
//
 
#include <Wire.h>
 
 
void setup()
{
  Wire.begin();
 
  Serial.begin(9600);
  while (!Serial);             // Leonardo: wait for serial monitor
  Serial.println("I2C Scanner");
}
 
 
void loop()
{
  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("Unknown error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found");
  else
    Serial.println("done");
 
  delay(5000);           // wait 5 seconds for next scan
} 

wiring:
image

Much appreciate it and have a great day/night :slight_smile:

@bigguygoose, please do not cross-post. Threads merged.

i have no idea how that happened tbh, i pressed new post so idk how then

Try using the Examples > Bolder Flight Systems InvenSense IMU > mpu6500 > I2C.
Worked for me considering the use case you mentioned.
Earlier I tried using mpu9250, but I was getting the same initializing error as you.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.