ampy from Adafruit to connect to ESP8266
By Pierre-Alain B on Tuesday, November 8 2016, 07:07 - Permalink
In past articles, we mentioned WebREPL and webcli.py tool to connect and upload files to the ESP8266 board equipped with Python. I recently discovered a new tool that does the job even better: adafruit-ampy. It works well with NodeMCU-embarked ESP8266 chips.
- Download and install adafruit-ampy with pip (in the following I will assume you are equipped with Python 3)
pip3 install adafruit-ampy
Depending on your Linux distribution, you may have to run this with sudo or as root.
- Let's flash our ESP8266 with micropython with esptool.py
esptool.py --port /dev/ttyUSB0 --baud 460800 erase_flash esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=8m 0 /path/to/esp8266-20161017-v1.8.5.bin
- Let's reboot the board after a couple of seconds. We can connect to it with picocom for example to check that the command line is fully accessible and the micropython system works.
picocom /dev/ttyUSB0 -b 115200
- Now let's connect with ampy to list the files on the board:
ampy -p /dev/ttyUSB0 ls
On a freshly booted ESP8266/NodeMCU, I only see "boot.py".
- To add a file, just use the "put" command:
ampy -p /dev/ttyUSB0 put /path/to/file
For the reference, the commands available are:
get Retrieve a file from the board. ls List contents of a directory on the board. mkdir Create a directory on the board. put Put a file on the board. reset Perform soft reset/reboot of the board. rm Remove a file from the board. run Run a script and print its output.