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
A simple program to blink LED
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
- Now download webrepl client https://github.com/micropython/webrepl/archive/master.zip
- Disconnect USB to Serial converter from computer.
- Connect computer to the WIFI access point of ESP8266.
- Open webrepl.html using Chrome or Firefox browser.
- ws://192.168.4.1:8266
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.
Important Links
- https://randomnerdtutorials.com/getting-started-micropython-esp32-esp8266/
- https://www.youtube.com/watch?v=lvmNLuHj25o
- https://docs.espressif.com/projects/esptool/en/latest/esp8266/index.html
- https://www.srccodes.com/setup-web-repl-esp8266-12e-connect-micro-python-prompt-repl-wifi-access-point-ap-hello-world/