Section 7: FastAccelStepper Library

The advanced features such as StallGuard can be purchased in our PDF guide here.

 

Did you know that we can drive the TMC2209 driver without any microcontroller? All we must do is apply 3.3V to the STEP pin and it will move one step. The stepper driver simply waits for a high signal on the step pin and when it sees a high pulse, it moves one step. Super simple!

The FastAccelStepper library is a set of algorithms that make controlling a motor very simple. We just tell it how far to move and how fast, and the library figures out how to pulse the step pin and sets the direction pin. This library will control the motor.

Let’s begin by initializing FastAccelStepper:

FastAccelStepperEngine engine = FastAccelStepperEngine();
FastAccelStepper *stepper = NULL;

But it still needs to be initialized. For this “init” will be used.

engine.init();
stepper = engine.stepperConnectToPin(STEP_PIN);

FastAccelStepper vs AccelStepper

If you’ve ever looked for stepper motor library online, chances are that you’ve come across one called “AccelStepper” as it has been around for a long time and is very popular. It always works well, only nearly any Arduino processor. The reason it works universally is because it uses a process called “Bit Banging” to pulse the Step pin.

According to Wikipedia, bit banging is a "term of art" for any method of data transmission that employs software as a substitute for dedicated hardware to generate transmitted signals. In our case, AccelStepper ends up using the main processor to set ultra-fast pulses to the Step pin. This can cause problems because now we’re tying up the main processor every time the motor moves.

However, there is a much better way to do this. The FastAccelStepper library makes use of two built-in peripheral modules that are available on the ESP32. In order to generate a pulse, it uses the Motor Control Pulse Width Modulator (MCPWM) module. And it also uses the Pulse Counter (PCNT) module to then count every pulse that it sends. Links to these modules are found on the resource page.

It's always a better idea to use dedicated hardware rather than tie up the processor when possible, which is why we use the FastAccelStepper library. 

NEXT SECTION: 8

Course Sections:

Advanced Sections:

Back to blog

Leave a comment