Some links in this post may be affiliate links. We may get paid if you buy something or take an action after clicking one of these, but without addictional costs for you compared to direct buying.

First steps with Raspberry PI Pico for Beginners

Raspberry PI Pico featured image
5
(1)

The new Raspberry PI Pico changes user approach to this device, because it works as microcontroller (unlikely other Raspberry PI boards working as linux computer). For this reason, starting your first steps with RPI Pico requires a different approach

In this tutorial I’m going to show you how to move your first steps with Raspberry PI Pico, installing the open source Thonny IDE (integrated development environment) and running a very simple command.

raspberry pi pico microcontroller

With the announcement of new Raspberry PI Pico, the RPI Foundation moved its firts steps on microcontrollers world. Common Raspberry PI users can be a little confused when getting this board and asking themselves “where is SD card slot?”. The answer is that no sd cards are present as Pico stores programs in its internal memory. Another common question is “What OS to use with Raspberry PI Pico?”. Same answer, there’s no operating system as with microcontrollers you will put your program directly on firmware and it will run until you won’t replace the main program.

Many of these questions are similar to ones when comparing the difference between Raspberry PI computer boards and microcontrollers (like Arduino). And Raspberry PI Pico is more similar to Arduino.

What is interesting with RPI Pico, is that you can use MicroPython to program your device.

In following paragraphs I will show you how to install Thonny in your computer to connect and program your Raspberry PI Pico.

What We Need

As usual, I suggest adding from now to your favorite e-commerce shopping cart all needed hardware, so that at the end you will be able to evaluate overall costs and decide if continuing with the project or removing them from the shopping cart. So, hardware will be only:

Check hardware prices with following links:

amazon raspberry pi pico box

Step-by-Step Procedure

To move your first steps with Raspberry PI Pico you need to install Thony IDE. This application is already installed in Raspberry PI OS Desktop. With different computer, you can install it fromt their official page: https://thonny.org.

Use links on top right side to download the installer:

Thonny download link

Execute the installation procedure according to your OS. With Windows, it is enought a double click on downloaded installer and follow setup wizard. If not present in your OS, this will also install Python in your computer.

Once installed, run Thonny to get its home window:

Thonny empty home

This window is splitted in 2 areas. The top one (labelled as “untitled”) is where you can write your scripts before running them. The bottom “Shell” is where you can use an interactive mode to run line by line your commands.

You can see from this image that the shell is running on bundled Python. This means that Thonny is running python commands on your current computer.

If you have never used your Thonny with Raspberry Pi Pico, you will need to add the MicroPython firmware to your Pico. Identify the BOOTSEL button on Pico:

Raspberry PI Pico BOOTSEL button

Press the BOOTSEL button and hold it while you connect the other end of the micro USB cable between RPI Pico and your computer. This installs your Raspberry Pi Pico as a mass storage device. You can release BOOTSEL button once you will see a new storage device in your computer, named “RPI-RPI2”.

Back to Thonny window, click on “Python” button in bottom-right side (see picture below). This will allow you selecting the Thonny interpreter:

Thonny IDE select interpreter

Select “MicroPython (Raspberry PI Pico)” option. A dialog box will pop up to install the latest version of the MicroPython firmware on your Raspberry Pi Pico. Click the “Install” button to copy the firmware to your Raspberry Pi Pico.

Thonny install micropython for raspberry pi pico warning

At the end of installation following result will be shown:

Thonny install micropython for raspberry pi pico done

Click Close. You have installed RPI Pico firmware and you will not require previous steps on next connection.

Run MicroPython on Raspberry PI Pico

When micropython installation on Pico has been finished, you will see that shell has moved interpreter to Raspberry PI Pico:

Thonny IDE ready for raspberry pi pico

A very simple command test is importing the “os” python module and asking info to your PICO device about its OS version. From thonny shell use following command:

import os

This will import os module. Then:

os.uname()

This will return following info:

Thonny raspberry pi pico first command

So showing you RPI Pico info.

Execute your First Python Script

Executing your first script is also simple, moreover if you are going to run it from your connected computer.

Our first example makes the Pico on-board LED blinking, following the most common microcontroller first example.

In your Thonny script section (top window) add following code:

from machine import Pin, Timer
led = Pin(25, Pin.OUT)
timer = Timer()

def blink(timer):
    led.toggle()

timer.init(freq=25, mode=Timer.PERIODIC, callback=blink)

This simple code imports required modules. Then it associate to a “led” variable it internal LED pin number (25) and set this to output mode.

A “timer” variable is initialized and then a blink function is defined. This function is a timer callback function, that means this will be called in a timer instance and will executed at each timer trigger. Its scope is only toggling our on-board LED: if LED is on, this will put to off; if LED is off, this will put to on.

Timer init statement will start trigeering blink function 25 times for second (frequency value).

Click “Run” icon from your Thonny IDE. This will require (only for your script first run) where to save your python code:

Thonny save options

Select “This computer” and then select path and file name on follwing window.

After saving, your python script will start running and you will see your board LED blinking. Use the “Stop” button from thonny to stop script execution.

Common Problems With Windows Computers

Some Windows users can experience problems connecting Raspberry PI Pico to their PC.

While the first part should go without problems, installing Pico firmware could result in RPI no more visible from your computer. They can see Raspberry PI Pico in computer devices, but listed as a generic “Board CDC” with a yellow warning icon. Moreover, when trying to forcing connection from thonny by manually configuring interpreter, it can result in access denied errors.

This problem is common to Windows 7 and requires manually installing drivers. Even if Thonny can be installed without an administrative user, drivers require administrator permissions. The procedure, shared from a user on Raspberry PI forum, has following steps:

  • Download the USB CDC driver from https://www.microchip.com/SWLibraryWeb/ … COM_Driver
  • unzip the amtel_devices_cdc.inf file to a folder named “pico-serial”
  • Change the name of amtel_devices_cdc.inf file to pico-serial.inf
  • open/edit the “pico-serial.inf” in a basic editor like notepad
  • remove and replace the lines under the following headings:
[DeviceList] 
%PI_CDC_PICO%=DriverInstall, USB\VID_2E8A&PID_0005&MI_00

[DeviceList.NTAMD64]
%PI_CDC_PICO%=DriverInstall, USB\VID_2E8A&PID_0005&MI_00 

[DeviceList.NTIA64]
%PI_CDC_PICO%=DriverInstall, USB\VID_2E8A&PID_0005&MI_00 

[DeviceList.NT]
%PI_CDC_PICO%=DriverInstall, USB\VID_2E8A&PID_0005&MI_00

[Strings] 
Manufacturer = "ATMEL, Inc." 
PI_CDC_PICO = "Pi Pico Serial Port" 
Serial.SvcDesc = "Pi Pico Serial Driver"
  • Close and save and make sure your file retains the name as pico-serial.inf
  • Go to your pc device list, find the pico under Ports, named something like CDC Device. A yellow exclamation mark indicates it.
  • Right click on the CDC Device and update or install the driver choosing the file you created from the location you saved it at.

This procedure is available at https://www.raspberrypi.org/forums/viewtopic.php?t=300633.

A pre-configured “inf” file (compressed) can be get from my download area: pico-serial.zip

Enjoy!

How useful was this post?

Click on a star to rate it anonymously!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Leave a Reply

Your email address will not be published. Required fields are marked *

I accept the Privacy Policy