I have bougth this sensor 10 DOF IMU Sensor Waveshare ( http://www.waveshare.com/10-dof-imu-sensor-b.htm ). I have write a code which read the X value from Gyro but the values have no make sense.This is my code
#include <SPI.h>
#include "Wire.h"
#define MPU9250_ADDRESS 0x68
#define AK8963_ADDRESS 0x0C
#define BMP180_ADRESS 0X77
#define PWR_MGMT_1 0x6B
#define SMPLRT_DIV 0x19
#define CONFIG 0x1A
#define GYRO_CONFIG 0x1B
#define GYRO_XOUT_H 0x43
#define GYRO_XOUT_L 0x44
void setup()
{
Wire.begin();
TWBR = 24; // Two Wire Bit Rate Register(Controls the frequency of the clock (SCL)Hz)
Serial.begin(115200);
initMPU9250();
}
void loop ()
{
// Read gyroscope
uint8_t Buf[2];
I2Cread(MPU9250_ADDRESS, GYRO_XOUT_H, 2, Buf);
// Create 16 bits values from 8 bits data
// Gyroscope
int16_t gx = -(Buf[0] << 8 | Buf[1]);
// Display values Gyroscope
Serial.print (gx, DEC);
Serial.print ("\t");
delay(1000);
}
// 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();
}
// 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();
}
void initMPU9250()
{
/**
* Just wakes the device up, because it sets the
* sleep bit to 0. Also sets
* the clock source to internal.
*/
I2CwriteByte(MPU9250_ADDRESS, PWR_MGMT_1, 0x00);
delay(100);
/**
* Setting the digital low pass filter to
* Acc Bandwidth (Hz) = 184
* Acc Delay (ms) = 2.0
* Gyro Bandwidth (Hz) = 188
* Gyro Delay (ms) = 1.9
* Fs (kHz) = 1
*
*/
I2CwriteByte(MPU9250_ADDRESS, PWR_MGMT_1, 0x01);
delay(200);
/**
* Setting the digital low pass filter to
* Acc Bandwidth (Hz) = 184
* Acc Delay (ms) = 2.0
* Gyro Bandwidth (Hz) = 188
* Gyro Delay (ms) = 1.9
* Fs (kHz) = 1
*
*/
I2CwriteByte(MPU9250_ADDRESS, CONFIG, 0x03);
/**
* Sets the smaple rate divider for the gyroscopes and
* accelerometers. This
* means
* acc-rate = 1kHz / 1+ sample-rate
* and
* gyro-rate = 8kHz /1+ sample-rate.
* The concrete value 0 leaves the sample rate on
* default, which means 1kHz for acc-rate and
* 8kHz for gyr-rate.
*/
I2CwriteByte(MPU9250_ADDRESS, SMPLRT_DIV, 0x00);
delay(100);
I2CwriteByte(MPU9250_ADDRESS, GYRO_CONFIG,0xE1);
}
The Output is
-18686 -18374 -18500 -18872 -18474 -18722 -18562 -18486 -18658 -18822 -18310 -18598 -18524 -18574
And when I move my sensor nothing change.
What is Wrong?