Breadboard
docs
Example project · ESP32

Motion sensor (MPU-6050, S3)

Wake a 6-axis IMU exactly like a real driver: WHO_AM_I check, sleep-bit clear, then a burst read of the accelerometer. The prefilled script prints the gravity vector in g; change the tilt in the Inspector and read again.

The Motion sensor (MPU-6050, S3) circuit as rendered by the simulator

What's on the bench

  • Battery
  • ESP32-S3
  • MPU-6050

The code

This MicroPython script runs on the emulated board every boot; edit it in the Code tab.

from machine import I2C, Pin
import struct
i = I2C(0, scl=Pin(9), sda=Pin(8))
print('WHO_AM_I:', hex(i.readfrom_mem(0x68, 0x75, 1)[0]))
i.writeto_mem(0x68, 0x6B, b'\x00')  # wake from sleep
ax, ay, az = struct.unpack(">hhh", i.readfrom_mem(0x68, 0x3B, 6))
print('accel g:', ax / 16384, ay / 16384, az / 16384)