GPIO pin numbering scheme not working on Arduino Nano ESP32

Hello, I have been having problems with pin definitions on the Arduino Nano ESP32

I am trying to use the FastAccelStepper library to control several motors with Step, Direction and Chip Select pins.

I was told that the library requires me to define the step and dir pins as the GPIO pins on the ESP32 chip (not the Nano Pin numbers).

I have been using this page as well as the Arduino Nano ESP32 pinout as reference for the different pin numbers.
Nano ESP32 Selecting Pin Configuration | Arduino Documentation

In the Arduino IDE I know you can select two different pin numbering schemes:

  • 'By Arduino Pin (default)'
  • 'By GPIO number (legacy)'

I found that if I defined the step pin as the GPIO number and the dir and CS pins as the Nano pin numbers I could move the motors individually with the default pin numbering scheme. I could add more motors and move them together however when I added one of the motor definitions nothing would work. It was like I was overwriting the other pin definitions but that couldn't have been the case as they had different pin definitions.

I then tried it in Platformio as the latest version of the library is not available from the Arduino Library manager for some reason. All of the motors would work if I added the DRIVER_RMT setting to each stepper's definition: engine.stepperConnectToPin(STEP_X_PIN, DRIVER_RMT). I don't really know what this setting does but at least it seemed to be working.

This was with defining the direction pin as the Arduino Nano pin number not the ESP32 chip's pin number however - not what the library requires.

What is going on here? I just want to be able to reliably define my pins. It is so frustrating.

The "working" pin definitions are below. The Z motor was the motor that would apparently 'overwrite' the other motor definitions.

#define STEP_X_PIN   21  // ESP32 GPIO pin
#define DIR_X_PIN   18   // Nano pin number
#define CS_X_PIN   8     // Nano pin number

#define STEP_Y_PIN   18  // ESP32 GPIO pin
#define DIR_Y_PIN   19     // Nano pin number
#define CS_Y_PIN   7       // Nano pin number

#define STEP_Z_PIN   9    // ESP32 GPIO pin
#define DIR_Z_PIN   20    // Nano pin number
#define CS_Z_PIN   4     // Nano pin number

#define STEP_R_PIN   8    // ESP32 GPIO pin
#define DIR_R_PIN   21     // Nano pin number
#define CS_R_PIN   17       // Nano pin number

where did this info come from??

never used that lib before but looking into the source, it's using pinMode and digitalWrite on the dir pin, so i'm not so sure about that info you got..

did you try both ways??
what was the results??

~q

The owner of the library told me on a Github issue I raised that "FastAccelStepper assumes, the pin numbers for step and dir to be the gpio-values as espressif32 is using it".

I can only get it to work if I define the dir and CS pins as the Arduino Nano pin numbers and the step pin as the ESP32 GPIO pin number. I also had to add this driver setting to each stepper's definition as mentioned in the original post: engine.stepperConnectToPin(STEP_X_PIN, DRIVER_RMT). I had to switch over to Platformio as the Arduino Library Manager doesn't have the latest versions of the library and I couldn't add this driver setting on older versions of the library.

It is confusing that it only works with a mix of pin numbering schemes. I couldn't get it to work by defining all pins as the Nano pin numbers (with the default pin numbering scheme) or defining all pins as the ESP32 GPIO pin numbers (and using the GPIO legacy pin numbering scheme).

What is going on in the background? How does the Arduino IDE or Platformio know which pin numbering to use?

be nice if that was documented..
diving a bit deeper into it i found these defined in fas_common.h..

#define pinMode(pin, mode) gpio_set_direction((gpio_num_t)pin, mode)
#define digitalWrite(pin, level) gpio_set_level((gpio_num_t)pin, level)

so yeah, looks like it's using gpio numbers..
I think they were rather rude to you, sorry about that..
you can still use Arduino, pretty easy to manually install a lib..

would take a dive into the core to see..
i'll look in a little bit, let you know what I find..

sorry for you troubles..

~q

1 Like

Thanks a lot, I tried looking at the source code but it was above what I could understand. Your help is appreciated!

Sorry for the late reply @hama7 . I see you have researched this a lot, but still, please try the following setup and let me know if this solves the issue:

  • Use the latest Arduino IDE (2.x)
  • Make sure to choose the Arduino ESP32 Boards package by Arduino in the Boards Manager, not the one by Espressif Systems
  • In the IDE, select Tools -> Pin Numbering -> By GPIO number (legacy)
  • In your sketch, use pin labels and not numbers everywhere. For example,
#define DIR_X_PIN   D18   // Nano pin number
#define CS_X_PIN    D8    // Nano pin number

(note the extra D). To be clear, these labels refer to the Nano pinout and your board PCB markings.

This should make the library work without issues. Let us know your results!