2024-07-17
mpremote
ist ein in Python geschriebenes
Kommandozeilenprogramm zum interaktiven Arbeiten mit einem
Embedded-Board auf dem der Micropython Interpreter läuft. Das Board ist
dabei meist über ein USB Kabel an den PC angeschlossen. Es handelt sich
dabei um eine serielle Schnittstelle (UART). Unter Linux stehen für
serielle Schnittstellen die Gerätedateien /dev/tty*
,
konkret /dev/ttyUSB0
, wobei die Zahl auch 1
,
2
, und so weiter sein kann. mpremote
wurde von
Damien P. George geschrieben, der auch Micropython entwickelt hat.
mpremote Projekt auf PyPI:
Doku:
Installation
$ pip install mpremote
Optionales Konfigurationsfile mit selbstdefinierten Makros:
~/.config/mpremote/config.py
$ mpremote --version
mpremote 1.23.0
$ mpremote help
$ mpremote --help
$ mpremote mount --help # Hilfe zu Kommandos
$ mpremote devs # Geraete anzeigen
/dev/ttyUSB0 0001 10c4:ea60 Silicon Labs CP2102 USB to UART Bridge Controller
$ mpremote connect /dev/ttyUSB0 repl # oder ...
$ mpremote u0 repl # siehe mpremote --help
Aus repl
aussteigen mit C-]
.
$ mpremote connect --help
$ mpremote connect list
$ /dev/ttyUSB0 0001 10c4:ea60 Silicon Labs CP2102 USB to UART Bridge Controller
$ mpremote ls
$ mpremote edit main.py
$ mpremote cp :main.py . # Datei von Mikrocontroller holen
$ mpremote cp -r dir : # Verzeichnis rekursiv auf Mikrocontroller kopieren
$ mpremote u0 exec "import hhtest"
$ mpremote u0 exec "import dog; dog.main()"
$ mpremote u0 repl # Ende mit C-]
$ mpremote mount . # mount klappt nicht
$ mpremote umount
Entfernte Datei ausgeben. Es geht aber auch
mpremote cat <rfile>
. Ausser cat kann man auch
eingeben: ls
, cp
, rm
,
mkdir
, rmdir
, touch
.
$ mpremote fs cat <rfile>
Lokale Python Datei
$ mpremote run <file>
$ mpremote reset # reset device after some delay
$ mpremote df
mount size used avail use%
501760 12288 489472 2
flash 501760 12288 489472 2
$ mpremote eval 1/2 eval 3/4
0.5
0.75
$ mpremote exec "import micropython; micropython.mem_info()"
stack: 720 out of 7168
GC: total: 67008, used: 17696, free: 49312
No. of 1-blocks: 210, 2-blocks: 34, max blk sz: 512, max free sz: 3073
User config: .config/mpremote/config.py
micropython-lib
[1] installieren.$ mpremote mip install aioble
$ mpremote mip install github:org/repo@branch
Sample config:
# Custom macro commands
commands = {
"c33": "connect id:334D335C3138",
"bl": "bootloader",
"double x=4": {
"command": "eval x*2",
"help": "multiply by two"
}
}
[1] Micropython Lib https://github.com/micropython/micropython-lib