Arduino additions

This commit is contained in:
Mikkeli Matlock
2026-02-01 11:47:37 +09:00
parent 559e62e292
commit f610f0fed2
4 changed files with 197 additions and 5 deletions

78
arduino/IMU.md Normal file
View File

@@ -0,0 +1,78 @@
# WT61 IMU Quick Reference
6-axis IMU (accelerometer + gyroscope) with onboard angle calculation via Kalman filter.
## Serial Configuration
| Setting | Factory Default | Our Config |
|---------|-----------------|------------|
| Baud rate | 115200 | 9600 |
| Output rate | 100Hz | 20Hz |
**Config command** (send at 115200 to switch to 9600/20Hz):
```
0xFF 0xAA 0x64
```
This is saved to flash - persists across power cycles.
## Wiring (ATmega328P / AltSoftSerial)
| WT61 Pin | Arduino Pin | Notes |
|----------|-------------|-------|
| TX | 8 (RX) | AltSoftSerial fixed pin |
| RX | 9 (TX) | Only needed for config commands |
| VCC | 5V | |
| GND | GND | |
## Packet Structure
11 bytes per packet, continuous stream (3 packet types interleaved):
```
Byte 0: 0x55 (header)
Byte 1: Packet type
Bytes 2-3: Value 0 (int16_t, little-endian)
Bytes 4-5: Value 1
Bytes 6-7: Value 2
Bytes 8-9: Temperature (usually ignored)
Byte 10: Checksum (sum of bytes 0-9, lower 8 bits)
```
### Packet Types
| Type | Byte 1 | V0 | V1 | V2 |
|------|--------|----|----|-----|
| Acceleration | 0x51 | ax | ay | az |
| Gyroscope | 0x52 | gx | gy | gz |
| Angle | 0x53 | roll | pitch | yaw |
## Scale Factors
| Measurement | Formula | Range |
|-------------|---------|-------|
| Acceleration | `raw / 32768.0 * 16.0` | +/-16g |
| Gyroscope | `raw / 32768.0 * 2000.0` | +/-2000 deg/s |
| Angle | `raw / 32768.0 * 180.0` | +/-180 deg |
| Temperature | `raw / 340.0 + 36.25` | Celsius |
## Known Quirks
- **Boot time**: Module needs ~200-500ms after power-on before sending valid data
- **Config at wrong baud**: Commands sent at wrong baud rate are ignored (garbled bytes) - this is actually useful for idempotent config-on-boot
- **AltSoftSerial at 115200**: Technically out of spec for 16MHz AVR, but TX-only bursts of a few bytes work fine. Don't try sustained RX at that rate.
## Commands
All commands are 3 bytes: `0xFF 0xAA <data>`
| Data Byte | Function | Notes |
|-----------|----------|-------|
| 0x52 | Zero Z-axis angle | Resets yaw to 0 |
| 0x67 | Accelerometer calibration | Keep module level, zeros X/Y |
| 0x60 | Toggle sleep mode | Toggles between standby and active |
| 0x61 | Serial mode | Enable UART, disable I2C |
| 0x62 | I2C mode | Enable I2C, disable UART |
| 0x63 | 115200 baud / 100Hz | Factory default |
| 0x64 | 9600 baud / 20Hz | Our config |
| 0x65 | Horizontal mounting | Module placed flat |
| 0x66 | Vertical mounting | Module placed upright |