I'm working with MPU-6050 with Arduino Uno.
I copied the code below from Arduino Playground - MPU6050.
Code :
// MPU-6050 Short Example Sketch
// By Arduino User JohnChi
// August 17, 2014
// Public Domain
#include<Wire.h>
const int MPU_addr = 0x68; // I2C address of the MPU-6050
int16_t AcX, AcY, AcZ, Tmp, GyX, GyY, GyZ;
void setup() {
Wire.begin();
Wire.beginTransmission(MPU_addr);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);
Serial.begin(9600);
}
void loop() {
Wire.beginTransmission(MPU_addr);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr, 14, true); // request a total of 14 registers
AcX = Wire.read() << 8 | Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
AcY = Wire.read() << 8 | Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
AcZ = Wire.read() << 8 | Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
Tmp = Wire.read() << 8 | Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
GyX = Wire.read() << 8 | Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
GyY = Wire.read() << 8 | Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
GyZ = Wire.read() << 8 | Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
Serial.print("AcX = "); Serial.print(AcX);
Serial.print(" | AcY = "); Serial.print(AcY);
Serial.print(" | AcZ = "); Serial.print(AcZ);
Serial.print(" | Tmp = "); Serial.print(Tmp / 340.00 + 36.53); //equation for temperature in degrees C from datasheet
Serial.print(" | GyX = "); Serial.print(GyX);
Serial.print(" | GyY = "); Serial.print(GyY);
Serial.print(" | GyZ = "); Serial.println(GyZ);
delay(333);
}
Firstly, I want to know every details about this code, AcX, AcY, AcZ, GyX, GyY, GyZ what all these mean ?
It will be nice with some visual representation.
Secondly, If I change the delay to 500 from 333, will it cause a problem ?
This type of stupid question because, I can't find any relatable figure with 333 except 1000/3
2 Answers 2
AcX = Accelerometer data in X axis in floating point.
AcY = Accelerometer data in Y axis in floating point.
AcZ = Accelerometer data in Z axis in floating point.
GyX = Gyroscope data in X axis in floating point.
GyY = Gyroscope data in X axis in floating point.
GyZ = Gyroscope data in X axis in floating point
.
Secondly study regarding I2C communication and MPU 6050 datasheet.
Third you have any value for delay as it is how fast you want to fetch data from all axis from IMU.
-
Thanks, I was trying to move and rotate an object in Unity using Arduino as input . Now I have this , rotation is perfect but, position isn't . Maybe you can help me with that.Maifee Ul Asad– Maifee Ul Asad2019年04月22日 08:46:44 +00:00Commented Apr 22, 2019 at 8:46
I think that AcX, AcY, AcZ, GyX, GyY, GyZ are raw acceleration and gyroscopic values recieved from mpu6050 in the corresponding directions. in order to recieve them a procedure is followed.
Wire.read();
means two registers are read and stored in the same variable
accelerometer_x = Wire.read()<<8 | Wire.read();
reads registers: 0x3B (ACCEL_XOUT_H) and 0x3C (ACCEL_XOUT_L) that is , it deals with bitwise operation to shift the values 8 bits left (multiplying it by 256). This enables addition ("|" or "ored") of two datas in order to continuously output the accelerometer data !! Without this you would not be able to see the increasing and decreasing sloping values . Further, the print just displays the instantaneous values on screen.
If you want to go in deapth of the code, you can visit this site for line to line description !!
delay(500);
Totally depends on your project, i don't see any forecoming issues if you will make 333 go 500 !! It will just stablize the output on screen there for a bit longer (for .5 seconds)
-
How to process these raw value to actual value ?Maifee Ul Asad– Maifee Ul Asad2019年04月01日 02:41:15 +00:00Commented Apr 1, 2019 at 2:41
-
@MaifeeUlAsad You can always use the mpu6050 library by jeffrowberg !! He has done an excellent job in reverse engineering the mpu6050 aspects and put them in perspective. You can use mpu6050_dmp6 sketch to get real processed values.Hrithik Baishakhiya– Hrithik Baishakhiya2019年04月01日 05:02:35 +00:00Commented Apr 1, 2019 at 5:02
-
you can also include the library and use some functions like mpu.getmotion6(&ax, &ay,&az,&gx,&gy,&gz,) to get these precise values.Hrithik Baishakhiya– Hrithik Baishakhiya2019年04月01日 05:06:32 +00:00Commented Apr 1, 2019 at 5:06
-
Thanks, I was trying to move and rotate an object in Unity using Arduino as input . Now I have this , rotation is perfect but, position isn't . Maybe you can help me with that.Maifee Ul Asad– Maifee Ul Asad2019年04月22日 08:46:50 +00:00Commented Apr 22, 2019 at 8:46
Explore related questions
See similar questions with these tags.
I can't find any relatable figure with 333
.... think about it a little bit ..... what is the purpose ofloop()
? ..... what happens if you put a 333ms delay inloop()
?