I've had trouble even getting the 6050 to be seen by the pi. I believe I've connected it correctly, and have installed/modified all the necessary files to run the i2c protocol. I tried checking with a voltmeter and confirmed that I have 3.3 V running between VCC and ground. When I run i2cdetect -y 0 or 1, I get an empty table. Has anyone else had these types of problems?
(I've also modified the code to use i2c-1 due to my board being rev 2)
Re: Yet more MPU6050 demo code
So I've connected the MPU 6050 correctly (I believe) to the Pi, enabled the i2c protocol on the Pi, and changed the existing code to work for my Rev 2 board (the code complies). However, when I run the i2cdetect -y 0 and 1 it shows that nothing is connected. I've verified that I'm getting 3.3 V to the 6050 via a voltmeter, so I'm unsure of the problem. Has anyone else had problems getting the Pi to detect that the 6050 is connected?
- Wes
- Wes
Re: Yet more MPU6050 demo code
Hi All,
Following a bit of a break, I have returned to looking at integrating the HMC5883L with the MPU6050 to provide 9DOF measurement. This time I have had success (I hope).
I have managed to edit Richard's original code and by integrating the HMC5883L libraries of Jeff Rowberg I can now successfully initialise and read the HMC5883L data in conjunction with the MPU6050 accel + gyro data.
This only works for the demo_raw application, but it is a start. I have uploaded the edited code, just follow Richard's instructions, in his original post for it to work.
Best
Glen
Following a bit of a break, I have returned to looking at integrating the HMC5883L with the MPU6050 to provide 9DOF measurement. This time I have had success (I hope).
I have managed to edit Richard's original code and by integrating the HMC5883L libraries of Jeff Rowberg I can now successfully initialise and read the HMC5883L data in conjunction with the MPU6050 accel + gyro data.
This only works for the demo_raw application, but it is a start. I have uploaded the edited code, just follow Richard's instructions, in his original post for it to work.
Best
Glen
- Attachments
-
- NINE_AXIS_IMU.7z
- (43.61 KiB) Downloaded 971 times
Re: Yet more MPU6050 demo code
Hi Wes,
I used the first part of the link below to get my IMU recognised by my Pi.
https://github.com/DavidEGrayson/minimu9-ahrs/wiki
I do not have the new version of the Pi and I changed my Debian Package to the version that David was using, although I am not sure this made any difference.
Glen
I used the first part of the link below to get my IMU recognised by my Pi.
https://github.com/DavidEGrayson/minimu9-ahrs/wiki
I do not have the new version of the Pi and I changed my Debian Package to the version that David was using, although I am not sure this made any difference.
Glen
Re: Yet more MPU6050 demo code
Hi !
I used this code in my Rpi-B but it gives this :
Initializing I2C devices...
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Testing device connections...
MPU6050 connection successful
Initializing DMP...
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
DMP Initialization failed (code 1)
and when I do i2cdetect -y 1 it gives 0x68 ( I've changed i2c-0 to i2c-1 in two files )
I used this code in my Rpi-B but it gives this :
Initializing I2C devices...
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Testing device connections...
MPU6050 connection successful
Initializing DMP...
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
DMP Initialization failed (code 1)
and when I do i2cdetect -y 1 it gives 0x68 ( I've changed i2c-0 to i2c-1 in two files )
Re: Yet more MPU6050 demo code
Hi,
I think you need to add the following line:
sudo chmod o+rw /dev/i2c*
to the file /etc/rc.local
Glen
I think you need to add the following line:
sudo chmod o+rw /dev/i2c*
to the file /etc/rc.local
Glen
Re: Yet more MPU6050 demo code
An alternative might be to add yourself to the i2c group, i.e.GATTACK wrote:Hi,
I think you need to add the following line:
sudo chmod o+rw /dev/i2c*
to the file /etc/rc.local
Glen
sudo adduser user-name i2c
The group change won't be in effect until the user has logged out and back in.
-
- Posts: 14
- Joined: Thu Mar 14, 2013 12:27 pm
Re: Yet more MPU6050 demo code
Hey,
I got my mpu6050, and I tried to get the temperature, but I get a wrong temperature. I used this as a code reference: http://mbed.org/users/Sissors/code/MPU6 ... ource.html (line 223-231).
Code:
Output:
can anybody help me what I´m doing wrong?
thx,
Auti
I got my mpu6050, and I tried to get the temperature, but I get a wrong temperature. I used this as a code reference: http://mbed.org/users/Sissors/code/MPU6 ... ource.html (line 223-231).
Code:
Code: Select all
#include <wiringPi.h>
#include <wiringPiI2C.h>
#include <stdio.h>
#define addr 0x68
#define MPU6050_RA_TEMP_OUT_H 0x41
#define MPU6050_RA_TEMP_OUT_L 0x42
//..some functions here, but shouln´t be neccesary to know them ;-)
int main (void)
{
int fd=Setup_MPU6050();
int Temp_H, Temp_L, Temp_raw;
float Temp_C;
Temp_H = wiringPiI2CReadReg8(fd, MPU6050_RA_TEMP_OUT_H);
Temp_L = wiringPiI2CReadReg8(fd, MPU6050_RA_TEMP_OUT_L);
printf("Temp_H: %x, Temp_L: %x\n", Temp_H, Temp_L);
Temp_H=Temp_H<<8;
Temp_raw=Temp_H+Temp_L;
Temp_C=((float)Temp_raw+521.0f)/(340.0f)+35.0f;
printf("Temperature in Celsius: %f \n",Temp_C);
return 0;
}
That Output is wrong, when I run ./mpu-6050-gettemp of (from: http://www.bitwizard.nl/wiki/index.php/ ... spberry_Pi) I get 24.803°C wich looks realy good.Temp_H: f0, Temp_L: 70
Temperature in Celsius: 217.567642
can anybody help me what I´m doing wrong?
thx,
Auti
Re: Yet more MPU6050 demo code
Hi,
Is Matlab code for MPU6050 available? I need it urgently.
Thank you.
Greets,
Lawica
Is Matlab code for MPU6050 available? I need it urgently.
Thank you.
Greets,
Lawica
Re: Yet more MPU6050 demo code
Hi,
Have you looked at the MATLAB support package for the PI?
I have downloaded it but cannot import the data into Simulink - although others have successfully managed it with Arduino using the S-Function Builder. The difficulty is getting Simulink to accept .cpp files - see link below:
https://www.mathworks.co.uk/matlabcentr ... ce-drivers
Glen
Have you looked at the MATLAB support package for the PI?
I have downloaded it but cannot import the data into Simulink - although others have successfully managed it with Arduino using the S-Function Builder. The difficulty is getting Simulink to accept .cpp files - see link below:
https://www.mathworks.co.uk/matlabcentr ... ce-drivers
Glen
-
- Posts: 3974
- Joined: Thu Dec 27, 2012 4:05 am
- Location: Québec, Canada
Re: Yet more MPU6050 demo code
I just finished a egg crash accelerator sensor using the MPU6050.
I find out that you could increase, by a lot, the sampling speed if you read multiple bytes at once.
Too bad that the wiring pi i2c module only read byte and word ;-(
But if you use the python-smbus module, you could read up to 31 bytes at once.
0x3b= First register address to read
14= 14 registers to read ( 3 accelerators, 1 temperature and 3 gyroscopes)
This will transfer all accelerator, gyroscope and temperature in one command.
And now you are just limited by the bus speed but you could change the speed.
To read the I2c speed use this command
I find out that you could increase, by a lot, the sampling speed if you read multiple bytes at once.
Too bad that the wiring pi i2c module only read byte and word ;-(
But if you use the python-smbus module, you could read up to 31 bytes at once.
0x68= MPU6050 addressimport smbus
bus = smbus.SMBus(1)
_block=bus.read_i2c_block_data(0x68,0x3b,14)
0x3b= First register address to read
14= 14 registers to read ( 3 accelerators, 1 temperature and 3 gyroscopes)
This will transfer all accelerator, gyroscope and temperature in one command.
And now you are just limited by the bus speed but you could change the speed.
To read the I2c speed use this command
And to change the speed to 400kHz ( Until the next reboot)sudo cat /sys/module/i2c_bcm2708/parameters/baudrate
If you want to change it permanently change to line in file /etc/modprobe.d/ tosudo modprobe - r i2c_bcm2708
sudo modprobe i2c_bcm2708 baudrate=400000
Danieloptions i2c_bcm2708 baudrate=400000
Last edited by danjperron on Sat Jul 20, 2013 7:23 pm, edited 1 time in total.
-
- Posts: 6
- Joined: Fri Feb 01, 2013 9:27 pm
Re: Yet more MPU6050 demo code
I am having the same problem. I followed the instructions correctly, and i2cdetect -y 0 and 1 it shows that nothing is connected. I have a HMC5883L connected, but can't detect it.Mufasa951 wrote:So I've connected the MPU 6050 correctly (I believe) to the Pi, enabled the i2c protocol on the Pi, and changed the existing code to work for my Rev 2 board (the code complies). However, when I run the i2cdetect -y 0 and 1 it shows that nothing is connected. I've verified that I'm getting 3.3 V to the 6050 via a voltmeter, so I'm unsure of the problem. Has anyone else had problems getting the Pi to detect that the 6050 is connected?
- Wes
How did you solve that, Mufasa951?
-
- Posts: 10
- Joined: Mon Jul 15, 2013 2:07 pm
Re: Yet more MPU6050 demo code
Totally the same with my Pi-B and MPU6050. Has anyone ever fixed this problem? I've set everything I can find.mehdroid wrote:Hi !
I used this code in my Rpi-B but it gives this :
Initializing I2C devices...
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Testing device connections...
MPU6050 connection successful
Initializing DMP...
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
Failed to write device(-1): Input/output error
DMP Initialization failed (code 1)
and when I do i2cdetect -y 1 it gives 0x68 ( I've changed i2c-0 to i2c-1 in two files )
Re: Yet more MPU6050 demo code
Check the connections. They may be loose or incorrect. There is no point in trying your own software until it can be seen by i2cdetect.
-
- Posts: 3974
- Joined: Thu Dec 27, 2012 4:05 am
- Location: Québec, Canada
Re: Yet more MPU6050 demo code
Joan is correct,
first check already made code first.
I give some resource on that post http://www.raspberrypi.org/phpBB3/viewt ... 93#p393993
And also the basic question,
When you power up the MPU6050, did you wait? It takes quite some times to settle?
Do you use 3.3V at the device VCC and is your ground connected?
Is AD0 grounded also? If it's not the device address will switch from 0x68 to 0x69 at will.
Did you add pull up resistor. If yes , you don't need them since the RPi already has some.
Is it the only device on the I2C?
Did you change the smbus speed?
Did you remove the i2c driver from the blacklist?
Daniel
first check already made code first.
I give some resource on that post http://www.raspberrypi.org/phpBB3/viewt ... 93#p393993
And also the basic question,
When you power up the MPU6050, did you wait? It takes quite some times to settle?
Do you use 3.3V at the device VCC and is your ground connected?
Is AD0 grounded also? If it's not the device address will switch from 0x68 to 0x69 at will.
Did you add pull up resistor. If yes , you don't need them since the RPi already has some.
Is it the only device on the I2C?
Did you change the smbus speed?
Did you remove the i2c driver from the blacklist?
Daniel
-
- Posts: 10
- Joined: Mon Jul 15, 2013 2:07 pm
Re: Yet more MPU6050 demo code
Thank you, and I have checked all these. The situation now is that I get nothing but the 0x68 given by i2cdetect, and when I link AD0 to ground, the address does not change. Maybe the last thing I can try is to get a new one.danjperron wrote:Joan is correct,
first check already made code first.
I give some resource on that post http://www.raspberrypi.org/phpBB3/viewt ... 93#p393993
And also the basic question,
When you power up the MPU6050, did you wait? It takes quite some times to settle?
Do you use 3.3V at the device VCC and is your ground connected?
Is AD0 grounded also? If it's not the device address will switch from 0x68 to 0x69 at will.
Did you add pull up resistor. If yes , you don't need them since the RPi already has some.
Is it the only device on the I2C?
Did you change the smbus speed?
Did you remove the i2c driver from the blacklist?
Daniel
Re: Yet more MPU6050 demo code
i can't make my mpu6050 working. Can someone help me on how to modified i2c class to use with linux in-kernal i2c driver rather than arduino?
-
- Posts: 3974
- Joined: Thu Dec 27, 2012 4:05 am
- Location: Québec, Canada
Re: Yet more MPU6050 demo code
Hi Matora88,
We will need more info to help you
1 - What revision is your RaspberryPi. ( I2c0 and i2c1 problem).
2 - Explain what you have . How you connect it?. What kind of MPU6050 ?
3 - I2c Class ? in what Python, c, c++ .
4- Are you running raspbian?
Did you install the i2c_bcm2708 driver module (check previous post)
did you check if your device is detected ?
i2cdetect -y 0 or
i2cdetect -y 1 (Revision 2)
Daniel
We will need more info to help you
1 - What revision is your RaspberryPi. ( I2c0 and i2c1 problem).
2 - Explain what you have . How you connect it?. What kind of MPU6050 ?
3 - I2c Class ? in what Python, c, c++ .
4- Are you running raspbian?
Did you install the i2c_bcm2708 driver module (check previous post)
did you check if your device is detected ?
i2cdetect -y 0 or
i2cdetect -y 1 (Revision 2)
Daniel
Re: Yet more MPU6050 demo code
Hi folks,
A bit stuck here
I'm pretty fresh to Rpi, linux and generally working from command line so please go slow
I have the MPU6050-Pi-Demo.005.tgz demo tarball unpacked and "make"ed.
I have libgtkmm-3.0-dev installed fine.
I have changed "/dev/i2c-0" to "/dev/i2c-1" in both I2Cdev.cpp and setup-i2c.sh ...and then run setup-i2c.sh.
I checked with i2cdetect -y 1 (I'm on a revision 2.0 board) and seen that the device address is 0x68 and checked MPU6050.h to see that indeed it is set as such.
So... when I run demo_3d I get same errors as roboenthus above:
"...
Failed to write device(-1): Input/output error
Failed to write reg: Input/output error
DMP Initialization failed (code 1)
..."
What on earth is wrong?
By the by, I have the MPU-6050 board (Sparkfun breakout version) connected to the Rpi (model B revision 2) like this:
VDD to Rpi 3v3 (pin 1)
GND to Rpi Ground (pin 9)
SCL to Rpi SCL (pin 5)
SDA to Rpi SDA (pin 3)
VIO to Rpi 3v3 (pin 17)
Cheers in advance
EDIT: using the code here http://www.bitwizard.nl/wiki/index.php/ ... spberry_Pi I can read raw sensor values absolutely fine. Do I need something else to get the MPU-6050-Pi-Demo package running?
A bit stuck here

I'm pretty fresh to Rpi, linux and generally working from command line so please go slow

I have the MPU6050-Pi-Demo.005.tgz demo tarball unpacked and "make"ed.
I have libgtkmm-3.0-dev installed fine.
I have changed "/dev/i2c-0" to "/dev/i2c-1" in both I2Cdev.cpp and setup-i2c.sh ...and then run setup-i2c.sh.
I checked with i2cdetect -y 1 (I'm on a revision 2.0 board) and seen that the device address is 0x68 and checked MPU6050.h to see that indeed it is set as such.
So... when I run demo_3d I get same errors as roboenthus above:
"...
Failed to write device(-1): Input/output error
Failed to write reg: Input/output error
DMP Initialization failed (code 1)
..."
What on earth is wrong?
By the by, I have the MPU-6050 board (Sparkfun breakout version) connected to the Rpi (model B revision 2) like this:
VDD to Rpi 3v3 (pin 1)
GND to Rpi Ground (pin 9)
SCL to Rpi SCL (pin 5)
SDA to Rpi SDA (pin 3)
VIO to Rpi 3v3 (pin 17)
Cheers in advance

EDIT: using the code here http://www.bitwizard.nl/wiki/index.php/ ... spberry_Pi I can read raw sensor values absolutely fine. Do I need something else to get the MPU-6050-Pi-Demo package running?
Re: Yet more MPU6050 demo code
danjperron wrote:Hi Matora88,
We will need more info to help you
1 - What revision is your RaspberryPi. ( I2c0 and i2c1 problem).
2 - Explain what you have . How you connect it?. What kind of MPU6050 ?
3 - I2c Class ? in what Python, c, c++ .
4- Are you running raspbian?
Did you install the i2c_bcm2708 driver module (check previous post)
did you check if your device is detected ?
i2cdetect -y 0 or
i2cdetect -y 1 (Revision 2)
Daniel
Hi Daniel,
I have found the solution posted by itsmrjack. Thanks for the reply.

Re: Yet more MPU6050 demo code
I am having problems reading or writing to my MPU6050 (GY-521 breakout board).
Doing i2cdetect on I2C bus 1 results in a device being found at address 0x68.
But any attempt to i2cget or i2cset results in either "Error: Read failed" or "Error: Write failed".
i2cdump gives almost every register as containing XX except 0x11 and 0x91 which both contain the value 0x0f.
I've tried both grounding and not grounding AD0 and it doesn't make any difference - the device remains at 0x68. The same happens if I disconnect VCC, a device is still detected at 0x68 - I don't understand how this can be so if the device is unpowered.
I'm beginning to think I may have a dodgy sensor board - any suggestions?
Things I've already tried:
I have a Rev 2 board so I've changed the /dev/i2c-0 to /dev/i2c-1 in three places in I2CDev.cpp, installed i2c-tools (obviously), I've added the user pi to the group i2c, I've added i2c-bcm2708 and i2c-dev to /etc/modules and commented out the two blacklist entries for i2c.
Pin Layout
MPU RPi
VCC >> Pin 1 3.3V
SDA >> Pin 3 SDA
SCL >> Pin 5 SCL
GND >> Pin 6 GND
AD0 >> Pin 9 GND (tried with this connected and disconnected).
Doing i2cdetect on I2C bus 1 results in a device being found at address 0x68.
But any attempt to i2cget or i2cset results in either "Error: Read failed" or "Error: Write failed".
i2cdump gives almost every register as containing XX except 0x11 and 0x91 which both contain the value 0x0f.
I've tried both grounding and not grounding AD0 and it doesn't make any difference - the device remains at 0x68. The same happens if I disconnect VCC, a device is still detected at 0x68 - I don't understand how this can be so if the device is unpowered.
I'm beginning to think I may have a dodgy sensor board - any suggestions?
Things I've already tried:
I have a Rev 2 board so I've changed the /dev/i2c-0 to /dev/i2c-1 in three places in I2CDev.cpp, installed i2c-tools (obviously), I've added the user pi to the group i2c, I've added i2c-bcm2708 and i2c-dev to /etc/modules and commented out the two blacklist entries for i2c.
Pin Layout
MPU RPi
VCC >> Pin 1 3.3V
SDA >> Pin 3 SDA
SCL >> Pin 5 SCL
GND >> Pin 6 GND
AD0 >> Pin 9 GND (tried with this connected and disconnected).
Re: Yet more MPU6050 demo code
Hi all!
I´m new RPi user and I get work demo_raw.
But I have problem tu run demo_dmp . I´m sure the problem cause the connection on my layout.
I have INT0 connectet to GPIO24 (pin 18). (on PCB)
Please can somebody tell me how can I change code to work with GPIO24?
I will be very happy for any tutorial becouse I´m total beginer with RPi.
Have nice Christmas!
Thanks
Peter
I´m new RPi user and I get work demo_raw.
But I have problem tu run demo_dmp . I´m sure the problem cause the connection on my layout.
I have INT0 connectet to GPIO24 (pin 18). (on PCB)
Please can somebody tell me how can I change code to work with GPIO24?
I will be very happy for any tutorial becouse I´m total beginer with RPi.
Have nice Christmas!
Thanks
Peter
-
- Posts: 33
- Joined: Sun Dec 08, 2013 2:11 pm
Re: Yet more MPU6050 demo code
Hello !
I try to use the MPU 6050 on a C programm,but here it using the C++ ...
The MPU6050 is detect and i can read a value so it's working but I can't find a command to attribute to a variable the values of MPU ...
Someone know how to get acceleration and rotation (temperature also) in a C program please ?
I try to use the MPU 6050 on a C programm,but here it using the C++ ...
The MPU6050 is detect and i can read a value so it's working but I can't find a command to attribute to a variable the values of MPU ...
Someone know how to get acceleration and rotation (temperature also) in a C program please ?
-
- Posts: 3974
- Joined: Thu Dec 27, 2012 4:05 am
- Location: Québec, Canada
Re: Yet more MPU6050 demo code
Hi Megaguigui,
I can't help you directly but I do have some I2C wrapper I did for my A/D converter project
Check this github
https://github.com/danjperron/A2D_PIC_RPI
I did a small PIC processor using the MPU6050 .
https://github.com/danjperron/GCrash
So if your problem is the I2C interface use my wrapper in the first github. And if it is how to read the register check my second github.
Daniel
I can't help you directly but I do have some I2C wrapper I did for my A/D converter project
Check this github
https://github.com/danjperron/A2D_PIC_RPI
I did a small PIC processor using the MPU6050 .
https://github.com/danjperron/GCrash
So if your problem is the I2C interface use my wrapper in the first github. And if it is how to read the register check my second github.
Daniel
-
- Posts: 33
- Joined: Sun Dec 08, 2013 2:11 pm
Re: Yet more MPU6050 demo code
Hi Daniel.
My problem is not i2c,it's working without any problem
I just want know how to make something like :
acceleration_top_bottom=getaccelerationX();
Where acceleration_top_bottom is a variable and getaccelerationX(); the command in C.
Here,I need the C command which exist
My problem is not i2c,it's working without any problem

I just want know how to make something like :
acceleration_top_bottom=getaccelerationX();
Where acceleration_top_bottom is a variable and getaccelerationX(); the command in C.
Here,I need the C command which exist
