mpremote(1)
π mpremote β MicroPython remote control π
okay bestie, buckle up, because this is the mpremote(1) page from the General Commands Manual, and it is genuinely one of the most useful little tools you'll ever meet. it's the remote control for your MicroPython board and i'm gonna walk you through every single thing it does π«Ά
β¨ NAME β¨
mpremote β MicroPython remote control
πΈ SYNOPSIS πΈ
mpremote command [options] [+command ...]
mpremote [--help]
mpremote [--version]
π¦ DESCRIPTION π¦
okay so. mpremote is a command line tool that gives you a whole integrated set of utilities to remotely interact with and automate a MicroPython device over a serial connection. that's the whole vibe. it's your little portal into the board β¨
the simplest way to use it is literally just to invoke it with no arguments at all:
mpremote
and that's it. it automatically detects and connects to the first available serial device and drops you into an interactive REPL. main character energy fr fr π
heads up bestie: serial ports are opened in exclusive mode, so if you run a second (or third, etc) instance of mpremote, it will connect to subsequent serial devices, if any are available. no fighting over ports in this house π
π OPTIONS π
--helpβ show a help message and exit. your lil friendly nudge when you forget stuff π--versionβ show the program version and exit. slay π
π COMMANDS π
for REPL access, running mpremote with no arguments is usually all you need. but mpremote also supports a set of commands given at the command line which will perform various actions on remote MicroPython devices. it's giving β¨versatileβ¨
for commands that support multiple arguments (e.g. a list of files), the argument list can be terminated with +. the full list of supported commands are:
connect [device]β connect to a specified device via a device-name shortcut.devicemay be one of:autoβ connect to the first available devicelistβ list the available devicesid:serialβ connect to the device with USB serial number serial (the second entry in the output from theconnect listcommand)port:pathβ connect to the device with the given path- if the device is not specified,
autois assumed.
disconnectβ disconnects the current device. after a disconnect, auto soft-reset is enabled (see AUTO-CONNECTION AND SOFT-RESET below).resumeβ resume a previousmpremotesession. this disables auto soft-reset (see AUTO-CONNECTION AND SOFT-RESET below).soft-resetβ perform a soft-reset of the device. this will clear out the Python heap and restart the interpreter. it also disables auto soft-reset (see AUTO-CONNECTION AND SOFT-RESET below).repl [options]β enter the REPL on the connected device. the available options are:--capture fileβ to capture output of the REPL session to the given file--inject-code stringβ to specify characters to inject at the REPL when Ctrl-J is pressed--inject-file fileβ to specify a file to inject at the REPL when Ctrl-K is pressed
eval stringβ evaluate and print the result of a Python expression.exec stringβ execute the given Python code.run fileβ run a script from the local filesystem.fs subcommandβ execute filesystem commands on the device.subcommandmay be:cat files...β to show the contents of a file or files on the devicelsls dirs...β to list the current, or specified directoriescp [-r] src... destβ to copy files; use":"as a prefix to specify a file on the devicerm src...β to remove files on the devicemkdir dirs...β to create directories on the devicermdir dirs...β to remove directories on the devicetouch files...β to create empty files (if they don't already exist)
edit files...β edit a file (or files) on the device. theeditcommand will copy each file from the device to a local temporary directory and then launch your editor (defined by the environment variable$EDITOR). if the editor exits successfully, the updated file will be copied back to the device. chef's kiss workflow honestly πmip install [options] packages...β install packages from micropython-lib (or GitHub) using themiptool. the available options are:--target pathβ install under path instead of the default location (the first entry insys.pathending in/lib). please note that it must exist insys.pathfor you to be able to subsequently import the package.--no-mpyβ install the source version.pyfiles rather than.mpy).--index URLβ use the specified URL instead of the default package index athttps://micropython.org/pi.
mount [options] local-dirβ mount a local directory on the remote device (under the path/remote). during usage, Ctrl-D will soft-reboot and normally reconnect the mount automatically. if the unit has amain.pyrunning at startup however, the remount cannot occur. in this case a raw mode soft reboot can be used: Ctrl-A Ctrl-D to reboot, then Ctrl-B to get back to normal repl at which point the mount will be ready.- the available options are:
-l,--unsafe-linksβ by default an error will be raised if the device accesses a file or directory which is outside (up one or more directory levels) the local directory that is mounted. this option disables this check for symbolic links, allowing the device to follow symbolic links outside of the local directory.
umountβ unmount the local directory from the remote device.
π AUTO-CONNECTION AND SOFT-RESET π
connection and disconnection will be done automatically at the start and end of the execution of the tool, if such commands are not explicitly given. automatic connection will search for the first available serial device. if no action is specified then the REPL will be entered. it just knows β¨
once connected to a device, mpremote will automatically soft-reset the device if needed. this clears the Python heap and restarts the interpreter, making sure that subsequent Python code executes in a fresh environment. auto soft-reset is performed the first time one of the following commands are executed: mount, eval, exec, run, fs. after doing a soft-reset for the first time, it will not be done again automatically, until a disconnect command is issued.
auto soft-reset behaviour can be controlled by the resume command. and the soft-reset command can be used to perform an explicit soft reset.
π SHORTCUTS π
shortcuts can be defined using the macro system. built-in shortcuts are:
devsβ list available devices (shortcut forconnect list)a0,a1,a2,a3β connect to/dev/ttyACMnu0,u1,u2,u3β connect to/dev/ttyUSBnc0,c1,c2,c3β connect toCOMncat,ls,cp,rm,mkdir,rmdir,touch,dfβ filesystem commands (mostly aliases for thefsequivalent)resetβ reset the devicebootloaderβ make the device enter its bootloader
any user configuration, including user-defined shortcuts, can be placed in the file ~/.config/mpremote/config.py. for example:
commands = {
"c33": "connect id:334D335C3138",
"bl": "bootloader",
"double x=4": "eval x*2", # x is an argument, with default 4
"wl_scan": ["exec", """
import network
wl = network.WLAN()
wl.active(1)
for ap in wl.scan():
print(ap)
""",],
"test": ["mount", ".", "exec", "import test"],
}
β EXAMPLES β
mpremoteβ launch a repl on the automatically detected device.mpremote a1β launch a repl on the device connected to port/dev/ttyACM1(using the built-ina1shortcut).mpremote connect /dev/ttyUSB0 replβ launch a repl on the device connect to port/dev/ttyUSB0.mpremote lsβ list files on the automatically detected device.mpremote a1 lsβ list files on the device connected to port/dev/ttyACM1(using the built-ina1shortcut).mpremote exec import micropython; micropython.mem_info()β execute some Python code on the remote board to obtain various memory statistics.mpremote eval 1/2 eval 3/4β execute (and show the output of) two simple Python statements on the remote board. note that no+was required becauseevalaccepts a single string argument.mpremote mount .β mount the local directory under/remoteon the automatically detected device.mpremote mount . exec "import localscript"β mount the local directory under/remoteon the MicroPython board, then import the"localscript"modulempremote cat boot.pyβ show the contents ofboot.pyon the MicroPython board.mpremote cp :main.py .β copy themain.pyfile from the (remote) MicroPython board to the current (local) directory.mpremote cp main.py :β copy themain.pyfrom the current (local) directory to the (remote) MicroPython board.mpremote cp :a.py :b.pyβ on the MicroPython board, copya.pytob.py.mpremote cp -r dir/ :β recursively copy the local directorydir/to the root directory of the (remote) MicroPython board.mpremote cp a.py b.py : + replβ copy the local filesa.pyandb.pyto the root directory of the (remote) MicroPython board, then launch a repl. note that the+terminator is required here as thecpcommand takes an arbitrary number of parameters.mpremote mip install aiobleβ install the asyncio-based wrapper for the Bluetooth API.mpremote mip install github:org/repo@branchβ install the branch of the MicroPython package located underorg/repoon GitHub.mpremote mip install --target /flash/third-party functoolsβ install thefunctoolspackage under the/flash/third-partydirectory on the MicroPython board.
π«Ά SEE ALSO π«Ά
and that's the whole page bestie!! π this was mpremote(1) from the General Commands Manual, section 1, no cap. go forth and remote-control your board, you absolute icon πβ¨
π¦ where this page comes from
- debian trixie: micropython-mpremote 1.24.1-1 Β· MIT
- ubuntu noble: micropython-mpremote 0.4.0-0ubuntu1 Β· MIT
- ubuntu questing: micropython-mpremote 1.24.1-1
- ubuntu resolute: micropython-mpremote 1.26.0-1 Β· MIT
- ubuntu stonking: micropython-mpremote 1.26.0-1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms