#include <Adafruit_MPU6050.h> //Header for MPU
#include <Adafruit_Sensor.h> //Header for MPU
#include <Wire.h> //I2C Communication for modules
#include <Adafruit_GFX.h> //Header for OLED screen
#include <Adafruit_SSD1306.h> //Header for OLED screen
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &Wire);
Adafruit_MPU6050 mpu;
void setup()
{
Serial.begin(9600); //Starts Serial Monitor
while (!mpu.begin()) {
Serial.println("MPU6050 not connected!"); //Check to see if MPU is connected successfully
delay(1000);
}
Serial.println("MPU6050 ready!"); //If MPU connected successfully then continue
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32
display.display(); //Starts the display
delay(1000);
display.clearDisplay(); //Make sure the display starts off blank
display.display();
}
sensors_event_t event;
void loop() {
mpu.getAccelerometerSensor()->getEvent(&event); //Get infomation from the MPU
display.setTextSize(1); //Set text Size for OLED
display.setTextColor(SSD1306_WHITE); //Set text colour for OLED
display.setCursor(0,0); //Set location for the text for OLED
display.print(" X: ");
display.println(event.acceleration.x); //Print the acceleration in the X axis
display.print(" Y: ");
display.println(event.acceleration.y); //Print the acceleration in the Y axis
display.print(" Z: ");
display.print(event.acceleration.z); //Print the acceleration in the Z axis
display.println(" m/s^2");
display.display();
delay(500);
display.clearDisplay(); //Clear display so new infomation can be printed
}
Loading
ssd1306
ssd1306