MicroPython now has a standard format for all remote access. The program is called mpremote. There is ample documentation on the site, and there is a higher chance it will include the latest features.
Why Use MicroPython Remote
There are three main reasons to use mpremote:
- Setting up a new device with many device drivers, data files and code.
- Automatically updating software to get new versions and fix bugs such as security patches.
- Moving data back and forth from your Pico to and from your host computer or a cloud server on the internet,
List of Commands
A partial list of the most frequently used commands are:
- connect - connect to a remote device
- disconnect - disconnect from a remote device
- resume - maintain existing interpreter state for subsequent commands. Useful for multiple REPL commands without soft resets between the commands.
- soft_reset - perform a soft-reset of the device which will clear out the Python heap and restart the interpreter.
- repl - enter the line-at-time REPL Python interpreter loop on the connected device.
- eval - evaluate a string you give as a parameter on the pico using the MicroPython interpreter.
- exec - execute a string and potentially run it in the background.
- run - run a script from the local filesystem on the Pico
- fs - file system commands like copy, move, rename. Examples below.
- df - print size/used/free statistics for teach of the device filesystems
- edit - edit a file locally. This will copy the file to your local file systems, launch your
$EDITORprogram and then copy the file back to the Pico.
- mip - intaller. Like pip but it runs on the pico. It install packages from micropython-lib (or GitHub) using the mip tool. This can be useful if you want to automatically upgrade your software and restart the device. If you have a wireless Pico "W" you can get new software directly from the Internet without ever needing a hardline to the Pico.
- mount - mount the local directory on your PC onto the remote device (the Pico). This will allow you to use local files directly from your MicroPython code.
- unmount - unmount a local directory. This happens automatically when mpremote terminates.
- rtc - get or set the real-time clock - useful if you want to keep clocks in sync
- sleep - (delay) n seconds before executing the next command
- reset - hard reset the device. It will then rerun the main.py if it finds it.
- bootloader - This will make the device enter its bootloader mode so it can get an new uf2 file. Useful if you need to upgrade to a new version of MicroPython.
Note that you can only be connected to one remote device at a time to use many commands.
The first time:
I use conda and you can see that it found the mpremote package version 1.20.0
1 2 3 4 5
Testing the Version
The version of mpremote is not yet working, but eventually, it will be used like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
Examples of File System Commands
Here is the syntax of the copy file command:
This copies the local file "main.py" to your pico. The colon ":" is the root of the pico.
Setting Up a UNIX Alias
If you get tired of typing "mpremote fs cp" you can create an command-line alias called "pcp" for Pico Copy:
The copy command the becomes simply:
If you place this line in your .bashrc or similar shell startup it saves you a lot of typing.
File systems examples include:
cat <file..>to show the contents of a file or files on the device
lsto list the current directory
ls <dirs...>to list the given directories
cp [-r] <src...> <dest>to copy files
rm <src...>to remove files on the device
mkdir <dirs...>to create directories on the device
rmdir <dirs...>to remove directories on the device
touch <file..>to create the files (if they don’t already exist)
Creating Deployment Scripts
For large classrooms that teach MicroPython using kits, we recommend that you arrange
mkdir and copy (
cp) file shell commands in a single UNIX shell script for consistency.
Here are the steps:
- Update the Pico with a new image
- Make a /lib directory using the
- Copy all the drivers for your projects to /lib directory. The drivers you use will be dependent on the hardware you use. For example if your kit has a display you might need to load the ssd1306.py display driver into the /lib directory.
- Copy the default startup program to the /main.py
- Have a sequence of "labs" that start with numbers such as 01_blink.py, 02_button.py etc.
If you follow these steps, then when the students connect to the Pico using Thonny they will see all the labs in the right order from simple to the most complex.