2025-06-11 08:29:59 +01:00
|
|
|
|
[](https://github.com/derdoktor667/DShotRMT/actions/workflows/esp32.yml)
|
2023-03-30 17:58:19 +01:00
|
|
|
|
|
2025-06-11 08:29:59 +01:00
|
|
|
|
# DShot ESP32 Library using RMT (Rewrite for ESP-IDF 5)
|
2025-04-17 15:48:27 +01:00
|
|
|
|
|
2025-06-11 08:29:59 +01:00
|
|
|
|
This is a complete rewrite of the original DShotRMT library to support the new ESP-IDF 5 RMT encoder API (`rmt_tx.h`).
|
|
|
|
|
|
The library sends continuous DShot frames with a configurable pause between them and supports all standard DShot modes (150, 300, 600).
|
2021-06-29 19:05:20 +01:00
|
|
|
|
|
2025-06-11 08:29:59 +01:00
|
|
|
|
The old Version without encoding (rmt.h) is still available by using "oldAPI" Branch.
|
2021-06-29 19:05:20 +01:00
|
|
|
|
|
2025-06-11 08:29:59 +01:00
|
|
|
|
---
|
2021-07-26 21:20:49 +01:00
|
|
|
|
|
2025-06-11 08:29:59 +01:00
|
|
|
|
## The DShot Protocol
|
2021-07-26 21:20:49 +01:00
|
|
|
|
|
2025-06-11 08:29:59 +01:00
|
|
|
|
The DShot protocol transmits 16-bit packets to brushless ESCs:
|
2021-07-26 21:20:49 +01:00
|
|
|
|
|
2025-06-11 08:29:59 +01:00
|
|
|
|
- 11-bit throttle value
|
|
|
|
|
|
- 1-bit telemetry request
|
|
|
|
|
|
- 4-bit checksum
|
2021-07-26 21:20:49 +01:00
|
|
|
|
|
2025-06-11 08:29:59 +01:00
|
|
|
|
Data is transmitted MSB-first. Pulse timing depends on the selected DShot mode.
|
2021-07-26 21:20:49 +01:00
|
|
|
|
|
2025-06-11 08:29:59 +01:00
|
|
|
|
| DSHOT | Bitrate | TH1 | TH0 | Bit Time (µs) | Frame Time (µs) |
|
|
|
|
|
|
|-------|-------------|-------|--------|---------------|-----------------|
|
|
|
|
|
|
| 150 | 150 kbit/s | 5.00 | 2.50 | 6.67 | ~106.72 |
|
|
|
|
|
|
| 300 | 300 kbit/s | 2.50 | 1.25 | 3.33 | ~53.28 |
|
|
|
|
|
|
| 600 | 600 kbit/s | 1.25 | 0.625 | 1.67 | ~26.72 |
|
2021-07-26 21:20:49 +01:00
|
|
|
|
|
2025-06-11 08:29:59 +01:00
|
|
|
|
Each frame is followed by a 21-bit time pause at low level. This helps ESCs detect separate frames.
|
2021-07-26 21:20:49 +01:00
|
|
|
|
|
2025-06-11 08:29:59 +01:00
|
|
|
|
---
|
2021-07-26 21:20:49 +01:00
|
|
|
|
|
2025-06-11 08:29:59 +01:00
|
|
|
|
## Checksum Calculation
|
2023-03-29 21:12:08 +01:00
|
|
|
|
|
2025-06-11 08:29:59 +01:00
|
|
|
|
The checksum is calculated over the first 12 bits (throttle + telemetry):
|
|
|
|
|
|
|
|
|
|
|
|
```c
|
|
|
|
|
|
crc = (value ^ (value >> 4) ^ (value >> 8)) & 0x0F;
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
For Bidirectional DShot (not yet implemented), the CRC is inverted:
|
|
|
|
|
|
|
|
|
|
|
|
```c
|
|
|
|
|
|
crc = (~(value ^ (value >> 4) ^ (value >> 8))) & 0x0F;
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## RMT on the ESP32
|
|
|
|
|
|
|
|
|
|
|
|
The RMT peripheral on the ESP32 is perfect for generating precise time-based signals like DShot.
|
|
|
|
|
|
|
|
|
|
|
|
### Advantages:
|
|
|
|
|
|
|
|
|
|
|
|
- Hardware-timed pulses
|
|
|
|
|
|
- CPU-independent signal generation
|
|
|
|
|
|
- Loop mode with inter-frame pause
|
|
|
|
|
|
- Reliable under system load
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## About This Library
|
|
|
|
|
|
|
|
|
|
|
|
This C++ library provides a simple class to generate DShot signals using any RMT-capable GPIO.
|
|
|
|
|
|
It uses a `copy_encoder` to continuously send a prebuilt symbol buffer. New throttle values are applied only when they change.
|
|
|
|
|
|
|
|
|
|
|
|
### Supported Modes:
|
|
|
|
|
|
|
|
|
|
|
|
- DSHOT150
|
|
|
|
|
|
- DSHOT300 (default)
|
|
|
|
|
|
- DSHOT600
|
|
|
|
|
|
|
|
|
|
|
|
### Frame Structure:
|
|
|
|
|
|
|
|
|
|
|
|
- 16-bit DShot data
|
|
|
|
|
|
- 21-bit times worth of pause (LOW)
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## References
|
|
|
|
|
|
|
|
|
|
|
|
- [DSHOT – the missing Handbook](https://brushlesswhoop.com/dshot-and-bidirectional-dshot/)
|
|
|
|
|
|
- [DSHOT in the Dark](https://dmrlawson.co.uk/index.php/2017/12/04/dshot-in-the-dark/)
|
2023-03-29 21:12:08 +01:00
|
|
|
|
- [ESP32 Technical Reference Manual](https://www.espressif.com/sites/default/files/documentation/esp32_technical_reference_manual_en.pdf)
|
2025-06-11 08:29:59 +01:00
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## License
|
|
|
|
|
|
|
|
|
|
|
|
MIT License – see LICENSE
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## Author
|
|
|
|
|
|
|
|
|
|
|
|
Wastl Kraus
|
|
|
|
|
|
GitHub: [@derdoktor667](https://github.com/derdoktor667)
|
|
|
|
|
|
Website: [wir-sind-die-matrix.de](https://wir-sind-die-matrix.de)
|