import time import board import busio import adafruit_mpu6050 # Import Adafruit's MPU6050 library # Initialize the I2C bus ONCE i2c = busio.I2C(board.GP1, board.GP0) # Use GP1 (SCL) and GP0 (SDA) # Initialize the MPU6050 sensor using the Adafruit library mpu = adafruit_mpu6050.MPU6050(i2c) # Optional: Adjust settings (Uncomment if needed) # mpu.gyro_range = adafruit_mpu6050.GyroRange.RANGE_500_DPS # mpu.accelerometer_range = adafruit_mpu6050.Range.RANGE_4_G # mpu.filter_bandwidth = adafruit_mpu6050.Bandwidth.BAND_94_HZ print("MPU6050 Initialized! Starting sensor read loop...") try: while True: # Read acceleration (m/s^2) accel_x, accel_y, accel_z = mpu.acceleration # Read gyro data (degrees/s) gyro_x, gyro_y, gyro_z = mpu.gyro # Read temperature (°C) temp = mpu.temperature # Print sensor data print(f"Accel: X={accel_x:.2f}, Y={accel_y:.2f}, Z={accel_z:.2f} m/s²") print(f"Gyro: X={gyro_x:.2f}, Y={gyro_y:.2f}, Z={gyro_z:.2f} °/s") print(f"Temp: {temp:.2f}°C") print("-" * 40) time.sleep(0.1) # Adjust delay as needed except KeyboardInterrupt: print("Exiting...")