//INCLUDE LIBRARY OLED
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Wire.h>
//DEFINE OLED PIXELS
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
//CREATE OLED DISPLAY OBJECT CONNECTED TO I2C
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
//INCLUDE LIBRARY MPU6050
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
//CREATE MPU6050
Adafruit_MPU6050 mpu;
void setup() {
Serial.begin(9600);
// initialize OLED display with I2C address 0x3C
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("failed to start SSD1306 OLED"));
while (1);
}
delay(2000); // wait two seconds for initializing
oled.clearDisplay(); // clear display
oled.setTextSize(1); // set text size
oled.setTextColor(WHITE); // set text color
oled.setCursor(0, 0); // set position to display
oled.println("esp32io.com"); // set text
oled.display(); // display on OLED
delay(2000);
oled.clearDisplay();
// Try to initialize!
if (!mpu.begin()) {
oled.setCursor(1, 0);
oled.println("Failed to find MPU6050 chip");
while (1) {
delay(10);
}
oled.setTextSize(1); // set text size
oled.setTextColor(WHITE); // set text color
oled.setCursor(0, 0); // set position to display
oled.println("MPU6050 Found!");
oled.display(); // display on OLED
}
}
void loop() {
// oled.clearDisplay(); // clear display
// oled.setTextSize(1); // set text size
// oled.setTextColor(WHITE); // set text color
// oled.setCursor(10, 10); // set position to display
// oled.println("halo"); // set text
// oled.display();
}
Loading
ssd1306
ssd1306