Skip to content
A gentle introduction to Micropython using a ESP8266
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Micropython (ESP8622) By Example

MicroPython is a lean and efficient implementation of the Python 3 programming language that includes a small subset of the Python standard library and is optimised to run on microcontrollers and in constrained environments.


Install Drivers and Identify COM port

Install the official nodemcu-devkit drivers for your OS.

Flashing the ESP8266 MCU

Firstly, erase the flash memory on the MCU. Memory is typically limited to a few megabytes.

esptool --port COM3 -c esp8266 --baud 460800 erase_flash

Write the firmware to the devices flash storage

esptool --port COM3 -c esp8266 --baud 460800 write_flash --flash_size=detect 0 esp8266-20180511-v1.9.4.bin

Connect to ESP8266 via Putty

Create a serial connection on your COM port with the correct baud rate:

  • Serial Line: COM3
  • Speed: 115200

A successful connection will yield a python REPL

MicroPython REPL

Run the following in the REPL to evaluate the device is working correctly:

from machine import Pin

# GPIO16 (D0) is the internal LED for NodeMCU
led_red = Pin(16, Pin.OUT)
# SETS the pin state to HIGH
# SETS the pin state to LOW

Copying files to the Flash Storage

To use ampy directly, you will need to run pipenv install and pipenv shell.

List all files within flash storage:

ampy -d 0.5 -p COM3 ls

Read the contents of a file from flash storage:

ampy -d 0.5 -p COM3 get

Copy file to flash storage at the root directory:

ampy -d 0.5 -p COM3 put examples/

Remove file from flash storage:

ampy -d 0.5 -p COM3 rm

Running a program on device boot will run as a precursor to Creating a will run every time the device is powered on.

# add contents to
ampy -d 0.5 -p COM3 put


Select your favorite IDE or editor for Python and develop your project. Once you are ready to run the code on a ESP8266, you can use uPyCraft to easily copy across the files to the device and open a REPL.



If you want to contact me, check out my twitter account, find me on #apoclyps.

You can’t perform that action at this time.