01
Project Overview VIEN
🇬🇧 ENGLISH
The ESP32-C6 Multi-Sensor IMU Module is a comprehensive IoT measurement platform combining four industrial-grade inertial and position sensors on a single ESP32-C6 board. It delivers high-speed vibration monitoring, inclinometry, 6-axis motion tracking, and magnetic field sensing — all accessible via Wi-Fi 6 (WebSocket / REST) or Bluetooth 5.0 BLE streaming.
🇻🇳 TIẾNG VIỆT
ESP32-C6 Multi-Sensor IMU Module là nền tảng đo lường IoT toàn diện, kết hợp bốn cảm biến quán tính và vị trí cấp công nghiệp trên một bo mạch ESP32-C6 duy nhất. Hệ thống cung cấp giám sát rung động tốc độ cao, đo góc nghiêng, theo dõi chuyển động 6 trục và cảm biến từ trường — tất cả đều truy cập qua Wi-Fi 6 (WebSocket / REST) hoặc BLE 5.0.
System Architecture Kiến trúc hệ thống
POWER SYSTEM
LiPo charge + SMPS 3.3V
Battery monitor
Battery monitor
MCU: ESP32-C6
RISC-V 160MHz
Wi-Fi 6 + BLE 5.0
Wi-Fi 6 + BLE 5.0
SENSOR ARRAY
4× sensors via SPI/I2C
DMA transfers
DMA transfers
FreeRTOS TASKS
Sensor read, FIFO mgmt
WebSocket, BLE tasks
WebSocket, BLE tasks
WI-FI 6 INTERFACE
HTTP REST + WebSocket
Real-time data stream
Real-time data stream
BLE 5.0 / 2M PHY
NOTIFY streaming
Python dashboard
Python dashboard
Use Cases Ứng dụng
Vibration Analysis
Structural Health Monitoring
Tilt / Inclinometry
Gesture Recognition
Fitness Tracking
Machine Learning Data Collection
Drone IMU Testing
Industrial IoT
02
Hardware Architecture VI
MCU Specifications — ESP32-C6 Thông số MCU
| Parameter | Value | Notes |
|---|---|---|
| CPU Core | RISC-V 32-bit | Single core, up to 160MHz |
| Flash | 4 MB (typ) | Quad SPI |
| SRAM | 512 KB | General + LP SRAM 16 KB |
| Wi-Fi | 802.11ax (Wi-Fi 6) | 2.4 GHz, 802.11b/g/n/ax |
| Bluetooth | BLE 5.0 | LE 1M / 2M PHY, Long Range |
| GPIO | 22 × multiplex | Including SPI/I2C/UART/USB |
| SPI | 2 × SPI master | DMA-capable, up to 80MHz |
| I2C | 2 × I2C | Standard / Fast / Fast-Plus mode |
| USB | USB 1.1 Full-Speed | JTAG + CDC/ACM |
| Operating voltage | 3.0V – 3.6V | Nominal 3.3V |
GPIO Pin Map Bản đồ chân GPIO
📌 GPIO ASSIGNMENT
Each sensor shares the same SPI bus (MOSI GPIO7, SCLK GPIO6) but has dedicated CS pins for chip selection. IIS2MDC uses I2C on GPIO22/23.
📌 PHÂN CÔNG GPIO
Mỗi cảm biến dùng chung bus SPI (MOSI GPIO7, SCLK GPIO6) nhưng có chân CS riêng. IIS2MDC sử dụng I2C trên GPIO22/23.
| GPIO | Function | Sensor | Protocol | Direction |
|---|---|---|---|---|
GPIO23 | SDA | IIS2MDC | I2C | Bidirectional (4.7kΩ pull-up) |
GPIO22 | SCL | IIS2MDC | I2C | Output (4.7kΩ pull-up) |
GPIO7 | MOSI / SDI | IIS3DWB, ICM45686, SCL3300 | SPI | Output |
GPIO6 | SCLK / SCK | IIS3DWB, ICM45686, SCL3300 | SPI | Output |
GPIO4 | MISO / SDO | IIS3DWB, ICM45686, SCL3300 | SPI | Input |
GPIO19 | CS | IIS3DWB | SPI | Output (active LOW) |
GPIO5 | CS | ICM45686 | SPI | Output (active LOW) |
GPIO20 | CS | SCL3300 | SPI | Output (active LOW) |
📝 SPI Bus Sharing Note: All three SPI sensors share the same MOSI/MISO/CLK lines. CS pins are de-asserted (HIGH) when not selected. Ensure SPI transaction completion before switching CS — use esp_spi_bus_acquire_device() for thread safety in FreeRTOS context.
03
Sensor Reference VI
IIS2MDC
Magnetometer — STMicroelectronics
100Hz max ODR
Interface: I2C (Addr: 0x1E)
Range: ±50 gauss | Sensitivity: 1.5 mgauss/LSB
Features: Temperature compensation, low-noise mode
Supply: 1.71V – 3.6V | Current: 100µA typ
Range: ±50 gauss | Sensitivity: 1.5 mgauss/LSB
Features: Temperature compensation, low-noise mode
Supply: 1.71V – 3.6V | Current: 100µA typ
IIS3DWB
High-Speed Accelerometer — STMicroelectronics
26.7kHz max ODR
Interface: SPI (CS: GPIO19)
Range: ±2 / ±4 / ±8 / ±16g | Sensitivity: 0.061 mg/LSB @±2g
Features: FIFO 3072 bytes, wideband single-axis
Supply: 1.71V – 3.6V | Current: 0.55mA typ
Range: ±2 / ±4 / ±8 / ±16g | Sensitivity: 0.061 mg/LSB @±2g
Features: FIFO 3072 bytes, wideband single-axis
Supply: 1.71V – 3.6V | Current: 0.55mA typ
ICM-45686
6-Axis IMU — InvenSense (TDK)
6.4kHz Gyro ODR
Interface: SPI (CS: GPIO5)
Gyro: ±125/250/500/1000/2000 dps | Accel: ±2/4/8/16g
Features: APEX (tap, tilt, wake-on-motion, pedometer)
Supply: 1.71V – 3.6V | Current: 0.55mA typ
Gyro: ±125/250/500/1000/2000 dps | Accel: ±2/4/8/16g
Features: APEX (tap, tilt, wake-on-motion, pedometer)
Supply: 1.71V – 3.6V | Current: 0.55mA typ
SCL3300
Inclinometer — Murata
1kHz max ODR
Interface: SPI (CS: GPIO20)
Range: ±10° / ±30° / ±90° (4 modes)
Features: CRC-8 on every frame, MEMS tilt compensation
Supply: 2.7V – 3.6V | Current: 3mA typ
Range: ±10° / ±30° / ±90° (4 modes)
Features: CRC-8 on every frame, MEMS tilt compensation
Supply: 2.7V – 3.6V | Current: 3mA typ
Sensor Register Quick Reference Tham chiếu thanh ghi nhanh
| Sensor | Register | Address (hex) | Purpose |
|---|---|---|---|
| IIS2MDC | CFG_REG_A | 0x60 | ODR, operating mode, temp comp |
| IIS2MDC | STATUS_REG | 0x67 | Data ready flags |
| IIS2MDC | OUTX_L_REG | 0x68 | Mag X low byte (burst read 6B) |
| IIS3DWB | CTRL1_XL | 0x10 | ODR, FS range selection |
| IIS3DWB | FIFO_CTRL4 | 0x0A | FIFO mode, watermark |
| IIS3DWB | FIFO_DATA_OUT | 0x79 | 16-bit FIFO output word |
| ICM45686 | PWR_MGMT0 | 0x10 | Gyro / Accel power mode |
| ICM45686 | ACCEL_CONFIG0 | 0x1B | Accel ODR and FS |
| ICM45686 | APEX_CONFIG0 | 0x25 | Enable APEX features |
| SCL3300 | CMD_READ_ACC_X | 0x040000F7 | 32-bit SPI frame: X-axis |
| SCL3300 | CMD_CHANGE_BANK | 0xFC000073 | Switch register bank |
04
Schematic Hardware Review VI
📋 REVIEW SCOPE
ElectroAgent hardware review of the uploaded ESP32_IMU_Module.pdf schematic (3 blocks: POWER, MCU, SENSOR). Partial view — full net-level review requires KiCad source.
📋 PHẠM VI REVIEW
ElectroAgent review phần cứng từ schematic ESP32_IMU_Module.pdf đã tải lên (3 khối: POWER, MCU, SENSOR). Review ở mức hiển thị — cần file KiCad để review toàn bộ net.
| # | Severity | Block / Net | Finding | Recommended Fix VI: Cách sửa |
|---|---|---|---|---|
| 01 | CRITICAL | SENSOR / U3 | U3 component crossed out with red X marker — indicates DNP (Do Not Populate) or design revision. Footprint / net connections may be orphaned. | Confirm DNP intent. Remove nets or add DNP annotation. Verify no floating pads on PCB layer. Xác nhận ý định DNP. Xóa net hoặc thêm chú thích DNP. Kiểm tra không có pad nổi trên lớp PCB. |
| 02 | WARN | POWER / VBAT_OUT | LiPo charger IC visible (TP4056 class). Need to verify CHRG/STDBY status LED current limiting resistors and thermal via count under IC. | Add 2 thermal vias under charger pad. LED resistors: R = (3.3V−Vf) / 5mA. Thêm 2 via nhiệt dưới pad charger. Điện trở LED: R = (3.3V−Vf) / 5mA. |
| 03 | WARN | POWER / SMPS | Boost/buck converter visible (likely MP2307/XL7015 class). Verify feedback resistor divider for 3.3V output; confirm output capacitor ESR within SMPS stability spec. | R_high/R_low for Vout = 3.3V per IC datasheet. Use 47µF/10µF MLCC output caps with ESR < 0.1Ω. Dùng MLCC 47µF/10µF, ESR < 0.1Ω tại đầu ra. |
| 04 | WARN | MCU / BOOT + RESET | ESP32-C6 BOOT and RESET buttons visible. Verify 100nF debounce capacitor on each switch and 10kΩ pull-up to VDD_IO on RESET. | C_debounce = 100nF to GND. R_pullup = 10kΩ on EN/RESET. Thêm 100nF xuống GND và 10kΩ kéo lên VDD trên RESET/EN. |
| 05 | WARN | SENSOR / SPI CS lines | Multiple SPI CS lines — confirm each has a 10kΩ pull-up to 3.3V so sensors remain deselected during ESP32-C6 boot (GPIO floating state). | Add 10kΩ pull-up on CS_IIS3DWB (GPIO19), CS_ICM (GPIO5), CS_SCL3300 (GPIO20). Thêm điện trở kéo lên 10kΩ cho mỗi chân CS. |
| 06 | INFO | SENSOR / I2C bus | IIS2MDC I2C lines (GPIO22/23) — ensure 4.7kΩ pull-up to 3.3V. Faster I2C speeds (400kHz Fast-mode) require lower pull-up to overcome bus capacitance. | Use 4.7kΩ for Standard (100kHz). Use 2.2kΩ for Fast-mode (400kHz). Dùng 4.7kΩ cho 100kHz, 2.2kΩ cho 400kHz Fast-mode. |
| 07 | INFO | MCU / USB_D± lines | USB connector visible. Verify D+/D- 22Ω series resistors for impedance matching and ESD TVS diodes (PRTR5V0U2X class) at connector entry. | Add 22Ω series resistors on D+/D−. Place PRTR5V0U2X TVS at USB connector pins. Thêm 22Ω nối tiếp và TVS tại chân USB. |
| 08 | INFO | ALL / Decoupling | Confirm 100nF + 10µF decoupling on every VDD pin of each sensor IC. Placement: <1mm from IC power pin. | 100nF 0402 MLCC + 10µF 0805 per VDD pin. Place closest layer to IC. 100nF 0402 + 10µF 0805 mỗi chân VDD. Đặt sát chân IC nhất có thể. |
🔴 Action Required: U3 (crossed-out component in SENSOR block) must be resolved before PCB ordering. Orphaned pads can cause solder bridges and assembly defects. Confirm with team whether this is a future sensor option or fully removed.
Thành phần U3 bị gạch X cần xử lý trước khi đặt hàng PCB. Pad cô đơn có thể gây ngắn mạch hàn.
Thành phần U3 bị gạch X cần xử lý trước khi đặt hàng PCB. Pad cô đơn có thể gây ngắn mạch hàn.
05
Firmware Options VI
ESP32C6_IMU_WebMonitor
Unified WiFi + BLE monitoring. Web dashboard with REST API and WebSocket. Best for desktop monitoring and data logging.
ESP32C6_IMU_BLEStreamer
BLE-only streaming. Lower power than WiFi. Designed for mobile apps and Python BLE dashboard. 2M PHY for maximum throughput.
ESP32C6_IIS3_WebMonitor_HighSpeed
Optimized for IIS3DWB 26.7kHz sampling. FIFO watermark interrupt driven. Dedicated to vibration analysis workloads.
Individual Sensor Tests
Standalone test projects per sensor. Use for driver validation, calibration, and hardware bring-up. Includes serial logging.
Firmware Selection Guide Hướng dẫn chọn firmware
| Use Case | Recommended Firmware | Reason |
|---|---|---|
| Vibration analysis (machinery) | IIS3_WebMonitor_HighSpeed | 26.7kHz ODR + FIFO |
| Multi-sensor IoT dashboard | IMU_WebMonitor | All sensors, REST + WebSocket |
| Mobile app / BLE device | IMU_BLEStreamer | No router needed, 2M PHY |
| Driver development / debug | Individual sensor tests | Isolated, easy to modify |
| ML data collection | IMU_WebMonitor + CSV export | Multi-sensor, timestamped |
06
FreeRTOS Architecture VI
⚙️ TASK DESIGN PRINCIPLES
The firmware uses FreeRTOS with priority-based scheduling. High-priority tasks handle sensor DMA interrupts and FIFO draining. Lower priority tasks manage networking and UI updates. All sensor data flows through queue/ringbuffer primitives.
⚙️ NGUYÊN TẮC THIẾT KẾ TASK
Firmware sử dụng FreeRTOS với lập lịch theo ưu tiên. Task ưu tiên cao xử lý ngắt DMA cảm biến và xả FIFO. Task ưu tiên thấp quản lý mạng và UI. Toàn bộ dữ liệu cảm biến chảy qua queue/ringbuffer.
Recommended Task Architecture Kiến trúc task gợi ý
sensor_iis3dwb_task
Priority 5 (REALTIME)
Stack: 4096B | Core: 0
sensor_icm45686_task
Priority 4 (HIGH)
Stack: 4096B | Core: 0
sensor_iis2mdc_task
Priority 3 (NORMAL)
Stack: 2048B | Core: 0
sensor_scl3300_task
Priority 3 (NORMAL)
Stack: 2048B | Core: 0
websocket_server_task
Priority 2 (LOW)
Stack: 8192B | Core: 1
ble_notify_task
Priority 2 (LOW)
Stack: 4096B | Core: 1
FIFO & DMA Data Flow Luồng dữ liệu FIFO & DMA
IIS3DWB FIFO
Watermark IRQ
Watermark IRQ
→
SPI DMA
Burst Read
Burst Read
→
RingBuffer
xRingbufferSend()
xRingbufferSend()
→
Processing
Task
Task
→
WebSocket
/ BLE TX
/ BLE TX
main.c — FreeRTOS task creation pattern
C
// ── SENSOR TASK CREATION ──────────────────────────────────── // [VI] Khởi tạo task cảm biến với ưu tiên và stack hợp lý static RingbufHandle_t sensor_ring_buf; void app_main(void) { // Create shared ring buffer (4096 bytes) sensor_ring_buf = xRingbufferCreate(4096, RINGBUF_TYPE_BYTEBUF); // IIS3DWB high-speed task — highest priority xTaskCreatePinnedToCore( iis3dwb_task, // task function "iis3dwb", // task name 4096, // stack bytes NULL, // parameters 5, // priority (5 = highest) NULL, // task handle 0 // core 0 ); // WebSocket server — low priority, core 1 xTaskCreatePinnedToCore( ws_server_task, "ws_srv", 8192, NULL, 2, NULL, 1 ); } // ── FIFO READ with DMA ─────────────────────────────────────── void iis3dwb_task(void *arg) { uint8_t fifo_data[512]; while(1) { ulTaskNotifyTake(pdTRUE, portMAX_DELAY); // Wait for FIFO watermark IRQ uint16_t fifo_count = iis3dwb_get_fifo_num_samples(); iis3dwb_spi_dma_read(fifo_data, fifo_count * 2); xRingbufferSend(sensor_ring_buf, fifo_data, fifo_count * 2, 0); } }
07
Build & Flash Guide VI
Step 1 — Prerequisites Điều kiện tiên quyết
📦 REQUIREMENTS
ESP-IDF v5.4 (mandatory for ESP32-C6 support), Python 3.11+, Git with submodules, USB-C cable for flashing, 3.3V regulated power during standalone operation.
📦 YÊU CẦU
ESP-IDF v5.4 (bắt buộc cho ESP32-C6), Python 3.11+, Git với submodule, cáp USB-C để nạp firmware, nguồn 3.3V ổn định khi chạy độc lập.
Terminal — ESP-IDF installation
bash
# [VI] Bước 1: Clone ESP-IDF v5.4 git clone --recursive https://github.com/espressif/esp-idf.git cd esp-idf git checkout v5.4 ./install.sh esp32c6 # Install tools for ESP32-C6 target source ./export.sh # Activate IDF environment # [VI] Bước 2: Clone dự án IMU git clone https://github.com/hbqtechnologycompany/ESP32-C6-Multi-Sensor-IMU-Module.git cd ESP32-C6-Multi-Sensor-IMU-Module # [VI] Bước 3: Cấu hình WiFi trong main.c # Edit: #define WIFI_SSID "YOUR_SSID" / #define WIFI_PASS "YOUR_PASS"
Terminal — Build, Flash, Monitor
bash
# ── Web Monitor (WiFi + BLE) ───────────────────────────────── cd ESP32C6_IMU_WebMonitor idf.py set-target esp32c6 # Set target chip idf.py menuconfig # Optional: adjust config (WiFi, log levels) idf.py build # Compile (~2-5 min first build) idf.py -p /dev/ttyUSB0 flash # Flash via USB (Linux; use COMx on Windows) idf.py -p /dev/ttyUSB0 monitor # Open serial monitor (Ctrl+] to exit) # ── High-Speed Vibration (IIS3DWB only) ────────────────────── cd ../ESP32C6_IIS3_WebMonitor_HighSpeed idf.py build flash monitor -p /dev/ttyUSB0 # ── BLE Streamer ───────────────────────────────────────────── cd ../ESP32C6_IMU_BLEStreamer idf.py build flash monitor -p /dev/ttyUSB0
💡 Windows Users: Replace
[VI] Trên Windows: thay
/dev/ttyUSB0 with COM3 (or your port). Install CP2102/CH340 driver from Silicon Labs if port not detected. Use Device Manager → Ports to identify.
[VI] Trên Windows: thay
/dev/ttyUSB0 bằng COM3 (hoặc cổng tương ứng). Cài driver CP2102/CH340 nếu không nhận cổng.
WiFi Configuration Cấu hình WiFi
main.c — WiFi credentials
C
// [VI] Cập nhật thông tin WiFi trước khi build #define WIFI_SSID "YOUR_WIFI_SSID" // 2.4GHz only for ESP32-C6 #define WIFI_PASS "YOUR_WIFI_PASSWORD" #define WIFI_MAX_RETRY 5 // Retry before AP mode fallback // After flash, open browser: http://<ESP_IP_ADDRESS> // Find IP in serial monitor after connection: // I (3421) wifi: connected to AP, IP: 192.168.x.x
08
REST API & WebSocket VI
REST Endpoints Các endpoint REST
GET
/api/data
Latest sensor readings (JSON)
GET
/api/stats
Buffer stats, frame count, errors
POST
/api/config
Update sensor config (ODR, range, mode)
GET
/api/download?format=csv
Export buffered data as CSV
GET
/api/download?format=json
Export buffered data as JSON
JSON Data Format Định dạng dữ liệu JSON
GET /api/data — Response example
JSON
{
"timestamp_ms": 1735000000123,
"iis2mdc": {
"mx_gauss": 0.042, "my_gauss": -0.018, "mz_gauss": 0.391,
"temp_c": 25.3, "data_ready": true
},
"iis3dwb": {
"ax_g": -0.012, "ay_g": 0.003, "az_g": 0.981,
"odr_hz": 26667, "fifo_samples": 512
},
"icm45686": {
"ax_g": -0.011, "ay_g": 0.002, "az_g": 0.979,
"gx_dps": 0.12, "gy_dps": -0.08, "gz_dps": 0.21,
"apex_tap": false, "apex_wom": false
},
"scl3300": {
"angle_x_deg": 1.24, "angle_y_deg": -0.31,
"angle_z_deg": 89.97, "crc_ok": true, "mode": 1
}
}
WebSocket Protocol Giao thức WebSocket
JavaScript — WebSocket client example
JS
// [VI] Kết nối WebSocket để nhận dữ liệu cảm biến realtime const ws = new WebSocket('ws://192.168.1.x/ws'); ws.onopen = () => console.log('Connected to ESP32-C6 IMU'); ws.onmessage = (event) => { const data = JSON.parse(event.data); // Access sensor values console.log('Accel Z:', data.iis3dwb.az_g, 'g'); console.log('Tilt X:', data.scl3300.angle_x_deg, '°'); }; ws.onerror = (err) => console.error('WS Error:', err);
09
BLE 5.0 Protocol VI
📶 BLE CONFIGURATION
The BLE firmware uses GATT NOTIFY characteristics to push sensor frames to connected clients at high speed. 2M PHY is used for maximum data throughput (~1 Mbps effective). The device advertises as "ESP32-IMU-xxxx" (last 4 hex of MAC).
📶 CẤU HÌNH BLE
Firmware BLE sử dụng đặc tính GATT NOTIFY để đẩy frame cảm biến đến client tốc độ cao. PHY 2M được dùng để đạt thông lượng tối đa (~1 Mbps hiệu dụng). Thiết bị quảng bá với tên "ESP32-IMU-xxxx" (4 ký tự hex cuối của MAC).
GATT Service Layout Cấu trúc GATT Service
| Service / Characteristic | UUID | Properties | Description |
|---|---|---|---|
| IMU Service | 0x1234 (custom) | — | Root service for all IMU data |
| ├ Sensor Data | 0x1235 | NOTIFY | Packed sensor frame (binary, 40 bytes) |
| ├ Config Write | 0x1236 | WRITE | Set ODR, range, active sensors |
| └ Status Read | 0x1237 | READ | Frame count, error count, uptime |
BLE Frame Format Định dạng frame BLE
BLE binary frame (40 bytes, little-endian)
C
// [VI] Cấu trúc frame BLE 40 bytes (little-endian) typedef struct __attribute__((packed)) { uint32_t timestamp_ms; // bytes 0-3: ESP32 uptime ms int16_t iis3_ax; // bytes 4-5: IIS3DWB accel X (raw LSB) int16_t iis3_ay; // bytes 6-7: IIS3DWB accel Y int16_t iis3_az; // bytes 8-9: IIS3DWB accel Z int16_t icm_ax, icm_ay, icm_az; // bytes 10-15: ICM45686 accel int16_t icm_gx, icm_gy, icm_gz; // bytes 16-21: ICM45686 gyro int16_t mag_x, mag_y, mag_z; // bytes 22-27: IIS2MDC mag int16_t tilt_x, tilt_y, tilt_z; // bytes 28-33: SCL3300 tilt (0.01°/LSB) uint8_t status; // byte 34: bit flags [CRC_OK | WOM | TAP...] uint8_t reserved[5]; // bytes 35-39: future use / padding } imu_ble_frame_t; // Total: 40 bytes
10
Python BLE Dashboard VI
Dashboard Features Tính năng Dashboard
| Feature | Detail | Ghi chú [VI] |
|---|---|---|
| Auto-scan | Discovers ESP32-IMU-xxxx devices via BLE scan | Tự động tìm thiết bị BLE |
| 12-plot grid | 4 sensors × 3 axes (X/Y/Z) live charts | 12 biểu đồ trực tiếp |
| 2M PHY streaming | Up to ~500 frames/sec from BLE 5.0 | Tốc độ cao ~500 frame/giây |
| Light/Dark theme | Toggle in toolbar | Chuyển theme sáng/tối |
| CSV export | Save timestamped data to file | Xuất dữ liệu CSV |
| Standalone EXE | dist\ESP32-IMU-Dashboard.exe (Windows) | Không cần Python cài đặt |
Terminal — Setup Python dashboard
bash
# [VI] Cài đặt dashboard Python BLE cd ble-imu-dashboard pip install -r requirements.txt # bleak, matplotlib, numpy, PyQt6 python main.py # Launch dashboard # [VI] Build file .exe standalone (Windows) .\build_exe.ps1 # Output: dist\ESP32-IMU-Dashboard.exe # [VI] Chạy trên Linux/macOS (cần Bluetooth adapter) sudo python main.py # sudo required for BLE access on some distros
11
Power Management VI
Power States Các chế độ nguồn
ACTIVE (Full)
~120mA
WiFi TX + All 4 sensors
ACTIVE (BLE)
~35mA
BLE NOTIFY + All sensors
LIGHT SLEEP
~1.5mA
WiFi preserved, CPU halted
DEEP SLEEP
~15µA
RTC only, sensors off
Battery Life Estimate Ước tính tuổi thọ pin
Formula: Thours = Cbattery_mAh / Iavg_mA | Iavg = Σ(Imode × duty_cycle)
Example: 1000mAh LiPo, BLE streaming 80% + Light Sleep 20%:
Iavg = (35 × 0.8) + (1.5 × 0.2) = 28 + 0.3 = 28.3 mA
T = 1000 / 28.3 ≈ 35 hours
[VI] Ví dụ: Pin 1000mAh, BLE 80% + Light Sleep 20% → khoảng 35 giờ hoạt động.
Example: 1000mAh LiPo, BLE streaming 80% + Light Sleep 20%:
Iavg = (35 × 0.8) + (1.5 × 0.2) = 28 + 0.3 = 28.3 mA
T = 1000 / 28.3 ≈ 35 hours
[VI] Ví dụ: Pin 1000mAh, BLE 80% + Light Sleep 20% → khoảng 35 giờ hoạt động.
main.c — Light sleep implementation
C
// [VI] Kích hoạt Light Sleep giữa các chu kỳ đọc cảm biến #include "esp_sleep.h" void enter_light_sleep_ms(uint32_t ms) { esp_sleep_enable_timer_wakeup(ms * 1000ULL); // µs units esp_light_sleep_start(); // Execution resumes here after wakeup } // Usage in sensor task (read every 100ms, sleep between): while(1) { read_all_sensors(); publish_data(); enter_light_sleep_ms(90); // 90ms sleep, ~10Hz effective rate }
12
Sensor Fusion Guide VI
🔬 FUSION OVERVIEW
This module provides raw sensor data and is well-suited for implementing sensor fusion algorithms. ICM45686 (6-axis) combined with IIS2MDC (magnetometer) enables full 9-DoF AHRS (Attitude Heading Reference System). SCL3300 provides independent tilt verification.
🔬 TỔNG QUAN FUSION
Module cung cấp dữ liệu cảm biến thô, phù hợp để triển khai thuật toán sensor fusion. ICM45686 (6 trục) kết hợp IIS2MDC (từ kế) cho phép AHRS 9 bậc tự do hoàn chỉnh. SCL3300 cung cấp xác minh nghiêng độc lập.
Fusion Options Các thuật toán fusion
| Algorithm | DoF | CPU Cost | Latency | Best For |
|---|---|---|---|---|
| Complementary Filter | 6 | Very Low | <1ms | Simple tilt, low-resource systems |
| Madgwick Filter | 6/9 | Low | <2ms | Good accuracy, open-source, AHRS |
| Mahony Filter | 6/9 | Low | <2ms | Similar to Madgwick, slightly faster |
| Extended Kalman Filter | 9+ | Medium | 2-5ms | High accuracy, dynamic environments |
| ICM45686 APEX | On-chip | Zero | <1ms | Tap, step count, WoM — hardware offload |
main.c — Complementary filter (tilt estimation)
C
// [VI] Bộ lọc bù đơn giản kết hợp Accel + Gyro #define ALPHA 0.98f // Trust gyro 98%, accel 2% #define DT 0.001f // 1ms sample period (1kHz) float angle_x = 0.0f; void complementary_filter_update( float accel_x, float accel_z, float gyro_x_dps ) { float accel_angle = atan2f(accel_x, accel_z) * 57.2958f; // rad→deg float gyro_delta = gyro_x_dps * DT; angle_x = ALPHA * (angle_x + gyro_delta) + (1.0f - ALPHA) * accel_angle; // Result: angle_x in degrees, drift-corrected }
13
Troubleshooting Guide VI
| Symptom | Triệu chứng [VI] | Root Cause | Fix |
|---|---|---|---|
| I2C NACK on IIS2MDC | Không nhận được ACK từ từ kế | Missing pull-up / wrong address | Add 4.7kΩ to 3.3V on SDA/SCL. Check SA0 pin for address 0x1E vs 0x1C |
| SPI reads all 0xFF | SPI trả về 0xFF toàn bộ | CS not pulled low / MISO float | Verify CS GPIO output, check MISO 10kΩ pull-down, SPI mode CPOL/CPHA |
| FIFO overflow (IIS3DWB) | Tràn FIFO IIS3DWB | Processing too slow | Increase task priority. Reduce FIFO watermark. Enable DMA. Use FIFO_CTRL4 to limit samples. |
| SCL3300 CRC errors | Lỗi CRC SCL3300 | SPI timing / noise on CLK | Lower SPI clock to 4MHz for SCL3300. Add 33Ω series on SCLK. Check GND plane. |
| WiFi connect fails | Không kết nối WiFi | Wrong credentials / 5GHz | ESP32-C6 WiFi 6 is 2.4GHz only. Verify SSID/password. Check RSSI > -80dBm. |
| BLE device not found | Không tìm thấy BLE | Advertise name mismatch / BT off | Scan for "ESP32-IMU". Ensure BLEStreamer firmware flashed, not WebMonitor. |
| Build fails: ESP-IDF version | Build lỗi phiên bản ESP-IDF | Wrong IDF version | Must use ESP-IDF v5.4. Run: idf.py --version. Re-checkout v5.4. |
| Flash fails: Wrong port | Flash lỗi sai cổng COM | Driver not installed | Install CH340/CP2102 driver. On Linux: sudo usermod -aG dialout $USER. Logout/login. |
Debug Log Levels Cấp độ log debug
sdkconfig / menuconfig — Log level
bash
# [VI] Bật verbose logging để debug idf.py menuconfig # → Component Config → Log Output → Default log verbosity → VERBOSE # Or set at runtime in code: esp_log_level_set("IIS3DWB", ESP_LOG_DEBUG); esp_log_level_set("ICM45686", ESP_LOG_DEBUG); esp_log_level_set("WIFI", ESP_LOG_WARN); // Reduce WiFi noise
14
Contributing VI
🤝 HOW TO CONTRIBUTE
- Fork the repository on GitHub
- Create a feature branch:
git checkout -b feat/your-feature - Follow ESP-IDF coding style (snake_case, Doxygen comments)
- Add test coverage for new sensor drivers
- Submit a Pull Request with clear description
- Respond to review comments within 72h
🤝 CÁCH ĐÓNG GÓP
- Fork repository trên GitHub
- Tạo branch tính năng:
git checkout -b feat/ten-tinh-nang - Tuân theo coding style ESP-IDF (snake_case, Doxygen)
- Thêm test coverage cho driver cảm biến mới
- Gửi Pull Request với mô tả rõ ràng
- Phản hồi review trong 72 giờ
📁 Code Style: Use
[VI] Dùng clang-format với file style của Espressif. Tất cả hàm public phải có comment Doxygen đầy đủ.
clang-format with Espressif style file. Variable names: snake_case. All public functions must have Doxygen @brief/@param/@return comments. New sensors must include unit tests in the test/ directory.
[VI] Dùng clang-format với file style của Espressif. Tất cả hàm public phải có comment Doxygen đầy đủ.
15
Contact & Support VI
| Channel | Link / Info | Best For |
|---|---|---|
| GitHub Issues | GitHub Issues | Bug reports, feature requests |
| GitHub Discussions | Discussions | Questions, ideas, general chat |
| hbqsolution@gmail.com | contact@hbqsolution.com | Hardware orders, business | |
| Phone (VN) | (+84) 035 719 1643 | (+84) 094 850 7979 | Hardware support |
| Store | HBQ Technology Store | Buy hardware module |
| Address | 31, Đường số 8, Cityland Garden Hill, P. An Nhơn, TP HCM | Physical office (Vietnam) |
HBQ TECHNOLOGY
ESP32-C6 Multi-Sensor IMU Module · MIT License · Made with ❤️ in Vietnam