from machine import Pin, I2C
from time import sleep
from mpu6050 import MPU6050
from ssd1306 import SSD1306_I2C
i2c_mpu = I2C(0, scl=Pin(1), sda=Pin(0), freq=400000)
sensor = MPU6050(i2c_mpu)
i2c_oled = I2C(1, scl=Pin(3), sda=Pin(2), freq=400000)
oled = SSD1306_I2C(128, 64, i2c_oled)
while True:
ax, ay, az = sensor.get_accel()
gx, gy, gz = sensor.get_gyro()
oled.fill(0)
oled.text("Accel", 0, 0)
oled.text("x: {:.2f}".format(ax), 0, 10)
oled.text("y: {:.2f}".format(ay), 0, 20)
oled.text("z: {:.2f}".format(az), 0, 30)
oled.text("Gyro", 64, 0)
oled.text("x: {:.1f}".format(gx), 64, 10)
oled.text("y: {:.1f}".format(gy), 64, 20)
oled.text("z: {:.1f}".format(gz), 64, 30)
oled.show()
sleep(0.5)