from machine import Pin, I2C
import mpu6050
import time
# Inisialisasi I2C dan MPU6050
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
mpu = mpu6050.MPU6050(i2c)
mpu.wake() # Bangunkan MPU6050 dari sleep mode
# Loop utama
while True:
# Baca data sensor
gyro = mpu.read_gyro_data() # Gyro (rad/s)
accel = mpu.read_accel_data() # Akselerasi (g)
temp = mpu.read_temperature() # Suhu (°C)
# Tampilkan ke Serial
print("\n--- MPU6050 ---")
print(f"Gyro (rad/s): X:{gyro[0]:7.2f}, Y:{gyro[1]:7.2f}, Z:{gyro[2]:7.2f}")
print(f"Accel (g) : X:{accel[0]:6.3f}, Y:{accel[1]:6.3f}, Z:{accel[2]:6.3f}")
print(f"Temp (°C) : {temp:6.2f}")
time.sleep(0.1) # Delay 100ms