The mpremote command line tool is python plug-in developed by the official organization of MicroPython. It interacts with devices through terminal commands. The most distinctive function is to use the “mount” command to load local folders to the development board for testing.
- Python environment
- Mpremote plug-in
- Development board
You can refer to the previous post for basic file operations.
- Prepare a folder with some python script files. Open the folder in VS code.
num_1 = 21 num_2 = 22 num_3 = 23
import numbers print("test_1 start") print(numbers.num_1) print(numbers.num_2) print(numbers.num_3) print("test_1 end")
import numbers print("test_2 start") temp1 = numbers.num_3 - numbers.num_2 print(temp1) temp1 = numbers.num_3 - numbers.num_1 print(temp1) print("test_2 end")
- Load local folders to development board with mount command.
mpremote connect COM44 mount .
- In REPL, enter the following code to run the two test programs:
>>> import test_1 >>> import test_2
Outputs in REPL:
MicroPython v1.19.1-dirty on 2022-06-22; BPI-Leaf-S3 with ESP32-S3 Type "help()" for more information. >>> import test_1 test_1 start 21 22 23 test_1 end >>> import test_2 test_2 start 1 2 test_2 end >>>
The “mount” command can be used in conjunction with the “exec” command. In this way, leaf-S3 runs python script directly and outputs the result in the terminal.
mpremote connect COM44 mount . exec "import test_1" exec "import test_2"
PS D:\temp> mpremote connect COM44 mount . exec "import test_1" exec "import test_2" Local directory . is mounted at /remote test_1 start 21 22 23 test_1 end test_2 start 1 2 test_2 end PS D:\temp>
We can get the same outputs with run command. It works by using the run command to write all code in the specified python script file to the REPL. It is less efficient compared with exec command.
mpremote connect COM44 mount . run test_1.py run test_2.py