#include <LiquidCrystal_I2C.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
Adafruit_MPU6050 mpu;
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
const float rad = 180/3.14159265359;
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(8, 1);
lcd.print("AXEL");
lcd.setCursor(0, 3);
lcd.print("By: Arkan Asadil H");
delay(500);
lcd.clear();
while (!mpu.begin()) {
lcd.setCursor(0, 0);
lcd.print("MPU6050 not ready!");
lcd.setCursor(0, 1);
lcd.print(millis()/1000);
lcd.print(" Sec");
delay(1000);
}
mpu.setAccelerometerRange(MPU6050_RANGE_16_G);
mpu.setGyroRange(MPU6050_RANGE_250_DEG);
mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
lcd.println("MPU6050 ready!");
lcd.setCursor(0, 1);
lcd.println("Fliter BW 21Hz");
lcd.setCursor(0, 2);
lcd.println("Gyro range 250DEG");
delay(100);
lcd.clear();
}
void loop() {
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
//Acceleration in g constant
//Gyro in Degrees
//Accel cannot be divided using variable
/* error: no match for 'operator/'
(operand types are 'float' and 'sensors_event_t') */
lcd.setCursor(0, 0);
lcd.print("X:");
lcd.print(a.acceleration.x/9.81);
lcd.print(" R:");
lcd.println(g.gyro.x*rad);
lcd.setCursor(0, 1);
lcd.print("Y:");
lcd.print(a.acceleration.y/9.81);
lcd.print(" P:");
lcd.println(g.gyro.y*rad);
lcd.setCursor(0, 2);
lcd.print("Z:");
lcd.print(a.acceleration.z/9.81);
lcd.print(" Y:");
lcd.println(g.gyro.z*rad);
lcd.setCursor(0, 3);
lcd.print(millis() % 1000);
lcd.print(" millis");
lcd.print(" T:");
lcd.println(temp.temperature);
delay(10);
}