This is an old revision of the document!


Remote development in Python

Programming Raspberry Pi with regular Python can be executed using development tools installed directly on the RPi, i.e. using Thonny[1]. 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.

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):

Figure 2: 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):

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 are used to 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.

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

Remote development requires a VS Code plugin able 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).

Figure 6: MicroPico extension for Visual Studio Code
en/iot-open/scriptingprogramming/remotedevelopment.1696183154.txt.gz · Last modified: 2023/10/01 17:59 by pczekalski
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0