micropython - How to Access a MicroPython Flashed Device
1) Preparing a Virtual Environment
Create a folder and name it as desired.
Let's create a virtual environment.
We now need to install the tool ampy to download or upload files to our board.
pip3 install adafruit-ampy
2) Serial Port Configuration
My ESP8266 board has a serial port installed on the board and after connecting it to my Linux PC it is possible to see it listed under the USB devices.
And, we can check which port our serial converter is attached to with the command below.
sudo dmesg | grep -i tty
[ 0.076223] printk: console [tty0] enabled
[ 0.410913] 00:01: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A
[227734.859083] usb 1-4: ch341-uart converter now attached to ttyUSB0
[228043.503965] ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0
[228044.006867] usb 1-4: ch341-uart converter now attached to ttyUSB0
[228557.181812] ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0
[231782.823891] usb 1-4: ch341-uart converter now attached to ttyUSB0
Make sure to grant read and write permissions to the device to your user otherwise ampy
will complain.
ll /dev/ttyUSB0
crw-rw---- 1 root dialout 188, 0 Nov 3 20:38 /dev/ttyUSB0
sudo chmod 0666 /dev/ttyUSB0
tiago@desktop ~/scripts (main)> ll /dev/ttyUSB0
crw-rw-rw- 1 root dialout 188, 0 Nov 3 20:38 /dev/ttyUSB0
3) Accessing the ESP8266 Files
Let's list the files currently in our device.
ampy -p /dev/ttyUSB0 -b 115200 ls
/boot.py
/led.py
/main.py
/websocket_server.py
I will backup the files to upload a new project to my board.
ampy -p /dev/ttyUSB0 -b 115200 get /boot.py boot.py
ampy -p /dev/ttyUSB0 -b 115200 get /led.py led.py
ampy -p /dev/ttyUSB0 -b 115200 get /main.py main.py
ampy -p /dev/ttyUSB0 -b 115200 get /websocket_server.py websocket_server.py
(temp-controller-venv) tiago@desktop ~/D/p/p/temp-controller (main)> ll
total 20K
-rw-rw-r-- 1 tiago tiago 353 Nov 3 20:57 boot.py
-rw-rw-r-- 1 tiago tiago 572 Nov 3 20:58 led.py
-rw-rw-r-- 1 tiago tiago 3.7K Nov 3 20:58 main.py
drwxrwxr-x 6 tiago tiago 4.0K Nov 3 18:59 temp-controller-venv
-rw-rw-r-- 1 tiago tiago 2.0K Nov 3 20:58 websocket_server.py
Conclusion
The steps above allowed us to upload or download files from our ESP8266 board flashed with MicroPython.
Resources