BPI-Leaf-S3 Load folders to development board with mount command

Introduction

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.

Video demo:

Preparation

  • Python environment
  • Mpremote plug-in
  • Development board

You can refer to the previous post for basic file operations.

BPI-Leaf-S3 Program in VS code with mpremote plug-in.

Getting started

  1. Prepare a folder with some python script files. Open the folder in VS code.

numbers.py:

num_1 = 21
num_2 = 22
num_3 = 23

test_1.py:

import numbers
print("test_1 start")
print(numbers.num_1)
print(numbers.num_2)
print(numbers.num_3)
print("test_1 end")

test_2.py:

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")
  1. Load local folders to development board with mount command.
mpremote connect COM44 mount .
  1. 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
>>>

Exec command

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"

Outputs:

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> 

Run command

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
1 Like

Some use cases and small talk for the #micropython #mpremote tool

Fixed the Bug of Mpremote on Windows and submitted to the authorities :