MPU6050 Six-Axis Gyroscope
MPU6050 Six-Axis Gyroscope
Overview
MPU6050 is a six-axis motion sensor (3-axis accelerometer + 3-axis gyroscope) that communicates via I2C bus. It can measure acceleration, angular velocity, and calculate tilt angle. Suitable for attitude detection, motion tracking, tilt alarm, and other scenarios.
Firmware Requirement: Standard / Full firmware enables
FASTBEE_ENABLE_I2C_SENSORSby default; Lite has it disabled by default.
Supported Peripheral Types
| Type | type Value | Description |
|---|---|---|
| SENSOR | 38 | I2C sensor (MPU6050) |
Hardware Wiring
| MPU6050 Pin | ESP32 GPIO | Description |
|---|---|---|
| VCC | 3.3V | Power supply |
| GND | GND | Ground |
| SDA | GPIO 21 | I2C data line |
| SCL | GPIO 22 | I2C clock line |
| INT | GPIO (optional) | Interrupt output (data ready) |
MPU6050 supports 3.3V and 5V power supply; ESP32 recommends using 3.3V.
Configuration
Method 1: Web Interface Configuration (Recommended)
Before saving MPU6050 configuration, verify I2C address, collection fields, and installation orientation.
Step 1: Navigate to Peripheral Management Page
- Open a browser and navigate to the ESP32 IP address
- After logging in, click Peripheral Configuration in the left menu
Step 2: Add MPU6050 Peripheral
Click the Add Peripheral button
Fill in the configuration:
Field Value Description Peripheral ID mpu6050_1Unique identifier Name MPU6050 GyroscopeDisplay name Peripheral Type Generic Sensor (type: 38) I2C sensor SDA Pin 21I2C data pin SCL Pin 22I2C clock pin Driver Name MPU6050Fixed value I2C Address 0x680x68 or 0x69 Sampling Interval 10001 second (≥500ms) Accel Range 2±2g Gyro Range 250±250°/s Click Save
Step 3: Verify Configuration
- Find the newly added peripheral in the peripheral list
- Click the Enable toggle
- Wait 1 second and check acceleration, angular velocity, and tilt angle data
⚠️ Important: Requires
FASTBEE_ENABLE_I2C_SENSORS=1; Lite firmware does not include this driver by default.
Method 2: JSON Configuration File Import
Add the following configuration to the peripherals array in data/config/peripherals.json:
{
"id": "mpu6050_1",
"name": "MPU6050 Gyroscope",
"type": 38,
"enabled": false,
"pins": [21, 22],
"params": {
"driver": "MPU6050",
"i2cAddress": "0x68",
"interval": 1000,
"accelRange": 2,
"gyroRange": 250
}
}Parameter Description
| Parameter | Description |
|---|---|
| driver | Driver name, fixed to "MPU6050" |
| i2cAddress | I2C address, default 0x68 (AD0 to GND); 0x69 when AD0 to VCC |
| interval | Sampling interval (ms), recommend ≥ 500 |
| accelRange | Accelerometer range: 2/4/8/16 (unit: g) |
| gyroRange | Gyroscope range: 250/500/1000/2000 (unit: °/s) |
pins[0] = SDA pin, pins[1] = SCL pin
Data Report Format
Sensor data is reported via MQTT:
[
{"id": "mpu6050_1", "value": "ax:0.12,ay:-0.03,az:9.78,gx:1.2,gy:-0.5,gz:0.1,tilt:5.3"}
]| Field | Description | Unit |
|---|---|---|
| ax/ay/az | Three-axis acceleration | m/s² |
| gx/gy/gz | Three-axis angular velocity | °/s |
| tilt | Combined tilt angle | ° |
Driver Registration Mechanism
MPU6050 uses the ISensorDriver + DriverRegistry mechanism for registration:
- Enabled at compile time via
FASTBEE_ENABLE_I2C_SENSORSmacro - Driver automatically registers to the global registry
- The
driverfield in configuration is used to match the specific driver implementation
Peripheral Execution Integration
Web Interface Configuration Steps
Create Tilt Detection Alarm Rule
- Switch to the Peripheral Execution Management tab
- Click the Add Rule button
- Configure poll trigger:
- Trigger Type: Poll Trigger
- Data Source: mpu6050_1
- Data Field: tilt (tilt angle)
- Comparison: Greater Than
- Comparison Value: 30 (degrees)
- Add actions:
- Action 1: Buzzer alarm
- Action Type: High Level
- Target Peripheral: buzzer1
- Action 2: Trigger device event
- Action Type: Trigger Event
- Event ID: tilt_alarm
- Action 1: Buzzer alarm
- Click Save
💡 Tip: Can share I2C bus with BMP280 (different addresses)
JSON Configuration Example
Tilt Detection Alarm
{
"name": "Tilt Alarm",
"enabled": true,
"triggers": [
{
"type": "poll",
"params": {
"periphId": "mpu6050_1",
"field": "tilt",
"operator": ">",
"threshold": 30
}
}
],
"actions": [
{
"type": "gpio_write",
"params": {
"periphId": "buzzer1",
"value": "1"
}
},
{
"type": "event_emit",
"params": { "event": "tilt_alarm" }
}
]
}Attitude Data Display on OLED
{
"name": "Display Attitude",
"enabled": true,
"triggers": [
{
"type": "timer",
"params": { "interval": 2000 }
}
],
"actions": [
{
"type": "sensor_read",
"params": { "periphId": "mpu6050_1" }
},
{
"type": "display_write",
"params": {
"periphId": "oled1",
"template": "Tilt:{mpu6050_1.tilt}deg\nAx:{mpu6050_1.ax}"
}
}
]
}Notes
- Firmware Version: Standard / Full firmware includes MPU6050 driver; Lite does not support it by default
- Installation Orientation: Sensor installation orientation affects axis definition; calibrate based on actual installation
- Offset Calibration: Recommend performing offset calibration on first use; place device horizontally at rest and read offset values
- Vibration Interference: Environmental vibration affects reading accuracy; recommend adding vibration dampening pad
- I2C Sharing: Can share the same I2C bus with BMP280 (different addresses), saving pin resources
- Sampling Rate: High-speed sampling (< 100ms) increases CPU load; recommend 500-2000ms for normal applications
