Pico – Developing for Raspberry Pi Pico (W) with Python

This article describes how to set up the development environment for programming the Raspberry Pi Pico or Raspberry Pi Pico W with the MicroPython programming language on a Windows PC.

First, you have to install the correct version of the MicroPython firmware on the Raspberry Pi Pico board: See here for instructions on how to install the firmware with drag-and-drop. Make sure you install the correct firmware depending on your board:

  • MicroPython for Raspberry Pi Pico
  • MicroPython for Raspberry Pi Pico W (with support for WLAN)

Second, you need a (integrated) development environment. The one proposed here is the Thonny Python IDE. Download it from the website and install it. After installation, connect your Pico to an USB port of your PC, start Thonny, from the Run menu select Select Interpreter… and in the first drop-down list select the interpreter MicroPython (Raspberry Pi Pico). IMPORTANT: If you don’t see the menu bar, click the link Switch to regular mode in the top-right corner and restart Thonny.

  • The top-left part shows the files in your current project directory on the PC.
  • At the bottom left you see the files currently existing on the target Raspberry Pi Pico. At the beginning you see none. You can up- and download files between PC and target by selection files an using the context menu.
  • In the top-right frame you can edit source files. Files are opened in tabs.
  • The botton-right frame is a terminal connected to your target. I.e. you may execute any Python commands directly on your target.

You can upload and start the currently displayed source code by clicking the green button. The red button stops the execution.

Each dependent Python module (source file), e.g. config.py and mqtt_as.py in the above example, must be uploaded to the target before the main module (test01.py in the example) is started. The standard Python libraries are contained in the firmware (not visible in the files list).

More documentation:

Caveats

Some caveats concerning Python / MicroPython as programming language for microcontrollers:

  • No support for debugging with breakpoints, varibale inspection etc. I.e. debugging has to be done using print statements.
  • The IDE (Thonny) is quite poor e.g. compared to Visual Studio Code: No/very poor IntelliSense, help for library functions, error checking already in editor, refactoring, integration with Git or other version control systems, …
  • Performance: Execution can be slower compared to compiled languages like C / C++.

But …

  • Python is much more readable than C / C++.
  • With Python you will most likely achieve your goals faster.
  • If you don’t have any knowledge of C or C++ yet, Python is probably your preferred language.

Table of Contents