Skip to content

Instantly share code, notes, and snippets.

@elktros
Created November 21, 2017 10:48
Show Gist options
  • Save elktros/3f6a07bcc1220e899b0fec615f5b3a6e to your computer and use it in GitHub Desktop.
Save elktros/3f6a07bcc1220e899b0fec615f5b3a6e to your computer and use it in GitHub Desktop.
Arduino Code for getting raw values from MPU-6050 Sensor
#include<Wire.h>
const int MPU6050_addr=0x68;
int16_t AccX,AccY,AccZ,Temp,GyroX,GyroY,GyroZ;
void setup(){
Wire.begin();
Wire.beginTransmission(MPU6050_addr);
Wire.write(0x6B);
Wire.write(0);
Wire.endTransmission(true);
Serial.begin(9600);
}
void loop(){
Wire.beginTransmission(MPU6050_addr);
Wire.write(0x3B);
Wire.endTransmission(false);
Wire.requestFrom(MPU6050_addr,14,true);
AccX=Wire.read()<<8|Wire.read();
AccY=Wire.read()<<8|Wire.read();
AccZ=Wire.read()<<8|Wire.read();
Temp=Wire.read()<<8|Wire.read();
GyroX=Wire.read()<<8|Wire.read();
GyroY=Wire.read()<<8|Wire.read();
GyroZ=Wire.read()<<8|Wire.read();
Serial.print("AccX = "); Serial.print(AccX);
Serial.print(" || AccY = "); Serial.print(AccY);
Serial.print(" || AccZ = "); Serial.print(AccZ);
Serial.print(" || Temp = "); Serial.print(Temp/340.00+36.53);
Serial.print(" || GyroX = "); Serial.print(GyroX);
Serial.print(" || GyroY = "); Serial.print(GyroY);
Serial.print(" || GyroZ = "); Serial.println(GyroZ);
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment