This project demonstrates how to interface an MPU6050 6-DOF IMU sensor with a CH552 microcontroller over I2C and stream formatted gyroscope, accelerometer, and temperature data via USB CDC. The stream is visualized using WebSerial and Processing.js in a 3D airplane model.
- USB CDC interface
- JSON-formatted IMU data
- Real-time visualization with WebSerial + Processing.js
- Built using a minimal CH552 firmware and open web technologies
The CH552 initializes the MPU6050 via I2C, then enters a loop to read:
* Acceleration (`accel[x, y, z]`)
* Gyroscope (`gyro[x, y, z]`)
* Temperature (`temp`)
Each 100 ms, the data is sent over USB CDC as a single-line JSON string.
{"accel":{"x":123,"y":456,"z":789},"gyro":{"x":12,"y":34,"z":56},"temp":2800}
Firmware Highlights
- Fully interrupt-driven USB stack (usb\_cdc)
- Raw I2C communication with MPU6050
- Output format: plain JSON + new line
> Based on Stefan Wagner's CH552 USB Terminal + Custom Modifications
WebSerial + Visualization (HTML + Processing.js)https://unit-electronics-mx.github.io/unit_cocket_nova_gyro_webviewer/
This HTML/JS sketch connects to the CH552 via the Web Serial API. It reads and parses each JSON line, then:
- Converts `gyro[x, y, z]` to degrees per second
- Integrates angular velocity over time
- Updates a 3D airplane rendered in Processing.js
* Real-time display of gyroscope values
* 3D airplane with horizon lines
> Compatible with latest Chrome/Edge (Web Serial API support required)
1. Flash the firmware to CH552 using `wchisp` or Docker SDK
2. Connect CH552 to USB
3. Open the HTML file in a Chromium-based browser
4. Click "Conectar Serial" and allow access to `/dev/ttyACMx`
5. Move the board and watch the airplane respond in real time
Future Enhancements
- Kalman/complementary filter for pitch/roll/yaw
- Additional HUD indicators
- Logging sensor data for offline replay
- Multi-sensor fusion (GPS + barometer)
Comments