Good afternoon all
I am having problems with my data from the mpu 6050 it is a generic type purchased from ebay. However when I run the example code I get sensible reading.
The issue that i am having is more than likley somthing silly that i am missing so i would very much appreciate any help.
here is the code that I am running it runs inset up and will eventually determine the starting angle of my robot.
I am using the MPU’s accelerometer in 2g mode and taking no data from the gyro or temp.
#include <Wire.h> // pin A4 = serial Data (SDA) pin A5 = serial clock (SDA)
int MPU = 0X68; // declare I2C address here
uint16_t aX = 0, aY = 0, aZ = 0; // 16bit storage for storing the raw acc data
float accX = 0, accY = 0, accZ = 0; // for storing the processed values from the acc
unsigned short led_pin = 13; // Pin used to supply the LED's with power to for visual notification.
void setup(){
short i = 0; // for counting flashes of LED's using a loop.
// initialize serial communication
Serial.begin(9700);
Serial.println("setup initialized. . . . . ");
// flash leds 5x as indicator that setup is initialized
pinMode(led_pin,OUTPUT);
digitalWrite(led_pin, LOW);
while (i <= 4){
digitalWrite(led_pin,HIGH);
delay(500);
digitalWrite(led_pin,LOW);
delay(500);
Serial.println (i);
i++;
}
Serial.println("visual drone status sent . . . . " );
// set up MUP ready to transmit
Wire.beginTransmission(MPU); //set the power register.
Wire.write (0x6B);
Wire.write (0x00);
Wire.endTransmission(true);
Wire.beginTransmission(MPU);
Wire.write(0x1B);
Wire.write(0x00);
Wire.endTransmission(true);
Wire.beginTransmission(MPU);
Wire.write(0x1C);
Wire.write(0x00);
Wire.endTransmission(true);
Serial.println("MPU6050 initialized . . . . ");
// read Acc to obtain orientation
Wire.beginTransmission(MPU);
Wire.write(0x3b);
Wire.endTransmission(false);
Wire.requestFrom(MPU,6,true);
Wire.endTransmission(false);
aX = Wire.read() <<8| Wire.read ();
aY = Wire.read() <<8| Wire.read ();
aZ = Wire.read() <<8| Wire.read ();
Serial.println ("Data recived . . . . ");
Serial.print ("aX = " ); Serial.println(aX);
Serial.print (" aY = "); Serial.println(aY);
Serial.print (" aZ = "); Serial.println(aZ);
Serial.println ("data processing in progress . . . . ");
accX = aX / 16384.0;
accY = aY / 16384.0;
accZ = aZ / 16384.0;
Serial.print ("accX = " ); Serial.println(accX);
Serial.print (" accY = "); Serial.println(accY);
Serial.print (" accZ = "); Serial.println(accZ);
Serial.println (" data processing in complete . . . . ");
// calculate base orientation
// flash led 3x as indication to set up complete
while(i <= 7){
digitalWrite(led_pin,HIGH);
delay(500);
digitalWrite(led_pin,LOW);
delay(500);
Serial.println (i);
i++;
}
// turn on positioning lights to indicates bluetooth connectivity
digitalWrite(led_pin, HIGH);
Serial.print ("setup complete! \n"); // marks the end of setup for serial interface.
}
this is what’s returned in the serial monitor however the mpu is stationary on a flat surface. so I would expect that the ACC reading should be around 1g give or take a little as I am on planet earth, although if I am wrong here please do correct me.
setup initialized. . . . .
0
1
2
3
4
visual drone status sent . . . .
MPU6050 initialized . . . .
Data recived . . . .
aX = 32767
aY = 32767
aZ = 364
data processing in progress . . . .
accX = 2.00
accY = 2.00
accZ = 0.02
data processing in complete . . . .
5
6
7
setup complete!
I have checked all of my connections and wiring i have also tryed 2 MPU’s so i am prety sure i have missed somthing important in the code.
many thanks in advanced