This page looks best with JavaScript enabled

Micropython on ESP8266

 ·   ·  β˜• 2 min read  ·  ✍️ Ohidur Rahman Bappy

Prerequisite

Flash appropriate microptyhon firmware on the board. I used thonny. It’s probably the most convenient IDE for
micropython. It comes prepackaged with python and has support for micropython out of the box.
And uploading files are pretty easy and simple.

Some info

  • use help() to list some sample code
  • use help('modules') to see installed packages
from machine import Pin
from time import sleep

led=Pin(2,Pin.OUT)

while True:
    led.value(not led.value())
    sleep(1)

List files on the Flash memory

import uos
print(uos.listdir())

To enable WebREPL open the boot.py and uncomment the following line

import webrepl

The default password for the Wifi Access point is micropythoN

We can setup the webrepl

by connecting to it via

screen <PORT> 115200

or through thonny ide.

and then

import webrepl_setup

Get the Wifi SSID

MicroPython v1.8.6-7-gefd0927 on 2016-11-10; ESP module with ESP8266
Type "help()" for more information.
>>> import network;
>>> ap = network.WLAN(network.AP_IF);
>>> print(ap.config('essid'));
MicroPython-d0fa00
>>>

Change wifi access point and password

MicroPython v1.8.6-7-gefd0927 on 2016-11-10; ESP module with ESP8266
Type "help()" for more information.
>>> import network;
>>> ap = network.WLAN(network.AP_IF);
>>> ap.active(True);
>>> ap.config(essid='MyESP8266', authmode=network.AUTH_WPA_WPA2_PSK, password='mypassword');
>>> print(ap.config('essid'));
MyESP8

ESPtool usage

Under the hood Thonny uses esptool to communicate with ESP boards. If you want to use it barebone following are the commands

Install esptool

pip install esptool

Writing a bin to the esp

esptool --port COM4 write_flash 0x1000 my_app-0x01000.bin

Multiple flash address

esptool --port COM4 write_flash 0x00000 my_app.elf-0x00000.bin 0x40000 my_app.elf-0x40000.bin

To run a program with the default bootloader you name the file as main.py when saving to the esp board.


Ohidur Rahman Bappy
WRITTEN BY
Ohidur Rahman Bappy
πŸ“šLearner 🐍 Developer