I would like to adopt this library on an Arduino Mega2560:


However, the macro DSHOT_PORT needs defined for the Mega2560 here: https://github.com/gueei/DShot-Arduino/blob/master/src/DShot.h

So I need to add a #if defined(__AVR_ATmega2560__) macro to that DShot.h header, however, it is not clear to me where to lookup the port mapping on a 2560 mega. I'm looking directly at the schematic itself here: https://www.arduino.cc/en/uploads/Main/arduino-mega2560-schematic.pdf

And understand that the 'ports' are groupings of IO where the pins are described as P?#, ? being the port letter and # being 0-7.

So what are my valid options? It appears that some ports (A,C,L) aren't pinned at all, some (D,J) only a few pins, and just about none of them (except K/F) have all port pins utilized. Also, I can see most of these pins are reserved for some type of functionality (analog, SPI, etc). I'm assuming I'm looking for a port with available pins reserved for PWM, such as Port B (pins 10-13 are PWM). Would this be correct?

  • According to the PDF you link to, port A is mapped to digital pins 22-29 on the board, port C to 30-37, port C to 42-49.
    – Mat
    Jan 10, 2021 at 14:01
  • You don't care about extra functionality of the pin unless you do need that extra functionality. Why would you want PWM? Jan 10, 2021 at 14:01
  • Thanks for clarification, I did read the drawing right. I assumed the lines that stopped early where not completed on the drawing (PDF search function failed me). Also, w/ respect to the additional functionality, I assumed PWM because DShot is often a replacement for PWM (as far ESC's). Does other functionality prevent me from using the pin (ex - pin 22 is PB3 'MOSI' SPI signal)?
    – DrTarr
    Jan 10, 2021 at 15:11

1 Answer 1


It would seem this library needs a single pin to communicate. So it doesn't really matter whether the port you choose has only a few pins available. Also, you do not care that some pins can have extra functionality, like SPI, I2C, etc, unless you do plan to use that functionality.

There is one think you should be aware of: the library uses the in and out assembly instructions to access the port. These instructions can only access the ports that are mapped in the regular I/O space of the microcontroller, not those that are in the “extended I/O” space. In the case of the ATmega2560, this means you can use any of the ports A through G, but you cannot use H, J, K nor L.

  • Thank you for feedback! Sounds like I can likely use most any pin on the board.
    – DrTarr
    Jan 10, 2021 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.