Mufasa951
Posts: 2
Joined: Sat Apr 13, 2013 9:19 pm

Re: Yet more MPU6050 demo code

Sat Apr 13, 2013 9:23 pm

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)

Mufasa951
Posts: 2
Joined: Sat Apr 13, 2013 9:19 pm

Re: Yet more MPU6050 demo code

Sat Apr 13, 2013 9:33 pm

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

GATTACK
Posts: 6
Joined: Sun Feb 24, 2013 8:06 pm

Re: Yet more MPU6050 demo code

Mon May 06, 2013 5:48 pm

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
Attachments
NINE_AXIS_IMU.7z
(43.61 KiB) Downloaded 971 times

GATTACK
Posts: 6
Joined: Sun Feb 24, 2013 8:06 pm

Re: Yet more MPU6050 demo code

Tue May 07, 2013 8:48 am

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

mehdroid
Posts: 7
Joined: Fri Dec 07, 2012 12:13 am

Re: Yet more MPU6050 demo code

Sun May 26, 2013 6:56 pm

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 )

GATTACK
Posts: 6
Joined: Sun Feb 24, 2013 8:06 pm

Re: Yet more MPU6050 demo code

Sun May 26, 2013 7:13 pm

Hi,

I think you need to add the following line:

sudo chmod o+rw /dev/i2c*

to the file /etc/rc.local

Glen

User avatar
joan
Posts: 15942
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Yet more MPU6050 demo code

Sun May 26, 2013 7:45 pm

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
An alternative might be to add yourself to the i2c group, i.e.

sudo adduser user-name i2c

The group change won't be in effect until the user has logged out and back in.

Autchirion
Posts: 14
Joined: Thu Mar 14, 2013 12:27 pm

Re: Yet more MPU6050 demo code

Sun Jun 30, 2013 3:24 pm

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:

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;
}
Output:
Temp_H: f0, Temp_L: 70
Temperature in Celsius: 217.567642
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.

can anybody help me what I´m doing wrong?

thx,
Auti

lawicaa
Posts: 1
Joined: Fri Jul 12, 2013 12:13 pm

Re: Yet more MPU6050 demo code

Fri Jul 12, 2013 12:17 pm

Hi,

Is Matlab code for MPU6050 available? I need it urgently.
Thank you.

Greets,
Lawica

GATTACK
Posts: 6
Joined: Sun Feb 24, 2013 8:06 pm

Re: Yet more MPU6050 demo code

Wed Jul 17, 2013 12:12 pm

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

danjperron
Posts: 3974
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Yet more MPU6050 demo code

Sat Jul 20, 2013 12:45 pm

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.
import smbus
bus = smbus.SMBus(1)
_block=bus.read_i2c_block_data(0x68,0x3b,14)
0x68= MPU6050 address
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
sudo cat /sys/module/i2c_bcm2708/parameters/baudrate
And to change the speed to 400kHz ( Until the next reboot)
sudo modprobe - r i2c_bcm2708
sudo modprobe i2c_bcm2708 baudrate=400000
If you want to change it permanently change to line in file /etc/modprobe.d/ to
options i2c_bcm2708 baudrate=400000
Daniel
Last edited by danjperron on Sat Jul 20, 2013 7:23 pm, edited 1 time in total.

NunoCardoso
Posts: 6
Joined: Fri Feb 01, 2013 9:27 pm

Re: Yet more MPU6050 demo code

Sat Jul 20, 2013 5:02 pm

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
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.

How did you solve that, Mufasa951?

roboenthus
Posts: 10
Joined: Mon Jul 15, 2013 2:07 pm

Re: Yet more MPU6050 demo code

Sat Jul 27, 2013 8:53 am

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 )
Totally the same with my Pi-B and MPU6050. Has anyone ever fixed this problem? I've set everything I can find.

User avatar
joan
Posts: 15942
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Yet more MPU6050 demo code

Sat Jul 27, 2013 12:11 pm

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.

danjperron
Posts: 3974
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Yet more MPU6050 demo code

Sat Jul 27, 2013 12:39 pm

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

roboenthus
Posts: 10
Joined: Mon Jul 15, 2013 2:07 pm

Re: Yet more MPU6050 demo code

Sun Jul 28, 2013 7:01 am

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
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.

matora88
Posts: 2
Joined: Fri Nov 08, 2013 2:13 am

Re: Yet more MPU6050 demo code

Fri Nov 08, 2013 2:18 am

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?

danjperron
Posts: 3974
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Yet more MPU6050 demo code

Fri Nov 08, 2013 12:19 pm

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

itsmrjack
Posts: 2
Joined: Mon Oct 28, 2013 9:57 pm

Re: Yet more MPU6050 demo code

Fri Nov 08, 2013 10:42 pm

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?

matora88
Posts: 2
Joined: Fri Nov 08, 2013 2:13 am

Re: Yet more MPU6050 demo code

Mon Nov 11, 2013 12:28 am

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. :)

ScomTott
Posts: 1
Joined: Tue Dec 03, 2013 12:58 am

Re: Yet more MPU6050 demo code

Tue Dec 03, 2013 1:20 am

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).

andariel
Posts: 3
Joined: Mon Dec 23, 2013 8:20 pm

Re: Yet more MPU6050 demo code

Mon Dec 23, 2013 8:47 pm

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

Megaguigui
Posts: 33
Joined: Sun Dec 08, 2013 2:11 pm

Re: Yet more MPU6050 demo code

Tue Dec 24, 2013 1:33 pm

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 ?

danjperron
Posts: 3974
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Yet more MPU6050 demo code

Tue Dec 24, 2013 1:52 pm

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

Megaguigui
Posts: 33
Joined: Sun Dec 08, 2013 2:11 pm

Re: Yet more MPU6050 demo code

Tue Dec 24, 2013 2:00 pm

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 ;)

Return to “Automation, sensing and robotics”