You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1.6 KiB

The Basics

The first boot.py will be executed when the interpreter starts. This file should contain only code associated with configuration. Then main.py will run. It is within this main.py that you will place your entry point code.

Setting the AMPY_PORT variable.

All of the commands below specify a serial port in their execution. We can use the AMPY_PORT environmental variable in our terminal session to avoid having to specify this port everytime.

export AMPY_PORT=/dev/cu.SLAB_USBtoUART

Uploading files with Ampy

First review the list of commands that the ampy tool provides.

ampy --help

We can view the contents of the current file system:

ampy --port /serial/port ls

We can execute a command immediately on a connected board:

ampy --port /serial/port run test.py

We can also upload the code directly to the board. Notice we are passing the upload path after the file in our current directory. So, this command is placing our test.py file on the board in a file under the root dir named main.py.

ampy --port /serial/port run test.py /main.py

We can pull the file from the board to our current working directory if we'd like so:

ampy --port /serial/port get main.py ./dirp.py

Connecting to a micropython board using screen on a Mac

screen /dev/cu.SLAB_USBtoUART 115200

To detach from a screen session first press Ctrl-A then Ctrl-D.

To resume a detach session use:

screen -r

To kill a screen session press Ctrl-A then k. You will be prompted to confirm with y\n whether to kill the session or not.