Problems with arduino mega 2560 and MPU 9150


I am having issues connecting my new MPU-9150 sensor ( to my arduino mega 2560. I was running the code from MPU-9150_Breakout/firmware at master · sparkfun/MPU-9150_Breakout · GitHub but having this message:

MPU6050 connection failed

Could somebody help me with the wiring and the code?
Do I need a logic level converter?
Which pins do I have to use for SDA and SDL?
What about the int signal?

Thanks in advance.

PS-MPU-9150A.pdf (3.95 MB)

mpu-9150_breakout.pdf (44.9 KB)

Please read this:

That Sparkfun code is just a copy of the i2cdevlib. Use the original library:

To make it work for the first time, try the i2c_scanner:

The I2C pins and interrupts are all on the site, you only have to find them:

Thanks for your answer.

I will get the level converter but it will take a bit. I followed the links you posted: so for the mega 20 (SDA) and 21 (SDL). The int.0 is on pin 2.

As soon as possible I will run the I2C scanner, could you tell me what should I expect from the scan?

Thank you so much for your help!

Correct, pin 20, 21 and pin 2.

The interrupt (3.3V INT signal from the sensor) can be tied to the Arduino input. It is better also using a level shifter for that, but it is not needed.

The i2c scanner only checks the addresses on the I2C bus and prints the addresses that are found. It is the most simple way to check if the I2C bus is working.

Thanks again for your answer,

why is that the level shifter for the interrupt is not needed?

When everything will be working I will send you my results.

Best regards.

The 5V Arduino Mega 2560 accepts the 3.3V INT signal as HIGH input.

Well.... in practice it will work, but according to the datasheet it barely works.

Hello again my friend.

My MPU 9150 is now working. Thank you again for your advice. Unfortunately I’m having problems with the magnetometer: the full scale of the magnetometer is ± 1200 µT. The magnetic field of the earth ranges from 25 to 65 µT. From the figure attached you can see the magnetometer is saturating which is not possible given the full scale and the magnetic field. I am storing the measures from the sensor in int16_t types and the sensor has a 13bit resolution so it should be ok. My question is: do you know what should be the conversion factor that I have to use to transform the raw output of the magnetometer to Tesla units? With the accelerometer and gyroscope it was pretty straightforward but with the magnetometer I’m not sure.

And one more question: do you know how to change the full scale of the accelerometer? I need to work with ±4g.


The range of the accelerometer is set with the AFS_SEL bits in a config register I think.

I know nothing about that magnetometer, so I can't help you with that. However, when looking at the graphs, it looks typically like a software problem with a wrong higher bit conversion. At least I can guarantee you that it is not a saturation problem. Perhaps an offset has to be set, or the conversion from the 13-bits is wrong. What do you do with the unused 3 bits ?

When the sensor is near your computer or near a monitor, it measures the magnetic field from that device, rather than the (tiny) field of the eatch magnetic field.

I was working with the sensor far from the computer. I am using the sparkfun's code because the original one is no longer available. They store the magnetometer data in a int16_t type. I was asking myself the same. I don't know what happens with the unused 3 bits.

You are right, it is not saturating. The integer from the sensor is just getting lower than -32678 and greater than 32767. So my sensor is not measuring a field with 1200 µT but something lower, I don't know how to fix it.

By the way, I developed a Kalman filter to estimate the roll and pitch angles (can't estimate the yaw due to my magnetometer problem) assuming the sensor to be static, if you want I can share the code.

Thank you for all your help