Hii
i am working with mpu6050 and stucked with getting a proper angle value from accelerometer.
(I am using full scale range of accelerometer). for now, just consider one angle (angle X) , so when i am reading the raw data from the accelerometer it is giving me the range of value from 0 - 16384 when i turn MPU6050 from 0 to 90 degree.
and when rotating 90 to 180 degree, value chnages from 16384 - 0
and same is going in while rotating 180 to 270, value is changing from 0 to -16384 and again for 270 - 360 degree it goes all the way -16384 to 0.
I actually want to map this value in the range of 0 - 360 degree,
how it will be done, any idea would be appreciated
here is the program i wrote, just fro reading accelerometer x value.
#include<Wire.h>
const int MPU_addr = 0x68; // MPU6050 I2C address
byte error;
int16_t temp;
int16_t accel_x;
void initialise_gyro()
{
Wire.begin();
Wire.beginTransmission(MPU_addr);
Wire.write(0x6B); // power management 1
Wire.write(0x00);
Wire.endTransmission(true);
Wire.beginTransmission(MPU_addr);
Wire.write(0x6c); // standby mode of particular hardware
Wire.write(0x00);
Wire.endTransmission(true);
Wire.beginTransmission(MPU_addr);
Wire.write(0x1C); // accelerometer configuration
Wire.write(0b00000000);
Wire.endTransmission(true);
delay(100);
}
int16_t read_accel_x()
{ // for reading accel_x
Wire.beginTransmission(MPU_addr);
Wire.write(0x3B);
error = Wire.endTransmission(false);
if (error != 0)
{
Serial.println("ERROR DURING READING");
}
Wire.requestFrom(MPU_addr, 2, true);
if (Wire.available() == 2)
{
temp = Wire.read() << 8;
temp |= Wire.read();
}
else
{
Serial.println("data not equal to two byte");
}
return temp;
}
void setup() {
Serial.begin(115200);
initialise_gyro();
delay(200);
}
void loop() {
accel_x = read_accel_x();
Serial.println(accel_x);
//Serial.println(accel_x/180); //for the range of angle 0-180 , 0-16384
delay(100);
}