Section 9: Dual Core Setup
Before we go further into FastAccelStepper, let’s set up the dual core capability of the ESP32, because it may confuse you in the sketch.
I’m not going to cover this in too much detail, but here is the basic overview.
The ESP32 has 2 cores. We want the motor functions to run on one core, and the WiFi to run on the other core.
When the motor runs, it uses all of the resources of the core and Wi-Fi sometimes drops and disconnects. To fix this, we place them on separate cores.
By default, all Arduino code runs on Core 0. So we will create Core 1.
To create Core 1, we do it on line 26 in setup:
MotorTask //Motor Task
, "MotorTask" // A name just for humans
, 1024 * 4 // This stack size can be checked & adjusted by reading the Stack Highwater
, 3 // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
Next, let’s create the function to run on this core, is needs to be named MotorTask like we named it above, but you can name it any function name you want.
On line 171 we have our function running in a loop on core 1 only. This is where the motor will run, ensuring it only runs on Core 1:
NEXT SECTION: 10
- Section 0: Background
- Section 1: Hardware Setup
- Section 2: Stepper Motor Basics
- Section 3: Arduino Setup
- Section 4: Understanding Trinamic Drivers
- Section 5: Setting Trinamic Drivers
- Section 6: Power Requirements
- Section 7: StallGuard
- Section 8: FastAccelStepper Library
- Section 9: ESP32 Dual Core Setup
- Section 10: Motor Setup
- Section 11: Preferences Library
- Section 12: ESPUI
- Section 13: API