This article answers the question: How do I use the Raspberry Pi Pico with MicroPython on Windows? We also show how to install the right driver for “Board CDC” (which the Pico will show up as once MicroPython is installed) on Windows 8.1.
Finally, we’ll show how to connect to the Pico using PuTTY, and a more comfortable option using Thonny (which is a Python IDE, integrating with the Pico!)
Introduction: What is Pico, what is MicroPython?
The Raspberry Pi Pico is a new microcontroller board from Raspberry Pi, sporting the in-house developed RP2040 microcontroller chip.
Raspberry Pi have designed lots of cool features into the RP2040 (my favorite is PIO – programmable IO, where you can emulate lots of hardware interfaces which require precise timing, etc. – I’ll go into it in another article in the future), and Pico is a really nice reference platform the RP2040 is implemented on.
How is a Raspberry Pi Pico different from a Raspberry Pi Zero W?
The difference between Microcontroller (Pico) and Single-Board-Computer (let’s say Pi Zero W) is roughly this: you program the Pico directly (e.g. in C), without an operating system, whereas the Pi Zero W will usually run Linux. This has advantages, like real-time, but also disadvantages – you need to know more about the hardware you are using, and need to implement a lot of functionality which you would take for granted on a modern operating system (e.g. file access). The Pico has less resources compared to the Pi Zero W (e.g. significantly less RAM, no VideoCore GPU, …) – but it draws less power, and has additional features, like the aforementioned PIO, and analog inputs (ADC).
The Pico is a good choice for projects which do not necessarily require network connectivity, HDMI output, camera input and processing. In other words, if you want to interface with hardware, have a long battery life, etc – then the Pico is for you.
What software does already exist for the Pico?
The Pico can be flashed using different software, which is provided in UF2 files (see Pico getting started guide). Raspberry Pi provides several UF2 files to get you started:
- MicroPython (which will be the focus of this article)
- Blink an LED (Blink UF2)
- Hello world (will say “Hello world” if you connect through a terminal)
- Picoprobe (use one Pico to debug another Pico)
- Reset flash memory (will set the Flash memory to empty)
There is lots more of examples to be found here (C code).
Note: I’m linking to the newest UF2 files as of 30.01.2021 – specifically MicroPython might be updated, so be sure to check on the Raspberry Pi Pico getting started page.
If the prospect of going full-in and programming in C seems a little bit daunting to you, you can get started in MicroPython. In this case, some software is pre-installed to the Raspberry Pi Pico (the MicroPython UF2 file), which will run a small Python interpreter.
It’s called MicroPython because it doesn’t support the full Python 3 standard library. MicroPython is intended for constrained environments, like the Pico. The Pico has a total of 2 MB RAM – this will not fit everything Python 3 brings along with it. Check this Github page for differences of CPython to MicroPython. Also, here’s the official MicroPython homepage, and the official MicroPython documentation.
What will you get with the MicroPython UF2?
Once MicroPython is installed on the Pico, you’ll be able to connect to the Pico using the serial console (we will show how in this article), and start writing Python code on the Pico.
Installing MicroPython on the Pico
- Remove power from the Pico
- Press the BOOTSEL button and keep it pressed
- plug in the Pico to your PC using a microUSB to USB cable
- now you can release the BOOTSEL button
The Pico should be visible in your filesystem now, as RPI-RP2:
(Sidenote: I wonder what RPI-RP1 was?)
The Pico emulates a FAT32 flash drive, which has two files in it: INDEX.HTM and INFO_UF2.TXT.
In fact, Windows Drive Manager shows Pico to be a 128 MB FAT flash drive.
Don’t make the mistake of trying to store any files on the Pico this way: they will be silently dropped. Even if it looks like they’re written, that’s just Windows caching the operations – your files will be gone! Did I mention already that the Pico actually has only 2MB Flash? It’s shamelessly lying about the 128MB here (the RP2040 is supposed to support up to 16MB flash by the way, AFAIK).
Sidenote: This reminds me a bit of my trip to India, where I bought thumb drives with 128 GB capacity – which would write your data to Nirvana. When I tried to return the drive and get my money back, the vendor was gone … the adventures to be had 🙂
However, if you copy the right kind of file – the UF2 file – to this drive, it will be recognized and written.
You can drag & drop it from your browser, after having downloaded it, or copy & paste it. Once it’s completed copying, the Pico will reboot automatically, and you won’t see a flash drive anymore.
The Pico now (after the reboot) runs MicroPython, which provides a serial port (COM-port) via USB. (In technical terms, this is USB device class 02 = Communications and CDC Control and USB device SubClass 02).
Connecting to the Pico, Windows 10
Windows 10 makes it easy for us to connect to the Pico, as the necessary COM-Port driver (usbser.inf) will be automatically installed and activated for you.
To check which COM Port it’s on, open your device manager:
Here, you’ll be able to see the new USB Serial Device, with the COM port number (which you’ll need in a second to connect), under Ports (COM & LPT).
To double-check that this is indeed the Pico, running MicroPython, you can do the following:
Click on View, and select Devices by Container:
Here you’ll see an entry “Board in FS mode”, with the two nodes “USB Composite Device” and “USB Serial Device (COM3)”. The COM3 is important, you will need to use it for PuTTY (see below).
We can investigate the devices further by right-clicking on them, and selecting the appropriate properties entry from the context menu. The properties for Board in FS mode are empty:
The USB Composite Device shows “Board in FS mode” as it’s Bus reported device description:
Note: this is the Pico running MicroPython. When you reflash it with different software, it will show different results here!
The USB serial device itself will show some interesting properties:
If you know what you are looking for, the Hardware IDs (VID = vendor id, and PID = product id) are useful:
VID_2E8A -> the vendor id is 2E8A (in hex) or 11914 (in decimal), which is Raspberry Pi
PID_0005 -> the product id is 5, which the board will show when running MicroPython (the default product id is 3)
Sidenote: Chrome Browser debug log
This information can also be obtained using the Chrome browser.
will allow you to see the currently attached Devices
Back to Windows 10:
As you see in the screenshot above, Windows 10 automatically installed usbser (USB Serial Driver) for you – so you can get started with the Pico immediately.
PuTTY is a telnet / SSH client. You will use it to connect to the Pico, and talk to MicroPython’s REPL. Download PuTTY here. (You can go with the 64-bit MSI Windows Installer for most Windows 10 installations).
Open PuTTY. Enter the right settings:
- Connection type needs to be set to Serial
- Serial Line needs to be set to whatever your investigation from above yielded. In my case, this is COM3. In your case it most likely will be something different!
- Speed can be left at 9600 for now
Click on Open, and a Terminal will open:
To get the initial prompt, press Enter once
Then you can start writing Python code after the prompt, which will be interpreted immediately. Try entering the classic “Hello world”:
MicroPython will reply with
as expected 🙂
Now that the initial contact is established, I wish you happy coding!
Thonny: a Python IDE, works with Pico!
Using PuTTY is not very comfortable for longer sessions, or when you want to load a lot of code into your Pico. Luckily, the open source application Thonny (which is installed by default on Raspberry Pi OS) is also available for Windows and integrates Pico (MicroPython) support!
Download Thonny here, and install it
Connect your Pico, as described above – it now should have a COM-Number – if you wish, you can test using the PuTTY method described above, whether you can reach your Pico.
Start Thonny, and click on the Tools menu, choose Options
Step Four: set Pico as the interpreter
Click on the Interpreter tab. You will see this screen by default:
Click and select MicroPython (Raspberry Pi Pico)
You can leave the port at “try to detect port automatically”, or set a specific port (we’ve seen above how the correct port number can be determined).
Note: the port should still show up in the drop down, so it might be a good idea to double-check it’s there:
I’m leaving it as “try to detect port automatically”. Click OK to save the setting.
Your screen should now change to this:
Step five: test
Now you can test the communication with the Pico.
into the MicroPython prompt, and press enter
You’ll see the Pico responding to you.
Congratulations, you have successfully connected Thonny with the Pico on Windows!
More complex scripts: Blinking an LED with Thonny
The REPL (read evaluate print loop) you’ve just seen is nice, but for more complex projects, we’d like to enter the source first, or load it from a file.
This is what the top part of the Thonny window can be used for.
Enter your code. In my example, we’ll blink the onboard LED (which is the hardware hello world equivalent!), and loop forever.
import time from machine import Pin print("Welcome to Pico example 2, blinking an LED") led = Pin(25, Pin.OUT) # For demo purposes, we have an infinite loop here while True: led.high() time.sleep(0.5) led.low() time.sleep(0.5)
Pay attention to proper indintation in Python (whitespace is used for control purposes in Python!)
Now click on the “run” button
Thonny will ask you where to save to
Select Raspberry Pi Pico:
I’ve chosen to name the file hello.py – Click on OK to save it
Once the OK button is pressed, your code will start executing. The on-board LED of the Pico should start blinking, and you’ll see the output in the Shell:
Note: I did not have to enter the %Run -c $EDITOR_CONTENT command, Thonny was doing it itself. The output below is from our code.
Windows 8.1 will NOT automatically load the serial driver, and show the device in an error state. Here’s how the properties for Board CDC (the Pico running MicroPython) look like:
It says that the drivers for this device were not installed (Code 28).
A solution to solve this problem is the Zadig tool, which you can download for free:
Zadig helps you to install generic USB drivers to help you access USB devices.
In our case we want the USB Serial (CDC) driver.
Select Board CDC (Interface 0) from the dropdown above, the USB Serial (CDC) in the other field. Click on Install Driver.
After the installation, you will see that the driver is now set to usbser (v220.127.116.11):
And you’ll be able to connect, as I’ve described in Windows 10, using the correct COM port number:
Pico / Serial Port on Windows 7
According to a customer, Zadig helped to install the serial port driver on Windows 7 as well, and the Pico was usable afterwards!
If you need a step-by-step guide, check out the guide for Windows 8.1 above – it should be pretty similar on a Windows 8.1 machine.
How do I stop code execution on the Pico in Thonny?
Click into the Shell, and press Ctrl+C. This should stop the current code execution:
Repeating previous statements in Thonny
It is convenient to run the same command again – press the up key on the keyboard in the shell prompt to call up a history of previous commands.
How do I know when my Pi Pico is disconnected from Thonny?
You’ll get an error message when trying to run code, something like this:
This means that Thonny can’t write to the serial port the Pico is expected to be on.
Your tips for Pico / MicroPython on Windows?
Let us know in the comments if you have any other tips for getting started with the Pico and MicroPython on Windows, we’ll update the article accordingly 🙂
Enjoy your Pico & have fun with the amazing projects you can do with it!
More Pico blog posts at PiCockpit
If you enjoyed reading this article, you might enjoy reading the following as well: