2025-08-27 15:50:55 +01:00
|
|
|
|
[](https://github.com/derdoktor667/DShotRMT/actions/workflows/ci.yml)
|
2023-03-30 17:58:19 +01:00
|
|
|
|
|
2025-07-19 15:41:04 +01:00
|
|
|
|
# DShotRMT - ESP32 Library (Rewrite for ESP-IDF 5)
|
2025-04-17 15:48:27 +01:00
|
|
|
|
|
2025-07-19 15:41:04 +01:00
|
|
|
|
A modern, robust C++ library for generating DShot signals on the ESP32 using the new ESP-IDF 5 RMT encoder API (`rmt_tx.h` / `rmt_rx.h`).
|
2025-09-07 14:19:52 +01:00
|
|
|
|
Supports all standard DShot modes (150, 300, 600, 1200) and features continuous frame transmission with configurable timing.
|
2025-09-04 13:41:05 +01:00
|
|
|
|
**Now with BiDirectional DShot support and advanced command management!**
|
2021-06-29 19:05:20 +01:00
|
|
|
|
|
2025-07-19 15:41:04 +01:00
|
|
|
|
> The legacy version (using the old `rmt.h` API) is still available in the `oldAPI` branch.
|
2025-06-12 23:45:48 +01:00
|
|
|
|
|
2025-07-19 15:41:04 +01:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## 🚀 Features
|
|
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
- **All DShot Modes:** DSHOT150, DSHOT300 (default), DSHOT600, DSHOT1200
|
|
|
|
|
|
- **BiDirectional DShot:** Full support for RPM telemetry feedback
|
2025-09-04 13:41:05 +01:00
|
|
|
|
- **Advanced Command Manager:** High-level API for ESC configuration and control
|
|
|
|
|
|
- **Command Sequences:** Predefined initialization and calibration sequences
|
2025-09-07 14:19:52 +01:00
|
|
|
|
- **Hardware-Timed Signals:** Independent, precise signal generation using ESP32 RMT peripheral
|
|
|
|
|
|
- **Configurable Timing:** Ensures ESCs can reliably detect frame boundaries
|
|
|
|
|
|
- **Error Handling:** Comprehensive result reporting with success/failure status
|
2025-07-19 15:41:04 +01:00
|
|
|
|
- **Simple API:** Easy integration into your Arduino or ESP-IDF project
|
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-07-19 15:41:04 +01:00
|
|
|
|
## 📦 Installation
|
|
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
### Arduino IDE
|
|
|
|
|
|
1. Search "Arduino Library Manager" for "DShotRMT"
|
2021-07-26 21:20:49 +01:00
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
or
|
|
|
|
|
|
|
|
|
|
|
|
1. Clone this repository or download as ZIP
|
|
|
|
|
|
2. Place in your Arduino libraries folder (`~/Arduino/libraries/DShotRMT/`)
|
|
|
|
|
|
3. Restart Arduino IDE
|
|
|
|
|
|
|
|
|
|
|
|
### PlatformIO
|
|
|
|
|
|
Add to your `platformio.ini`:
|
|
|
|
|
|
```ini
|
|
|
|
|
|
lib_deps =
|
|
|
|
|
|
https://github.com/derdoktor667/DShotRMT.git
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### Manual Installation
|
2025-07-19 15:41:04 +01:00
|
|
|
|
```sh
|
|
|
|
|
|
git clone https://github.com/derdoktor667/DShotRMT.git
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
---
|
2021-07-26 21:20:49 +01:00
|
|
|
|
|
2025-07-19 15:41:04 +01:00
|
|
|
|
## ⚡ Quick Start
|
2021-07-26 21:20:49 +01:00
|
|
|
|
|
2025-09-04 13:41:05 +01:00
|
|
|
|
### Basic Usage (DShotRMT)
|
|
|
|
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
|
|
#include <DShotRMT.h>
|
|
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
// Create motor instance (GPIO 17, DSHOT300, non-bidirectional)
|
|
|
|
|
|
DShotRMT motor(17, DSHOT300, false);
|
2025-09-04 13:41:05 +01:00
|
|
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
|
|
Serial.begin(115200);
|
2025-09-07 14:19:52 +01:00
|
|
|
|
|
|
|
|
|
|
// Initialize the motor
|
|
|
|
|
|
dshot_result_t result = motor.begin();
|
|
|
|
|
|
if (result.success) {
|
|
|
|
|
|
Serial.println("Motor initialized successfully");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Serial.printf("Motor init failed: %s\n", result.msg);
|
|
|
|
|
|
}
|
2025-09-04 13:41:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void loop() {
|
2025-09-07 14:19:52 +01:00
|
|
|
|
// Send throttle value (48-2047)
|
|
|
|
|
|
dshot_result_t result = motor.sendThrottle(1000);
|
|
|
|
|
|
if (!result.success) {
|
|
|
|
|
|
Serial.printf("Throttle command failed: %s\n", result.msg);
|
|
|
|
|
|
}
|
2025-09-04 13:41:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
```
|
|
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
### Bidirectional DShot (RPM Telemetry)
|
2025-09-04 13:41:05 +01:00
|
|
|
|
|
2025-07-19 15:41:04 +01:00
|
|
|
|
```cpp
|
2025-09-04 13:41:05 +01:00
|
|
|
|
#include <DShotRMT.h>
|
|
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
// Enable bidirectional mode for telemetry
|
|
|
|
|
|
DShotRMT motor(17, DSHOT300, true);
|
2025-09-04 13:41:05 +01:00
|
|
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
|
|
Serial.begin(115200);
|
|
|
|
|
|
motor.begin();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void loop() {
|
2025-09-07 14:19:52 +01:00
|
|
|
|
// Send throttle
|
|
|
|
|
|
motor.sendThrottle(1000);
|
|
|
|
|
|
|
|
|
|
|
|
// Get telemetry data
|
|
|
|
|
|
dshot_telemetry_result_t telemetry = motor.getTelemetry(14); // 14 magnets
|
|
|
|
|
|
if (telemetry.success) {
|
|
|
|
|
|
Serial.printf("eRPM: %u, Motor RPM: %u\n",
|
|
|
|
|
|
telemetry.erpm,
|
|
|
|
|
|
telemetry.motor_rpm);
|
|
|
|
|
|
}
|
2025-09-04 13:41:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## 📚 Examples
|
|
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
The library includes comprehensive examples:
|
2025-09-04 13:41:05 +01:00
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
### 1. Basic DShot Control (`dshot300.ino`)
|
|
|
|
|
|
- Simple throttle control
|
|
|
|
|
|
- Command execution
|
|
|
|
|
|
- Serial interface for testing
|
|
|
|
|
|
- Telemetry reading (if bidirectional enabled)
|
2025-09-04 13:41:05 +01:00
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
### 2. Advanced Command Management (`command_manager.ino`)
|
|
|
|
|
|
Interactive ESC control with full menu system:
|
2025-09-04 13:41:05 +01:00
|
|
|
|
```
|
|
|
|
|
|
=== DShot Command Manager Menu ===
|
2025-09-07 14:19:52 +01:00
|
|
|
|
1 - Stop Motor
|
|
|
|
|
|
2 - Activate Beacon 1
|
|
|
|
|
|
3 - Set Normal Spin Direction
|
|
|
|
|
|
4 - Set Reversed Spin Direction
|
|
|
|
|
|
5 - Get ESC Info
|
|
|
|
|
|
6 - Turn LED 0 ON
|
|
|
|
|
|
7 - Turn LED 0 OFF
|
|
|
|
|
|
0 - Emergency Stop
|
|
|
|
|
|
|
|
|
|
|
|
Advanced Commands:
|
|
|
|
|
|
cmd <number> - Send DShot command (0-47)
|
|
|
|
|
|
throttle <value> - Set throttle (48-2047)
|
|
|
|
|
|
repeat cmd <num> count <count> - Repeat command
|
2025-07-19 15:41:04 +01:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
## 🔧 Hardware Configuration
|
2025-07-19 15:41:04 +01:00
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
### Supported DShot Modes
|
2025-07-19 15:41:04 +01:00
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
| Mode | Bitrate | Bit Time | Frame Time | Use Case |
|
|
|
|
|
|
|----------|-------------|----------|------------|----------|
|
|
|
|
|
|
| DSHOT150 | 150 kbit/s | 6.67 µs | ~107 µs | Long wires, EMI-prone |
|
|
|
|
|
|
| DSHOT300 | 300 kbit/s | 3.33 µs | ~53 µs | Standard (recommended) |
|
|
|
|
|
|
| DSHOT600 | 600 kbit/s | 1.67 µs | ~27 µs | High performance |
|
|
|
|
|
|
| DSHOT1200| 1200 kbit/s | 0.83 µs | ~13 µs | Racing applications |
|
2025-07-19 15:41:04 +01:00
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
### GPIO Configuration
|
|
|
|
|
|
```cpp
|
|
|
|
|
|
// Using GPIO number
|
|
|
|
|
|
DShotRMT motor(17, DSHOT300);
|
2021-07-26 21:20:49 +01:00
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
// Using GPIO enum
|
|
|
|
|
|
DShotRMT motor(GPIO_NUM_17, DSHOT300);
|
2021-07-26 21:20:49 +01:00
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
// With bidirectional support
|
|
|
|
|
|
DShotRMT motor(17, DSHOT300, true);
|
|
|
|
|
|
```
|
2021-07-26 21:20:49 +01:00
|
|
|
|
|
2025-07-18 08:31:44 +01:00
|
|
|
|
|
2025-06-11 08:29:59 +01:00
|
|
|
|
---
|
2021-07-26 21:20:49 +01:00
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
## 🎯 DShot Commands
|
|
|
|
|
|
|
|
|
|
|
|
| Command | Value | Description | Usage |
|
|
|
|
|
|
|---------|-------|-------------|-------|
|
|
|
|
|
|
| MOTOR_STOP | 0 | Stop motor | Always available |
|
|
|
|
|
|
| BEACON1 - 5 | 1 - 5 | Motor beeping | Motor identification |
|
|
|
|
|
|
| ESC_INFO | 6 | Request ESC info | Get ESC version/settings |
|
|
|
|
|
|
| SPIN_DIRECTION_1/2 | 7 - 8 | Set spin direction | Motor configuration |
|
|
|
|
|
|
| 3D_MODE_OFF/ON | 9 - 10 | 3D mode control | Bidirectional flight |
|
|
|
|
|
|
| SAVE_SETTINGS | 12 | Save to EEPROM | Permanent configuration |
|
|
|
|
|
|
| EXTENDED_TELEMETRY_ENABLE/DISABLE | 13 - 14 | Telemetry control | Data transmission |
|
|
|
|
|
|
| SPIN_DIRECTION_NORMAL/REVERSED | 20 - 21 | Spin direction | Alias commands |
|
|
|
|
|
|
| LED0-3_ON/OFF | 22 - 29 | LED control | BLHeli32 only |
|
|
|
|
|
|
| AUDIO_STREAM_MODE | 30 | Audio mode toggle | KISS ESCs |
|
|
|
|
|
|
| SILENT_MODE | 31 | Silent mode toggle | KISS ESCs |
|
2023-03-29 21:12:08 +01:00
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
---
|
2025-06-11 08:29:59 +01:00
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
## 📚 DShot Protocol Details
|
2025-06-11 08:29:59 +01:00
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|

|
2025-06-12 23:45:48 +01:00
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
### Packet Structure
|
|
|
|
|
|
Each DShot frame consists of 16 bits:
|
|
|
|
|
|
- **11 bits:** Throttle/command value (0-2047)
|
|
|
|
|
|
- **1 bit:** Telemetry request flag
|
|
|
|
|
|
- **4 bits:** CRC checksum
|
2025-07-19 15:41:04 +01:00
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
### Checksum Calculation
|
|
|
|
|
|
```cpp
|
|
|
|
|
|
// Standard DShot CRC
|
|
|
|
|
|
uint16_t crc = (data ^ (data >> 4) ^ (data >> 8)) & 0x0F;
|
2025-06-11 08:29:59 +01:00
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
// Bidirectional DShot (inverted CRC)
|
|
|
|
|
|
uint16_t crc = (~(data ^ (data >> 4) ^ (data >> 8))) & 0x0F;
|
2025-06-11 08:29:59 +01:00
|
|
|
|
```
|
|
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
### Bidirectional DShot
|
|
|
|
|
|
- **Inverted Logic:** High/low levels are inverted
|
|
|
|
|
|
- **GCR Encoding:** Telemetry uses Group Code Recording
|
|
|
|
|
|
- **21-bit Response:** 1 start + 16 data + 4 CRC bits
|
|
|
|
|
|
- **eRPM Data:** Electrical RPM transmitted back to controller
|
2025-06-11 08:29:59 +01:00
|
|
|
|
|
2025-07-19 15:41:04 +01:00
|
|
|
|
---
|
2025-06-11 08:29:59 +01:00
|
|
|
|
|
2025-07-19 15:41:04 +01:00
|
|
|
|
## 🛠️ ESP32 RMT Peripheral
|
2025-06-11 08:29:59 +01:00
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
The library utilizes the ESP32's RMT (Remote Control) peripheral for precise signal generation:
|
2025-06-11 08:29:59 +01:00
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
### Advantages
|
|
|
|
|
|
- **Hardware Timing:** No CPU intervention during transmission
|
|
|
|
|
|
- **Concurrent Operation:** Multiple channels can run simultaneously
|
|
|
|
|
|
- **DMA Support:** Efficient memory-to-peripheral transfers
|
2025-06-11 08:29:59 +01:00
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
---
|
2025-06-11 08:29:59 +01:00
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
## 📖 References & Documentation
|
2025-09-04 13:41:05 +01:00
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
### DShot Protocol
|
|
|
|
|
|
- [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/)
|
|
|
|
|
|
- [Betaflight DShot Implementation](https://github.com/betaflight/betaflight)
|
2025-09-04 13:41:05 +01:00
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
### ESP32 Documentation
|
|
|
|
|
|
- [ESP32 Technical Reference Manual](https://www.espressif.com/sites/default/files/documentation/esp32_technical_reference_manual_en.pdf)
|
|
|
|
|
|
- [ESP-IDF RMT Driver](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/rmt.html)
|
|
|
|
|
|
- [Arduino ESP32 Core](https://github.com/espressif/arduino-esp32)
|
2025-09-04 13:41:05 +01:00
|
|
|
|
|
|
|
|
|
|
---
|
2025-06-11 08:29:59 +01:00
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
## 🤝 Contributing
|
2025-09-04 13:41:05 +01:00
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
We welcome contributions! Please:
|
2025-06-11 08:29:59 +01:00
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
1. Fork the repository
|
|
|
|
|
|
2. Create a feature branch
|
|
|
|
|
|
3. Make your changes with tests
|
|
|
|
|
|
4. Submit a pull request
|
2025-06-11 08:29:59 +01:00
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
### Development Guidelines
|
|
|
|
|
|
- Follow existing code style
|
|
|
|
|
|
- Add documentation for new features
|
|
|
|
|
|
- Include examples where appropriate
|
|
|
|
|
|
- Test with real hardware when possible
|
2025-06-11 08:29:59 +01:00
|
|
|
|
|
2025-09-07 14:19:52 +01:00
|
|
|
|
### Reporting Issues
|
|
|
|
|
|
When reporting issues, please include:
|
|
|
|
|
|
- ESP32 board type and version
|
|
|
|
|
|
- Arduino/ESP-IDF version
|
|
|
|
|
|
- ESC type and firmware
|
|
|
|
|
|
- Complete error messages
|
|
|
|
|
|
- Minimal reproduction code
|
2025-06-11 08:29:59 +01:00
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
2025-07-19 15:41:04 +01:00
|
|
|
|
## 📄 License
|
2025-06-11 08:29:59 +01:00
|
|
|
|
|
2025-07-19 15:41:04 +01:00
|
|
|
|
MIT License – see [LICENSE](LICENSE)
|
2025-06-11 08:29:59 +01:00
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
2025-07-19 15:41:04 +01:00
|
|
|
|
## 👤 Author
|
2025-06-11 08:29:59 +01:00
|
|
|
|
|
2025-07-19 15:41:04 +01:00
|
|
|
|
**Wastl Kraus**
|
2025-09-07 14:19:52 +01:00
|
|
|
|
- GitHub: [@derdoktor667](https://github.com/derdoktor667)
|
|
|
|
|
|
- Website: [wir-sind-die-matrix.de](https://wir-sind-die-matrix.de)
|