from machine import Pin, I2C
import ssd1306
import mpu6050
import time
# ESP32 Pin assignment
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
mpu = mpu6050.MPU6050(i2c)
# wake up the MPU6050 from sleep
mpu.wake()
gyro = ""
accel = ""
temp = ""
# continuously print the data
while True:
new_gyro = mpu.read_gyro_data()
new_accel = mpu.read_accel_data()
temperature = mpu.read_temperature()
if(new_gyro != gyro or new_accel != accel or temperature != temp):
gyro = new_gyro
accel = new_accel
temp = temperature
print("Gyro: " + str(gyro) + ", Accel: " + str(accel))
oled.fill(0)
oled.text("Gyro", 0, 2)
oled.text("-----------------", 0, 10)
oled.text("x:"+ str(round(gyro[0],2)), 0, 15)
oled.text("y:"+ str(round(gyro[1],2)), 0, 25)
oled.text("z:"+ str(round(gyro[2],2)), 0, 35)
oled.text("Accel", 70, 2)
oled.text("x:"+ str(round(accel[0],2)), 70, 15)
oled.text("y:"+ str(round(accel[1],2)), 70, 25)
oled.text("z:"+ str(round(accel[2],2)), 70, 35)
oled.text("Temp", 0, 45)
oled.text("------------"+str(temperature), 0, 48)
oled.show()
time.sleep(0.1)
esp:0
esp:2
esp:4
esp:5
esp:12
esp:13
esp:14
esp:15
esp:16
esp:17
esp:18
esp:19
esp:21
esp:22
esp:23
esp:25
esp:26
esp:27
esp:32
esp:33
esp:34
esp:35
esp:3V3
esp:EN
esp:VP
esp:VN
esp:GND.1
esp:D2
esp:D3
esp:CMD
esp:5V
esp:GND.2
esp:TX
esp:RX
esp:GND.3
esp:D1
esp:D0
esp:CLK
oled1:GND
oled1:VCC
oled1:SCL
oled1:SDA
imu1:INT
imu1:AD0
imu1:XCL
imu1:XDA
imu1:SDA
imu1:SCL
imu1:GND
imu1:VCC