This board is also supported by MicroPython. This page covers the basics to get you started.
Load MicroPython using esptool
Before you can load MicroPython, you'll need to install esptool
. Follow the instructions found here.
Once you have esptool
installed, you will first want to erase the flash on your Feather. You can do so by running something similar to the following command. Make sure you update the port to match the serial port to which your board is connected, i.e. change /dev/tty.usbserial-1144440
to match your connection.
esptool.py --chip esp32 --baud 115200 --port /dev/tty.usbserial-1144440 erase_flash
Once the flash is successfully erased, you can load MicroPython by running something similar to the command below. Make sure you update the following:
- The port to match the serial port to which your board is connected, i.e. change /dev/tty.usbserial-1144440 to match your connection.
- The firmware.bin file name to match the MicroPython firmware you downloaded, i.e. change firmware.bin to something like esp32spiram-20220117-v1.18.bin.
Load MicroPython using something similar to the following command, with the above changes:
esptool.py --chip esp32 --baud 115200 --port /dev/tty.usbserial-1144440 write_flash -z 0x1000 firmware.bin
MicroPython Blink
The first example is making an LED blink. To do so, begin by connecting to the serial REPL.
Type the following code into the REPL.
import time from machine import Pin led = Pin(13, Pin.OUT) while True: led.on() time.sleep(0.5) led.off() time.sleep(0.5)
First you import time
, and from machine import Pin
. Next, you create the led object. The LED is on pin 13
, and the pin must be set as an output when used for this purpose. Inside the loop, you turn the led pin on, wait 0.5 seconds, turn the LED pin off, wait another 0.5 seconds, and repeat.
This code will continue running until you break out of it by typing CTRL+C. When you type CTRL+C with the above code running, you'll see something like the following as you return to the REPL prompt.
That's all there is to blinking the build-in red LED on the ESP32 Feather V2 using MicroPython and the REPL.
MicroPython WiFi Connection
To manage and run code, you can use Thonny - set up to be a MicroPython (ESP32) board, then pick the matching serial port.
Install the urequests
library via the package manager. Click Tools > Manage Packages to open the package manager. Type urequests into the search bar, and click Search on PyPI.
You may be greeted with the following popup. Click Yes.
Once installed, the package manager will show it as installed.
Download the following code and save it to your ESP32 as main.py
Don't forget to change MY_SSID
and MY_PASSWORD
to your WiFi access point name and credentials.
# SPDX-FileCopyrightText: 2022 Ladyada for Adafruit Industries # SPDX-License-Identifier: MIT """MicroPython simple WiFi connection demo""" import time import network import urequests station = network.WLAN(network.STA_IF) station.active(True) # Network settings wifi_ssid = "MY_SSID" wifi_password = "MY_PASSWORD" url = "http://wifitest.adafruit.com/testwifi/index.html" print("Scanning for WiFi networks, please wait...") authmodes = ['Open', 'WEP', 'WPA-PSK', 'WPA2-PSK4', 'WPA/WPA2-PSK'] for (ssid, bssid, channel, RSSI, authmode, hidden) in station.scan(): print("* {:s}".format(ssid)) print(" - Channel: {}".format(channel)) print(" - RSSI: {}".format(RSSI)) print(" - BSSID: {:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}".format(*bssid)) print(" - Auth: {}".format(authmodes[authmode])) print() # Continually try to connect to WiFi access point while not station.isconnected(): # Try to connect to WiFi access point print("Connecting...") station.connect(wifi_ssid, wifi_password) time.sleep(10) # Display connection details print("Connected!") print("My IP Address:", station.ifconfig()[0]) # Perform HTTP GET request on a non-SSL web response = urequests.get(url) # Display the contents of the page print(response.text)
Once you have the main.py file on your computer, open the main.py file into Thonny, and click Save.
The first time you do this, you will receive the following popup. Click MicroPython Device.
The following window will show up next, allowing you to save the main.py file to your Feather ESP32 V2.
Once saved to your ESP32, in Thonny, click STOP (red button) followed by Run (green arrow button) to load the main.py file and run it.
You should see something like the following indicating it could connect to WiFI and read the data from our webserver.
Page last edited January 20, 2025
Text editor powered by tinymce.