Go Down

Topic: MPU6050 + arduino nano + raw data over serial (Read 8 times) previous topic - next topic

augustinoy

ok, I'm doing a small proyect, the basic idea it's to use the arduino as a sensor base to communicate the data from 10 buttons and the MPU6050 over bluetooth to my computer and process that data on puredata. any way, I've already manage to connect over USB (the bluetooth part it's easy, I just connect the dongle on the comport TX and RX and everithing will go wireless) and transmit as many buttons I want, but with the MPU6050 I can't doit. I've connected it to the I2C port (digital 4 and 5), I loaded the code on http://arduino.cc/playground/Main/MPU-6050 to test it and the board canĀ“t connect at all, no data recived. I've also tryed the Jeff Rowberg Code for I2C using the Wire.h library, no luck there, I'm kind of lost, does anyone have any idea how to continue from here? I can't find any resource and actually, I'm too noob to understand the I2C protocol, It's like chinese to me. So, any help would be great. Thanks!

lesto

are you sure to use the right I2C address? there are some skect that "portscan" every I2C address, if your MPU6050 won't show up then probabily is broken, or you are making confusion with internal/external pullup, or the I2C level (5v and ?v) aren't compatible
sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

MarkT

Quote
I've connected it to the I2C port (digital 4 and 5),


Then you've done it wrong, SDA is A4, SCL is A5 (not digital 4/5) and you _must_ use 4.7k pull-up resistors on both those pins.  If the device is 3.3V (which I believe it is) the pull-ups _must_ go to +3.3V, not 5V.
[ I won't respond to messages, use the forum please ]

lesto

no, if you use pul-up it wont work until you disable the inetrnal pull-up of atmega (file twi.h of library wire)
sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

augustinoy


Quote
I've connected it to the I2C port (digital 4 and 5),


Then you've done it wrong, SDA is A4, SCL is A5 (not digital 4/5) and you _must_ use 4.7k pull-up resistors on both those pins.  If the device is 3.3V (which I believe it is) the pull-ups _must_ go to +3.3V, not 5V.


You are right, I was connecting it to A not D, my bad.


are you sure to use the right I2C address? there are some skect that "portscan" every I2C address, if your MPU6050 won't show up then probabily is broken, or you are making confusion with internal/external pullup, or the I2C level (5v and ?v) aren't compatible


actually i'm not sure at all, I'm searching in the forum for that kind of sketches but I can't find one, can you give me a link pleas? thanks.

lesto

http://omarfrancisco.com/i2c-bus-scanner/

http://todbot.com/blog/2009/11/29/i2cscanner-pde-arduino-as-i2c-bus-scanner/

just the 2 first link of google for keyword "i2c scanner arduino"  :smiley-mr-green:
sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

augustinoy

Thanks! but does code don't really work as they are, the libs have been updated. If anyone needs it now should be something like this

Quote
/**
* I2CScanner.pde -- I2C bus scanner for Arduino
*
* 2009, Tod E. Kurt, http://todbot.com/blog/
*
*/

#include "Wire.h"
extern "C" {
#include "utility/twi.h"  // from Wire library, so we can do bus scanning
}

// Scan the I2C bus between addresses from_addr and to_addr.
// On each address, call the callback function with the address and result.
// If result==0, address was found, otherwise, address wasn't found
// (can use result to potentially get other status on the I2C bus, see twi.c)
// Assumes Wire.begin() has already been called
void scanI2CBus(byte from_addr, byte to_addr,
                void(*callback)(byte address, byte result) )
{
  byte rc;
  byte data = 0; // not used, just an address to feed to twi_writeTo()
  for( byte addr = from_addr; addr <= to_addr; addr++ ) {
    rc = twi_writeTo(addr, &data, 0, 1, 0);
    callback( addr, rc );
  }
}

// Called when address is found in scanI2CBus()
// Feel free to change this as needed
// (like adding I2C comm code to figure out what kind of I2C device is there)
void scanFunc( byte addr, byte result ) {
  Serial.print("addr: ");
  Serial.print(addr,DEC);
  Serial.print( (result==0) ? " found!":"       ");
  Serial.print( (addr%4) ? "\t":"\n");
}


byte start_address = 1;
byte end_address = 200;

// standard Arduino setup()
void setup()
{
    Wire.begin();

    Serial.begin(19200);
    Serial.println("\nI2CScanner ready!");

    Serial.print("starting scanning of I2C bus from ");
    Serial.print(start_address,DEC);
    Serial.print(" to ");
    Serial.print(end_address,DEC);
    Serial.println("...");

    // start the scan, will call "scanFunc()" on result from each address
    scanI2CBus( start_address, end_address, scanFunc );

    Serial.println("\ndone");
}

// standard Arduino loop()
void loop()
{
    // Nothing to do here, so we'll just blink the built-in LED
    digitalWrite(13,HIGH);
    delay(300);
    digitalWrite(13,LOW);
    delay(300);
}


it works for me this way.

Krodal

#7
Jun 26, 2012, 05:57 pm Last Edit: Jun 26, 2012, 05:59 pm by Krodal Reason: 1
I wrote the page http://arduino.cc/playground/Main/MPU-6050 and it should provide you with a sketch that runs without problem.

You have to get a I2C connection of course.
Do you use a board with the MPU-6050? Which one ? Some have a voltage regulator on board. The board I used also has the right pull-up and pull-down resistors, so I only had to use the power supply and the I2C-bus.

I used code by user RandallR for scanning. See here: http://arduino.cc/forum/index.php?topic=96952.0

About the power supply. The MPU-6050 needs 3.3V (if there is no regulator on the MPU-6050 board). Pull-up registers of 4k7 can be used to pull-up to the 3.3V. Can you upload a photo perhaps ? So we know what and how you are using it ?

augustinoy

#8
Jun 26, 2012, 07:49 pm Last Edit: Jun 26, 2012, 07:55 pm by augustinoy Reason: 1
Ok, I've tried that, I changed in the sketch #define MPU6050_I2C_ADDRESS 0x68 to #define MPU6050_I2C_ADDRESS 0x69 and it seems to kind of start working hahahahaha.

the serial port read its
Quote
InvenSense MPU-6050
June 2012
WHO_AM_I : 68, error = 0
PWR_MGMT_2 : 0, error = 0

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 368, -44, -12616
temperature: 23.329 degrees Celsius
gyro x,y,z : -176, -63, 31,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 380, 516, -13460
temperature: 23.424 degrees Celsius
gyro x,y,z : -196, -84, 1,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 520, 260, -12556
temperature: 23.376 degrees Celsius
gyro x,y,z : -174, -46, 45,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 644, 432, -13304
temperature: 23.424 degrees Celsius
gyro x,y,z : -175, 23, 27,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 600, 340, -12400
temperature: 23.471 degrees Celsius
gyro x,y,z : -135, -22, 77,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 796, 264, -12840
temperature: 23.565 degrees Celsius
gyro x,y,z : -164, -61, 54,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 4, -484, -12364
temperature: 23.424 degrees Celsius
gyro x,y,z : -206, -15, -27,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 804, 320, -12464
temperature: 23.424 degrees Celsius
gyro x,y,z : -145, 12, 83,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 592, 444, -12892
temperature: 23.518 degrees Celsius
gyro x,y,z : -196, 17, 86,


I think it's working because if I put my finger over the board the temperature rises smoothly, and goes back when I take out the finger.
About the accel and gyro data, I really don't get it, it's confusing. Anyway, now I get some data, I'ts a lot better :D

anyway This board seems to have the voltage regulator but hasn't the pullup pulldown resistors, I added that and the I2C scan port sketch gave me the address.

Thanks for all the help!!!!!!

I just need to have some real readings now.


========================================EDIT============================================
Ignore this picture, I've attached the wrong one, look the next post.

augustinoy

Sorry, I attached the wrong photo there, this is the one!!!!!

Krodal

#10
Jun 26, 2012, 10:03 pm Last Edit: Jun 26, 2012, 10:46 pm by Krodal Reason: 1
So this is your board with sensor: http://www.drotek.fr/shop/en/42-mpu6050-gyro-accelerometer.html
That page also shows how to use it. It has a voltage regulator on the board.
Connect the 5V of the sensor board to the 5V of the arduino.
The 3.3V of the sensor board is an output, don't use it.

I'm pretty sure that the two black 10k resistors on the sensor board are pull-up resistors for the I2C bus, but 4K7 is better to avoid problems with the internal pull-up resistors of the Arduino (the internal pull-up resistors pull the signal to 5V, see: http://arduino.cc/playground/Main/I2CBi-directionalLevelShifter ), so you could add two extra 10k pull-up resistors to 3.3V (The 3.3V of the Arduino, or the 3.3V output of the sensor board). It looks as if you have already those 10k pull-up resistors.

The page at drotek says: I2C address: 0x69
So they have a pull-up on the address pin, mine had a pull-down. I will change my page with the example sketch.

Now for your values:
error = 0 : good, i2c communication is okay.
temperature : good
acceleration values : good, the module is upside down, so the z-axis is negative (-1 g)
gyro : I think they are also good.

Here are my values (raw values, not calibrated, no offset compensation).
My MPU-6050 sensor is in normal position, with the z-axis pointing up.
Code: [Select]

InvenSense MPU-6050
June 2012
WHO_AM_I : 68, error = 0
PWR_MGMT_2 : 0, error = 0

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: -384, -284, 15236
temperature: 27.706 degrees Celsius
gyro x,y,z : 394, 201, -806,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: -312, -356, 15232
temperature: 27.706 degrees Celsius
gyro x,y,z : 386, 205, -818,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: -468, -392, 15192
temperature: 27.847 degrees Celsius
gyro x,y,z : 387, 197, -794,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: -380, -380, 15256
temperature: 27.659 degrees Celsius
gyro x,y,z : 388, 209, -808,


If you rotate and move the sensor, you should see the values change.

You are doing fine so far.

augustinoy

You where right, I took out the 3.3v and works fine but I need the pullup resistors, if I take them away stops communicating.
Ok, so it's working, but why the values are so erratic?
the temperature reading looks kind of stable, but I leave the board steady on the table and the values change dramatically.

Code: [Select]
InvenSense MPU-6050
June 2012
WHO_AM_I : 68, error = 0
PWR_MGMT_2 : 0, error = 0

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 192, 60, -13372
temperature: 23.518 degrees Celsius
gyro x,y,z : -144, -25, 22,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 64, 112, -13100
temperature: 23.612 degrees Celsius
gyro x,y,z : -181, 26, 25,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 884, 76, -12336
temperature: 23.565 degrees Celsius
gyro x,y,z : -121, -24, 51,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 712, 404, -12368
temperature: 23.565 degrees Celsius
gyro x,y,z : -186, -21, 35,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: -248, 368, -12872
temperature: 23.706 degrees Celsius
gyro x,y,z : -166, -105, 119,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 704, 440, -12892
temperature: 23.612 degrees Celsius
gyro x,y,z : -248, 1, 31,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 308, 208, -12716
temperature: 23.706 degrees Celsius
gyro x,y,z : -147, -89, 88,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 1148, 380, -12952
temperature: 23.612 degrees Celsius
gyro x,y,z : -160, -16, 93,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 8, 528, -12676
temperature: 23.518 degrees Celsius
gyro x,y,z : -168, -5, 92,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: -436, -52, -12948
temperature: 23.612 degrees Celsius
gyro x,y,z : -169, 90, 56,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 516, -508, -12976
temperature: 23.612 degrees Celsius
gyro x,y,z : -176, -61, -14,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 456, 672, -13008
temperature: 23.565 degrees Celsius
gyro x,y,z : -103, 11, 95,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 776, 704, -12880
temperature: 23.612 degrees Celsius
gyro x,y,z : -268, -41, 114,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 212, -92, -12772
temperature: 23.565 degrees Celsius
gyro x,y,z : -169, -21, -59,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 712, -616, -12652
temperature: 23.612 degrees Celsius
gyro x,y,z : -202, -41, 87,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 652, -276, -12596
temperature: 23.659 degrees Celsius
gyro x,y,z : -152, 15, 55,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 28, 164, -13212
temperature: 23.565 degrees Celsius
gyro x,y,z : -233, -84, 75,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 216, 92, -13024
temperature: 23.518 degrees Celsius
gyro x,y,z : -198, 24, 26,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 612, 244, -13552
temperature: 23.471 degrees Celsius
gyro x,y,z : -191, -65, -11,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 552, -464, -13216
temperature: 23.518 degrees Celsius
gyro x,y,z : -167, -3, 12,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 280, 88, -13088
temperature: 23.659 degrees Celsius
gyro x,y,z : -196, -95, 10,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: -176, 72, -12884
temperature: 23.612 degrees Celsius
gyro x,y,z : -171, -219, -13,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 216, -284, -13324
temperature: 23.565 degrees Celsius
gyro x,y,z : -153, 145, 3,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 500, -524, -13360
temperature: 23.612 degrees Celsius
gyro x,y,z : -247, -140, 85,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 552, 272, -13832
temperature: 23.612 degrees Celsius
gyro x,y,z : -198, 76, 28,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 676, 12, -13336
temperature: 23.659 degrees Celsius
gyro x,y,z : -176, 28, 37,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 816, -408, -13080
temperature: 23.659 degrees Celsius
gyro x,y,z : -150, 3, 64,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: -224, -104, -12812
temperature: 23.659 degrees Celsius
gyro x,y,z : -201, 32, 55,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 368, 360, -13316
temperature: 23.753 degrees Celsius
gyro x,y,z : -205, -43, -8,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 100, 756, -13448
temperature: 23.471 degrees Celsius
gyro x,y,z : -135, 12, 52,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 332, -188, -13100
temperature: 23.565 degrees Celsius
gyro x,y,z : -157, -68, 48,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 904, 708, -13120
temperature: 23.706 degrees Celsius
gyro x,y,z : -123, 1, 45,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 600, -372, -12800
temperature: 23.706 degrees Celsius
gyro x,y,z : -134, 17, -18,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 1072, 724, -13252
temperature: 23.565 degrees Celsius
gyro x,y,z : -213, -32, -7,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: -336, -48, -12972
temperature: 23.659 degrees Celsius
gyro x,y,z : -146, 2, -49,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 292, 392, -13152
temperature: 23.518 degrees Celsius
gyro x,y,z : -212, -169, 106,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 116, -504, -12388
temperature: 23.612 degrees Celsius
gyro x,y,z : -188, 51, 38,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 304, 116, -12740
temperature: 23.706 degrees Celsius
gyro x,y,z : -150, 42, 40,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 344, -424, -13104
temperature: 23.471 degrees Celsius
gyro x,y,z : -178, -30, 56,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 472, 800, -13340
temperature: 23.659 degrees Celsius
gyro x,y,z : -203, 10, 27,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 524, 192, -12968
temperature: 23.706 degrees Celsius
gyro x,y,z : -247, -98, -24,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 752, 448, -12528
temperature: 23.659 degrees Celsius
gyro x,y,z : -194, 140, 8,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 644, -380, -12412
temperature: 23.753 degrees Celsius
gyro x,y,z : -147, -95, -9,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 424, 136, -12596
temperature: 23.518 degrees Celsius
gyro x,y,z : -216, -13, 16,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 636, -292, -12532
temperature: 23.565 degrees Celsius
gyro x,y,z : -212, 20, 43,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 296, 512, -12968
temperature: 23.706 degrees Celsius
gyro x,y,z : -188, 20, 130,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 520, 500, -13472
temperature: 23.706 degrees Celsius
gyro x,y,z : -231, -38, 8,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 396, 224, -13188
temperature: 23.706 degrees Celsius
gyro x,y,z : -137, 71, 12,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 612, -304, -13568
temperature: 23.659 degrees Celsius
gyro x,y,z : -199, 34, 61,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: 332, -144, -13404
temperature: 23.612 degrees Celsius
gyro x,y,z : -104, 31, 87,


I really can't see a relation between them.
If I move the board I can't either see a pattern between the movement and the numbers.

Anyway Krodal, You helped a lot! Thanks!!!!! in that page it says that the I2C address is 0x69. Anyway, I've learned a lot finding it out by myself.

Krodal

The values change a lot, but it's not dramatically. The values are 16-bit, and they should be filtered/averaged.

If I put it on the same table of my computer, the vibration of my computer is measured.
So I place it on the floor for (a little) better readings.
You could rotate the board in all directions, and see what the acceleration values do.
The gyro is harder to recognize, but they will change if you move the board upward or sideward.

For proper I2C communication a level shifter could be used: http://arduino.cc/playground/Main/I2CBi-directionalLevelShifter
But just two resistors of 4k7 to the 3.3V will do fine, the Arduino will read the 3.3V as a logical '1'.
The 10k on the sensor board is probably just a little too much outside the specs.

augustinoy

IT'S ALIVE!!!!!!!!!!!!!!!!!!!!

I thinks it's working, and to keep a good feed of data I think I will decode and filter/average directly on puredata.
Which it's the range of values of the gyro and accel? if it's in 16 bits, one bit for the sign and number between -32767 and 32767????
it's that even close?

Krodal

IT'S ALIVE!!!!!!!!!!!!!!!!!!!!

Congratulations!

Which it's the range of values of the gyro and accel? if it's in 16 bits, one bit for the sign and number between -32767 and 32767

Yes, that is the range.
You have to study the datasheet(s) for the sensitivity and the digital low-pass and high-pass filter.

Go Up