CircuitPython on the ESP8266
I’ve been enjoying circuit-python on my Hallowing and Circuit Playground Express boards but don’t really want to tie those up with any long term projects, so I decided to dust off my old ESP8266 Feather Huzzah to see if I could get that running circuit-python as well. Because it lacks built-in USB support, the Huzzah is a little more complicated to get going but really not bad as long as you don’t mind the command line.
I’m using Windows 10, but a similar process will work on other operating systems.
Steps to get setup:
- esptool requires legacy Python 2.7 so I created a conda environment:
conda create --name py27 python=2.7 -y
pip install esptool
- Install the SiLabs CP210x driver to make the board’s serial port visible.
- Download the latest CircuitPython ESP8266 firmware file
- Determine which port your esp8266 is connected to. On Windows 10 just open up device manager, then under the view menu show hidden devices. After that you’ll see it under Ports and something like ‘Silicon Labs CP210x USB to UART Bridge (COM6)’.
- Erase the flash of ESP8266. Substitute your com port. Mine was on COM6:
esptool --port COM6 erase_flash
- Run the following command to load the downloaded firmware file:
esptool --port COM6 --baud 115200 write_flash --flash_size=detect 0 adafruit-circuitpython-feather_huzzah-3.1.2.bin
- Now you can use Python 3 again so change environments if you wish. I setup another conda environment for this and other micro-controller specific setup. It’s called
pip install adafruit-ampy
- After that it’s just a matter of running the following to run a python script on the board:
ampy --port COM6 run code.py
- I don’t want to constantly type the port so I set AMPY_PORT environment variable to COM6 like this:
- Now just run
ampy run code.pyto run a python script on the board
ampy put code.pyto write a python script to the board
- Also see:
to print the pin names available to this board in circuit python:
import board print(dir(board))
Of course we always need a simple blink example:
import board import digitalio import time # Setup led pin LED_PIN = board.GPIO4 # Setup digital output for LED: led = digitalio.DigitalInOut(LED_PIN) led.direction = digitalio.Direction.OUTPUT # blink while True: led.value = True time.sleep(0.2) led.value = False time.sleep(0.2)