# Import necessary libraries
import machine
from utime import sleep
from lcd_api import LcdApi
from i2c_lcd import I2cLcd
import mpu6050
# Pin configuration
sda = machine.Pin(21)
scl = machine.Pin(22)
# I2C configuration
i2c = machine.SoftI2C(sda=sda, scl=scl, freq=10000)
# Initialize the LCD display
lcd = I2cLcd(i2c, 0x27, 2, 16)
mpu = mpu6050.MPU6050(i2c)
# Main routine
def main():
while True:
sensor_data = mpu_i2c()
lcd_i2c(sensor_data)
def mpu_i2c():
accel_data = mpu.read_accel_data()
temp_data = mpu.read_temperature()
print("Acceleration X: ", accel_data[0])
print("Acceleration Y: ", accel_data[1])
print("Acceleration Z: ", accel_data[2])
print("Temperature: ", temp_data)
return accel_data, temp_data
def lcd_i2c(sensor_data):
accel_data = sensor_data[0]
temp_data = sensor_data[1]
# Display acceleration data (X, Y, Z) and temperature on the LCD
lcd.move_to(0, 0)
display_text = "X:" +str("{:.2f}".format(accel_data[0]))
lcd.putstr(display_text)
lcd.move_to(8, 0)
display_text = "Y:" +str("{:.2f}".format(accel_data[1]))
lcd.putstr(display_text)
lcd.move_to(0, 1)
display_text = "Temp:" +str("{:.1f}".format(temp_data)) + "C"
lcd.putstr(display_text)
sleep(2)
if __name__ == "__main__":
main()