from machine import I2C, Pin
import network
import time
from mpu6050 import MPU6050
# Wi-Fi details
ssid = 'Wokwi-GUEST'
password = ''
# Initialize I2C
i2c = I2C(scl=Pin(22), sda=Pin(21))
# Connect to Wi-Fi
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
while not wlan.isconnected():
time.sleep(0.5)
print('Connecting to WiFi..')
print('Connected to WiFi network')
print('IP address:', wlan.ifconfig()[0])
# Initialize MPU6050 sensor
mpu = MPU6050(i2c)
print('MPU6050 Found!')
# Set ranges
mpu.set_accel_range(MPU6050.ACCEL_RANGE_8G)
mpu.set_gyro_range(MPU6050.GYRO_RANGE_500DEG)
mpu.set_filter_bandwidth(MPU6050.DLPF_BW_5HZ)
time.sleep(0.1)
while True:
# Get sensor readings
accel = mpu.get_accel_data()
gyro = mpu.get_gyro_data()
temp = mpu.get_temp()
# Print out the values
print('Acceleration X:', accel['x'], 'Y:', accel['y'], 'Z:', accel['z'], 'm/s^2')
print('Rotation X:', gyro['x'], 'Y:', gyro['y'], 'Z:', gyro['z'], 'rad/s')
print('Temperature:', temp, 'degC')
print('')
time.sleep(0.5)