Remote development in Python

 General audience classification icon  General audience classification icon  General audience classification icon
As developers use PCs to author software, but it is executed in the microcontroller, using a terminal over a serial connection or secure shell (SSH) may not be convenient for larger projects. For this reason, many IDEs can perform remote development with code authored in the IDE on the PC but executed on the MCU. It requires a stable connection between the development host and the microcontroller and sometimes installation of the remote development host. One of the most flexible IDEs, able to act in virtually any scenario of remote development, is Visual Studio Code[1].

Programming Raspberry Pi with regular Python can also be executed using development tools installed directly on the RPi, e.g. using Thonny[2]. It is not the case of programming with Micropython that one needs to connect to it remotely. However, installing an external development environment on a PC or Mac computer is usually more convenient. Visual Studio Code comes with a ready solution for both scenarios.

Python
In the case of the RPi programming, VS Code connects to the RPi via Secure Shell (SSH) and installs development tools remotely. The model is present in the figure 1.

 Remote development for RPi with VS Code and Python
Figure 1: Remote development for RPi with VS Code and Python

Configuring the remote target requires a few simple steps.
Initiate connection to the remote device: over SSH, the target RPi board runs Linux on ARM, here Rasbian, but is also works with other Linux distributions or even remote Docker containers exposing SSH (figures 2 and 3):

 Connecting to the remote development target from under VS Code
Figure 2: Connecting to the remote development target from under VS Code
 Connecting to the remote development target from under VS Code
Figure 3: Connecting to the remote development target from under VS Code (cont.)

Remote development is straightforward, as in the case of the local one (figure 4):

 Python remote development for RPi in action, using VS Code
Figure 4: Python remote development for RPi in action, using VS Code

Micropython
In the case of the Micropython, the connection is usually made via a serial port that is exposed either on the device's GPIOs (RX, TX) or as a Serial over USB. Micropython devices commonly expose a filesystem over the USB, alternatively to the Serial over USB. This is usually inducted with an onboard button press during the boot process. Boot system exposition enables an easy firmware (Micropython) update and source file management, such as uploading and downloading the libraries and application source code. A file named 'main.py' is executed automatically on boot if it only exists in the device's root folder and the device is not in the filesystem mode. Some devices (such as RP2040) also provide file management via Serial over USB and thus do not require enabling the filesystem mode manually but rather enable IDE to manage files along with development. For this reason, files can be stored locally and executed with REPL or stored remotely on the Micropython device. A concept of the code development for Micropython is graphically present in the figure 5.

 Remote development for Micropython-enabled devices with VS Code and Python
Figure 5: Remote development for Micropython-enabled devices with VS Code and Python (Micropython)

Remote development requires a VS Code plugin to communicate with the Micropython device. One of them is MicroPico, which is dedicated to Raspberry RP2040 (Pico and Pico W), and it can be installed and updated with VS Code extension manager (figure 6).

 MicroPico extension for Visual Studio Code
Figure 6: MicroPico extension for Visual Studio Code

Code then can be stored locally or remotely and easily executed via the right-click command (figure 7):

 Executing Python code on Micropython device
Figure 7: Executing Python code on Micropython device (RP2040)