A real-time vehicle driving status detection system based on the QuecPython embedded platform, utilizing the MPU6500 sensor and a Random Forest classifier.
This TinyML system employs machine learning directly on embedded hardware to detect vehicle driving status in real time. The system uses a small sensor called MPU6500 to measure motion and rotation, and it is currently optimized for motion along the X-axis, Y-axis, Z-axis, and gyroscopic motion.
- Real-time Detection: Recognition response time ranges from 150ms to 300ms
- Memory Efficiency: Automatic buffer management with overflow prevention
- False Alarm Prevention: Requires 3 consecutive consistent results before detection confirmation
- Timer-based Processing: Non-blocking hardware timer architecture
- Gesture Separation: Independent analysis of each gesture to avoid mutual interference
tinyml-car/
├── src
├── _main.py # Main application based on the timer system
├── mpu6500.py # MPU6500 sensor driver with m/s² scaling
├── random_forest.py # Pre-trained random forest model
├── tinyml.py # TinyML pipeline with anti-shake mechanism
├── fw
├── LICENSE
├── README.md
└── README_zh.md
- Platform: Quectel embedded module running MicroPython
- Sensor: MPU6500 6-axis IMU (3-axis accelerometer + 3-axis gyroscope)
- Model: Random Forest classifier (4 categories: 1 = driving on flat ground, 2 = uphill, 3 = downhill, 4 = skidding)
- Sampling: 50Hz sensor reading, 20Hz inference
- Detection: 3 consecutive consistent results within a 450ms window
- Data Format: Accelerometer (m/s²), Gyroscope (deg/s)
- X/Y/Z-axis Motion - Reliable operation and stable detection
- Memory Management - Buffer contamination issue resolved
- Real-time Processing - Timer-based architecture implemented
- Anti-shake System - False alarm prevention function working properly
- Circular Motion - Currently under development
Before you start, please ensure you have the following prerequisites:
- Hardware:
- A QuecPython development board
- A computer (Windows 7, Windows 10, or Windows 11)
- An MPU6500 sensor
- Software:
- Clone the repository:
git clone https://github.com/aaronchenzhihe/Tinyml-car.git
2.Flash the firmware: Flash the firmware to the development board according to the instructions.
- Hardware Connection: Correctly connect the MPU6500 sensor to the I2C interface of the development board.
- Connect to the host computer via Type-C cable.
- Download the code to the device:
- Launch the QPYcom debugging tool.
- Connect the data cable to the computer.
- Press the PWRKEY button on the development board to power it on.
- Import all files in the
srcfolder into the module's file system while maintaining the directory structure, following the instructions.
- Run the code
- Select the
Filetab. - Select the
_main.pyscript. - Right-click and select
Runto execute the script.
- Select the
The system automatically performs real-time detection. When a vehicle driving status is recognized, it outputs the classification result (1, 2, 3, 4) and clears all buffers to prevent interference from previous results.
- Detection Latency: Theoretical minimum of 150ms, actual range of 200-300ms
- Memory Usage: Total < 50KB
- Accuracy: Optimized for X/Y/Z-axis motion and gyroscopic motion