MPU6500 and MPU6050 Arduino Simple Code
From wikiluntti
Introduction
Libraries
- FastIMU
- MPU6050_WE
- Wire / I2C addr = 0x68
- Wire / MPU6050 addr
- TwoWire obj wire2
Theory
MPU6050_WE.h
Connections:
- VCC -> 3.3 V
- GND -> GND
- SCL -> SCL
- SDA -> SDA
/***************************************************************************
* https://wolles-elektronikkiste.de/en/mpu9250-9-axis-sensor-module-part-1 (English)
***************************************************************************/
#include <MPU6050_WE.h>
#include <Wire.h>
#define MPU6050_ADDR 0x68
MPU6050_WE myMPU6050 = MPU6050_WE(MPU6050_ADDR);
void setup() {
Serial.begin(115200);
Wire.begin();
if(!myMPU6050.init()){
Serial.println("MPU6050 does not respond");
}
else{
Serial.println("MPU6050 is connected");
}
Serial.println("Position you MPU6050 flat and don't move it - calibrating...");
delay(1000);
myMPU6050.autoOffsets();
Serial.println("Done!");
myMPU6050.setAccRange(MPU6050_ACC_RANGE_2G);
Serial.println( "ax, ay, az, a" );
delay(200);
}
void loop() {
xyzFloat gValue = myMPU6050.getGValues();
float resultantG = myMPU6050.getResultantG(gValue);
Serial.print(gValue.x);
Serial.print(", ");
Serial.print(gValue.y);
Serial.print(", ");
Serial.print(gValue.z);
Serial.print(", ");
Serial.println(resultantG);
delay(100);
}