Section 3: Setting Up Arduino
Now that we know how a stepper motor works, we need program our microcontroller to make it move.
I have taken the time to write all of the firmware myself. What we will do in this course is examine it line by line so you understand how each part works.
You will then be able to create your own firmware using my example.
Let’s open up the firmware I created in Arduino so we can learn how to program this driver.
If you do not have Arduino installed, please install it now.
And if you do not have the ESP32 board installed for Arduino, please follow these instructions to install the ESP32 board in Arduino.
We will use the ESP32 in because it is very affordable and easy to purchase, but most importantly, it is dual core.
The dual core allow you to run the motor function on one core, and the wifi on the other core without any issues.
That’s how we can use the WiFi at the same time as the motor.
Github: Click here to download the Arduino firmware that we will use.
Let's open up Firmware.ino in the Arduino IDE.
Installing Libraries
Open up the Arduino library manager and install the following libraries
1) TMCStepper
2) FastAccellStepper
3) ESPUI
4) ArduinoJson
5) LittleFS
LittleFS is more difficult to find. Search for the one like in this image LittleFS_esp32 by lorol.
Extra Dependencies
The ESPUI library has some extra dependencies that need to be installed in a slightly more complicated way.
Follow the next steps to install the ESPAsyncWebServer library:
- Click here to download the ESPAsyncWebServer library. You should have a .zip folder in your Downloads folder
- Unzip the .zip folder and you should get ESPAsyncWebServer-master folder
- Open the ESPAsyncWebServer-master folder and you will see another ESPAsyncWebServer-master folder.
- Rename this folder from ESPAsyncWebServer-master to ESPAsyncWebServer
- Move the ESPAsyncWebServer folder to your Arduino IDE installation libraries folder.
Installing the Async TCP Library for ESP32
The ESPAsyncWebServer library requires the AsyncTCP library to work. Follow the next steps to install that library:
- Click here to download the AsyncTCP library. You should have a .zip folder in your Downloads folder
- Unzip the .zip folder and you should get AsyncTCP-master folder
- Open the AsyncTCP-master folder and you will see another AsyncTCP-master folder
- Rename this folder from AsyncTCP-master to AsyncTCP
- Move the AsyncTCP folder to your Arduino IDE installation libraries folder
- Finally, re-open your Arduino IDE
Course Sections:
- 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