Using ampy for transferring files with MicroPython

ampy (Adafruit MicroPython tool)

  • Normally the connection to MicroPython is done using the serial connection.
  • Ampy is a simple little tool for transferring files to, or from, MicroPython.
  • Ampy can also execute a script on the MicroPython controller and return the output, which is convenient for development work.

Install

Installation happens on the workstation that connects to MicroPython, not on to the NodeMCU running MicroPython

Install pip

  • pip is the Python package installer.
  • If pip is not installed, add it to the system:
apt-get install -y python-pip

Install ampy

pip install adafruit-ampy

Transferring files

List files on MicroPython

ampy  -p /dev/ttyUSB0 -b 115200 ls

Transferring files to MicroPython

echo 'print("hello world")' > hello.py

## put local [remote]
ampy  -p /dev/ttyUSB0 -b 115200 put hello.py

Transferring files from MicroPython

## get remote local
ampy  -p /dev/ttyUSB0 -b 115200 get boot.py boot.py
cat boot.py

Run script on remote MicroPython and display output

ampy  -p /dev/ttyUSB0 -b 115200 run hello.py
categories: micropython | esp8266 | nodemcu |