Go Down

Topic: Problem with MPU-9255 and the 10 DOF IMU Sensor (Read 844 times) previous topic - next topic

PEKANO

So I aquired recently a 10 DOF IMU Sensor like this one : http://www.waveshare.com/10-dof-imu-sensor-b.htm

So I tried to set it up for like 5 hours but I can't resolve my problems.

The gyro is currently pluged  like that :

VCC in 5V
GND in GND
SDA in SDA
SCL in SCL


I used this code but i don't know if it works


Code: [Select]


#include <Wire.h>

#define    MPU9250_ADDRESS            0x68
#define    MAG_ADDRESS                0x0C

#define    GYRO_FULL_SCALE_250_DPS    0x00 
#define    GYRO_FULL_SCALE_500_DPS    0x08
#define    GYRO_FULL_SCALE_1000_DPS   0x10
#define    GYRO_FULL_SCALE_2000_DPS   0x18

#define    ACC_FULL_SCALE_2_G        0x00 
#define    ACC_FULL_SCALE_4_G        0x08
#define    ACC_FULL_SCALE_8_G        0x10
#define    ACC_FULL_SCALE_16_G       0x18



// This function read Nbytes bytes from I2C device at address Address.
// Put read bytes starting at register Register in the Data array.
void I2Cread(uint8_t Address, uint8_t Register, uint8_t Nbytes, uint8_t* Data)
{
  // Set register address
  Wire.beginTransmission(Address);
  Wire.write(Register);
  Wire.endTransmission();
 if(Register == 0x02){
   Serial.println("Data Not Ready");
 }
  // Read Nbytes
  Wire.requestFrom(Address, Nbytes);
  uint8_t index=0;
  while (Wire.available())
    Data[index++]=Wire.read();
  Serial.println("Data: " + *Data);
}


// Write a byte (Data) in device (Address) at register (Register)
void I2CwriteByte(uint8_t Address, uint8_t Register, uint8_t Data)
{
  // Set register address
  Wire.beginTransmission(Address);
  Wire.write(Register);
  Wire.write(Data);
  Wire.endTransmission();
}


// Initializations
void setup()
{
  // Arduino initializations
  Wire.begin();
  Serial.begin(115200);

  // Configure gyroscope range
  I2CwriteByte(MPU9250_ADDRESS,27,GYRO_FULL_SCALE_2000_DPS);
  // Configure accelerometers range
  I2CwriteByte(MPU9250_ADDRESS,28,ACC_FULL_SCALE_16_G);
  // Set by pass mode for the magnetometers
  I2CwriteByte(MPU9250_ADDRESS,0x37,0x02);

  // Request first magnetometer single measurement
  I2CwriteByte(MAG_ADDRESS,0x0A,0x01);


}


long int cpt=0;
// Main loop, read and display data
void loop()
{

  // _______________
  // ::: Counter :::

  // Display data counter
  Serial.println(cpt++,DEC);
  Serial.print ("\t");



  // ____________________________________
  // :::  accelerometer and gyroscope :::

  // Read accelerometer and gyroscope
  uint8_t Buf[14];
  I2Cread(MPU9250_ADDRESS,0x3B,14,Buf);


  // Create 16 bits values from 8 bits data

  // Accelerometer
  int16_t ax=-(Buf[0]<<8 | Buf[1]);
  int16_t ay=-(Buf[2]<<8 | Buf[3]);
  int16_t az=Buf[4]<<8 | Buf[5];

  // Gyroscope
  int16_t gx=-(Buf[8]<<8 | Buf[9]);
  int16_t gy=-(Buf[10]<<8 | Buf[11]);
  int16_t gz=Buf[12]<<8 | Buf[13];

    // Display values

  // Accelerometer
  Serial.print (ax,DEC);
  Serial.print ("\t");
  Serial.print (ay,DEC);
  Serial.print ("\t");
  Serial.print (az,DEC); 
  Serial.print ("\t");

  // Gyroscope
  Serial.print (gx,DEC);
  Serial.print ("\t");
  Serial.print (gy,DEC);
  Serial.print ("\t");
  Serial.print (gz,DEC); 
  Serial.print ("\t");


  // _____________________
  // :::  Magnetometer :::


  // Read register Status 1 and wait for the DRDY: Data Ready
 //Strong suspicion that this do while loop repeats to infinity
  uint8_t ST1;
  do
  {
    I2Cread(MAG_ADDRESS,0x02,1,&ST1);
    //Serial.println("Reading");
  }
  while (!(ST1&0x01));

  // Read magnetometer data 
  uint8_t Mag[7]; 
  I2Cread(MAG_ADDRESS,0x03,7,Mag);


  // Create 16 bits values from 8 bits data

  // Magnetometer
  int16_t mx=-(Mag[3]<<8 | Mag[2]);
  int16_t my=-(Mag[1]<<8 | Mag[0]);
  int16_t mz=-(Mag[5]<<8 | Mag[4]);


  // Magnetometer
  Serial.print (mx+200,DEC);
  Serial.print ("\t");
  Serial.print (my-70,DEC);
  Serial.print ("\t");
  Serial.print (mz-700,DEC); 
  Serial.print ("\t");



  // End of line
  Serial.println("");
  delay(100);   
}









The thing is I have the following problem.

It displays some weird caracters and never tells anything .





So what's wrong ? My wiring ? The code ? I have no idea what to do, please send some help xD

PEKANO

So I resolved the weird characters problems, but the sensor keep telling me "Data Not Ready". Anyone knows what's the problem ?



jremington

#4
Mar 23, 2017, 06:26 pm Last Edit: Mar 23, 2017, 06:27 pm by jremington
That code doesn't work.

It was intended for an MPU-9250, which your sensor is not.

Try different code. You could read the data sheets for the devices, and take into account the differences.

PEKANO

I found someone on internet who said that it worked for his MPU-9255 o/

PEKANO

I AM NO HERO
AND IF YOU LOOK TO THE SKY
YOU WILL NEVER SEE MY NAME
YOU'LL NEVER SEE, ME CRY

plz send some help



PEKANO

USE THIS CAPTOR ???





Without joking.

I practice MMA for 6 years now, boxing in parallel for 7 years, I could.

As well as bodybuilding for 4 years, 1m87 for 86 kg

I have a crazy speed, and reflexes identical to my speed. I just have to wait for him to load me, dodge and give him good potatoes in the head. I will not let it go, at the slightest mistake the sensor is finished. You will always have virgins from here to think that it is impossible. Nothing is impossible with Will friends, and 2) it is not with your body of coward that you will do anything.

Any man a minimally trained can defeat an arduino sensor with a knife already. With naked hand it is not necessarily more complicated it just demands the technique.

PEKANO

ISSOU LA CHANCLA YATANGAKI

HELP ME

-----

Roses are red
Violets are blue
I'm not in my bed
and I need your help to
Resolve this freaking problem
Which is sucking a lot
I have to ask for them
How to make it work.

jashraf

Did you resolved that problem? I have a same IMU Unit but havent figured out how to get the right values- a bro in need!

Power_Broker

"The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind."
   - Nikola Tesla

jashraf

Yes it has a MPU 9255 on it, but I cannot find the predefined library on Arduino, tried searching for MPU 9250, have got one and followed the link you've shared

jashraf

Here is another code, I am getting first two values, but then there is some looping problem, I have to click on my serial monitor to get the values again, if someone can determine where the loop is stuck then we are golden.

Connecitons :

http://www.lucidarme.me/wp-content/uploads/2015/01/wiring.png

Code:

#include <Wire.h>

#define    MPU9250_ADDRESS            0x68
#define    MAG_ADDRESS                0x0C

#define    GYRO_FULL_SCALE_250_DPS    0x00 
#define    GYRO_FULL_SCALE_500_DPS    0x08
#define    GYRO_FULL_SCALE_1000_DPS   0x10
#define    GYRO_FULL_SCALE_2000_DPS   0x18

#define    ACC_FULL_SCALE_2_G        0x00 
#define    ACC_FULL_SCALE_4_G        0x08
#define    ACC_FULL_SCALE_8_G        0x10
#define    ACC_FULL_SCALE_16_G       0x18



// This function read Nbytes bytes from I2C device at address Address.
// Put read bytes starting at register Register in the Data array.
void I2Cread(uint8_t Address, uint8_t Register, uint8_t Nbytes, uint8_t* Data)
{
  // Set register address
  Wire.beginTransmission(Address);
  Wire.write(Register);
  Wire.endTransmission();
 
  // Read Nbytes
  Wire.requestFrom(Address, Nbytes);
  uint8_t index=0;
  while (Wire.available())
    Data[index++]=Wire.read();
}


// Write a byte (Data) in device (Address) at register (Register)
void I2CwriteByte(uint8_t Address, uint8_t Register, uint8_t Data)
{
  // Set register address
  Wire.beginTransmission(Address);
  Wire.write(Register);
  Wire.write(Data);
  Wire.endTransmission();
}


// Initializations
void setup()
{
  // Arduino initializations
  Wire.begin();
  Serial.begin(9600);
 
  // Configure gyroscope range
  I2CwriteByte(MPU9250_ADDRESS,27,GYRO_FULL_SCALE_2000_DPS);
  // Configure accelerometers range
  I2CwriteByte(MPU9250_ADDRESS,28,ACC_FULL_SCALE_16_G);
  // Set by pass mode for the magnetometers
  I2CwriteByte(MPU9250_ADDRESS,0x37,0x02);
 
  // Request first magnetometer single measurement
  I2CwriteByte(MAG_ADDRESS,0x0A,0x01);


}


long int cpt=0;
// Main loop, read and display data
void loop()
{
 
  // _______________
  // ::: Counter :::
 
  // Display data counter
  Serial.print (cpt++,DEC);
  Serial.print ("\t");
 
 
 
  // ____________________________________
  // :::  accelerometer and gyroscope :::

  // Read accelerometer and gyroscope
  uint8_t Buf[14];
  I2Cread(MPU9250_ADDRESS,0x3B,14,Buf);
 
 
  // Create 16 bits values from 8 bits data
 
  // Accelerometer
  int16_t ax=-(Buf[0]<<8 | Buf[1]);
  int16_t ay=-(Buf[2]<<8 | Buf[3]);
  int16_t az=Buf[4]<<8 | Buf[5];

  // Gyroscope
  int16_t gx=-(Buf[8]<<8 | Buf[9]);
  int16_t gy=-(Buf[10]<<8 | Buf[11]);
  int16_t gz=Buf[12]<<8 | Buf[13];
 
    // Display values
 
  // Accelerometer
  Serial.print (ax,DEC);
  Serial.print ("\t");
  Serial.print (ay,DEC);
  Serial.print ("\t");
  Serial.print (az,DEC); 
  Serial.print ("\t");
 
  // Gyroscope
  Serial.print (gx,DEC);
  Serial.print ("\t");
  Serial.print (gy,DEC);
  Serial.print ("\t");
  Serial.print (gz,DEC); 
  Serial.print ("\t");

 
  // _____________________
  // :::  Magnetometer :::

 
  // Read register Status 1 and wait for the DRDY: Data Ready
 
  uint8_t ST1;
  do
  {
    I2Cread(MAG_ADDRESS,0x02,1,&ST1);
  }
  while (!(ST1&0x01));

  // Read magnetometer data 
  uint8_t Mag[7]; 
  I2Cread(MAG_ADDRESS,0x03,7,Mag);
 

  // Create 16 bits values from 8 bits data
 
  // Magnetometer
  int16_t mx=-(Mag[3]<<8 | Mag[2]);
  int16_t my=-(Mag[1]<<8 | Mag[0]);
  int16_t mz=-(Mag[5]<<8 | Mag[4]);
 
 
  // Magnetometer
  Serial.print (mx+200,DEC);
  Serial.print ("\t");
  Serial.print (my-70,DEC);
  Serial.print ("\t");
  Serial.print (mz-700,DEC); 
  Serial.print ("\t");
 
 
 
  // End of line
  Serial.println("");
//  delay(1000);   
}

Go Up