Motor driver code using ESP32
The general workflow goes as such.
- Install
esptoolonto your laptop (preferably in avirtual environment). - Download the firmware onto your computer (
.binformat) - Flash the firmware to the computer
- (Optional) Verify that the firmware was successfully flashed.
esptool is a Python package. As such, first ensure that you have a recent version of python installed on your device and is on your path.
NOTE: For Windows users, I have found it easier to use a Python environment on WINDOWS and not on WSL because you have to do some setup in order to make the Serial ports accessible via WSL.
python3 -m venv .venvYou may need to install a package (via brew or apt) for virtual environments. On Ubuntu it's
sudo apt update && sudo apt upgrade -y
sudo apt install python3-venv -yTo load in (or to use the proper lingo, source) the virtual environment, run in the top level directory:
source .venv/bin/activatepython -m venv .venvTo source the virtual environment, run in the top level directory:
.\.venv\Scripts\activate.batNOTE: I needed to expose the <Python Path>\Scripts directory to my path in order to actually be able to run esptool.exe from the command line.
With the virtual environment sourced, run these lines on Mac/Linux:
python3 -m pip install esptoolOn Windows:
python -m pip install esptool
NOTE: On Windows, the
esptoolapplication will be accessible viaesptool.exe.
Connect the ESP32 via USB.
Next, on a Linux environment (I can't speak to Mac for this one), check to see if you can see the Serial device. To do this, look at the /dev/ folder.
Try plugging in and out the USB device and see if a new /dev/ttyACM* device or similar is loaded as a result of connecting the device to your machine.
On a Windows machine, you can use the Device Manager. Look under "Ports (COM & LPT)", you should see a new device once it is plugged in. It should be specified as a COM port.
Next, in a terminal, run the following line (use the .exe for a Windows machine).
esptool[.exe] erase_flashYou may need to specify the Serial port using --port <PORT> on the above line.
NOTE: If you encounter an issue connecting to the Serial port, try these tips. First,ensure no Arduino IDE instances are open. Next, load the board in BOOT mode by holding down the "B" button before plugging in the device to your computer, and only after that releasing the "B" button.
Download the .bin file from this site.
Next, we can use the esptool command from the terminal to flash the ESP as follows:
esptool[.exe] write_flash 0 <PATH TO ESP32_FIRMWARE_FILE>Again you may need to specify a Serial (/dev/ttyACM* on Linux/Mac or COM* on Windows) port.
To do this we will connect to the ESP device using Serial.
For a cross-platform experience, I recommend using Thonny. However, I used PuTTY since I am on a Windows device.
- Specify
SerialunderConnection type. - Specify the Serial port as whichever COM port you find in Device Manager.
- Set the Speed (which is the BAUD rate) as
115200. - Click open.
You should now be able to see a MicroPython terminal open.
Try running
import machine
machine.freq()If you see something, then this is a success!