BPI-Leaf-S3 Program in VS code with mpremote tool

The Mpremote command line tool is a python plugin developed by the Micropython official organization.

It works on operating systems that can install standard python3 environment, and can be paired with any IDE or text editor.

For instance, you can start debugging MicroPython code at the terminal of VS code.

Video demo:

Leaf-S3 VS code Mpremote - ixigua.com

Establishment of operating environment

Install standard python3 environment

Download and install python3 for the corresponding operating system from https://www.python.org/downloads/.

Install python plugin

Mpremote has been released in pypi.org, you can install python plugin by running the following code in the terminal:

python -m pip install mpremote

Enter MicroPython REPL

Select or make a directory which can be used as your workspace.

Click the “Terminal” menu to create a new window so that you can enter commands in the terminal.

  • List all available commands
python -m mpremote --help
  • List the commands of serial interfaces
python -m mpremote connect list
  • Connect to the serial interface and enter the MicroPython REPL
python -m mpremote connect COM1 repl

COM1 is the format of the serial interface on Windows, which may be /dev/ttyacm0 on Linux, or /dev/cu.usbmodem01 on MacOS.

After entering the REPL, you can edit MicroPython code and run it on the development board.

>>>print("Hello")

You can use the shortcut key “ctrl + ]” to exit the REPL.

Basic operation commands

Create a new python file “main.py” in the workspace directory. Enter the MicroPython code and save it.

print("start")
for i in range(10):
	print(i)
print("end")

ls

Print the files list.

python -m mpremote connect COM1 ls

Output in the terminal:

ls :
		139 boot.py

cat

Print the content of files.

The basic format is “cat : filename”, “:” can be omitted.

This command can only operate the file stored on the development board.

python -m mpremote connect COM1 cat :boot.py

Output in the terminal:

cat :boot.py
# This file is executed on every boot (including wake-boot from deepsleep)
#import esp
#esp.osdebug(None)
#import webrepl
#webrepl.start()

cp

Copy files from development board to PC

python -m mpremote connect COM1 cp :boot.py ./boot.py

Then “boot.py” will be copied to the path of current terminal. We can click it to open the file.

Copy files from PC to development board

python -m mpremote connect COM1 cp ./main.py :mian.py

The “main.py” file in the current terminal path will be copied to the root path of the development board. You can run ls and cat commands to view the file in the development board.

Enter the REPL and reset the development board by using shortcut key “CTRL + D”. You can see the running results of “main.py” on the development board.

>>>
MPY: soft reboot
start
0
1
2
3
4
5
6
7
8
9
end
MicroPython v1.19.1 on 2022-08-18; BPI-Leaf-S3 with ESP32-S3
Type "help()" for more information.
>>>

run

Using the run command, you can directly input the local MicroPython code on the PC to the REPL of the development board and print out the program output results on the terminal. The program will automatically end the occupation of the terminal after running.

You can use the keyboard shortcut “CTRL +C” to interrupt the Mpremote tool, but the program will continue to run on the development board until the ending.

python -m mpremote connect COM1 run ./main.py

Outputs:

start
0
1
2
3
4
5
6
7
8
9
end

rm

“rm” can used to remove files.

python -m mpremote connect COM1 rm :main.py

Run the ls command to check whether the file is removed successfully.

Banana Pi BPI-Leaf-S3 wiki page: https://wiki.banana-pi.org/BPI-Leaf-S3

Banana pi BPI-Leaf-S3 with ESP32-S3 Use mpremote tool to mount the local directory on the device