Skip to content

Bidirectional DShot library for the Raspberry Pi Pico series (RP2040, RP235x) using the PIO hardware. Jitter-resistant and efficient on the CPU.

License

Notifications You must be signed in to change notification settings

bastian2001/pico-bidir-dshot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bidirectional DShot library for RP2040 / RP2350

GitHub Release GitHub License All RPMs Difficulty: Easy Pico SDK: C++

Features

  • Easy to use
    • No need for timers, interrupts or DMA
    • Low setup and usage complexity
    • ERPM packets are decoded in this library
  • Fast bidirectional communication
    • Bidirectional and normal DShot up to 4800 (tested up to DShot 1200)
    • Speed only limited by DShot protocol
    • Fully asynchronous: no CPU intervention needed for sending or receiving
  • Oversampling with edge detection
    • Telemetry unaffected by jitter/aliasing or clock differences between ESC and MCU
    • Low CPU overhead: Edge detection is done on the PIO
  • Low usage of PIO hardware
    • Bidirectional DShot needs 28 instructions and 1 state machine per ESC => max 8/12 ESCs
    • Normal DShot needs 4 instructions and 1 state machine per 4 ESCs => max 30/48 ESCs
  • Extended DShot Telemetry support
    • Read ESC temperature, voltage, current and more: all integrated
    • See here for more information

Usage

This is essentially a bare minimum example for the Arduino IDE. For more details, check the integrated examples or the Wiki.

#include <PIO_DShot.h>
#define MOTOR_POLES 14

BidirDShotX1 *esc;

void setup() {
	esc = new BidirDShotX1(10, 600); // pin 10, DShot600
}

void loop() {
	delayMicroseconds(200); // keep packets spaced out
	uint32_t rpm = 0;
	esc->getTelemetryErpm(&rpm);
	rpm /= MOTOR_POLES / 2; // eRPM = RPM * poles/2 <=> RPM = eRPM / (poles/2)
	esc->sendThrottle(0); // 0-2000
}

Not calling getTelemetryErpm is fine if you don't care about that, but you definitely need to call sendThrottle regularly (recommended >500Hz), or else the ESC will time out because it thinks the main controller died.

Installation

Arduino IDE

  1. Open the Arduino IDE and go to Sketch -> Include Library -> Manage Libraries...
  2. In the Library Manager, search for Pico_Bidir_DShot and install it

PlatformIO

Append this repo to your lib_deps in your platformio.ini:

lib_deps = https://github.com/bastian2001/pico-bidir-dshot.git

CMake (bare Pico-SDK)

The code is written to use no Arduino.h for regular usage, so it can be used with the bare Pico SDK as well. Only the debug info uses Arduino's Serial class, so you can't enable those error hints without it. I personally never used CMake (manually), so sadly I can't help you with the installation.

Roadmap

  • Refactor code into library
  • Add example code and test on RP2040
  • Add documentation
  • Adjust and test code for RP2350 (more PIOs)
  • Release to Arduino Library Manager
  • Add more setups (e.g. DShotX1 - more efficient and versatile, DShotX8 - less PIOs needed)
  • Add more features (command queue, sendAll etc.)

Contributing

If you feel like a feature is missing or something is broken, feel free to open an issue. I'm happy to help you with any questions you might have.

If you have the experience to fix the issue yourself, feel free to open a pull request. I'm happy to review and merge it.

Credits

About

Bidirectional DShot library for the Raspberry Pi Pico series (RP2040, RP235x) using the PIO hardware. Jitter-resistant and efficient on the CPU.

Topics

Resources

License

Stars

Watchers

Forks