Raspberry Pi Pico Workshop for Beginners

Hey peeps, got something exciting: “Raspberry Pi Pico Workshop for Beginners”



We have been hard at work for quite a while now creating this Pico Workshop. It’s designed to take someone with little to no experience with microcontrollers, Micropython or electronics, and get them up to speed enough so they can go out and start making their own projects. If you have any questions relating to the course, or you get stuck somewhere, or just have a general question about something we covered, feel free to pop it in here.

Read more

5 Likes

Nice! Looks great.

4 Likes

Nice one @Jaryd.
I learned a lot listening to 1.5 Powering The Pico & Safety. Basics like not putting it on a metal or how to handle a micro controller. Good habbits I bypassed in my rush to see how many polarized capacitors need to explode before the LED turns on out of pity. Nice to slow down and learn some technique.
Pix :heavy_heart_exclamation:

4 Likes

Glad you got something out of it, the metal bench is always one that catches people off guard ahaha.

-Jaryd

3 Likes

Hey yall, Chapter 2 just released.

We finally get into some serious action with digital and analog inputs, PWM signals, some more MicroPython basics, as well as some practical knowledge of circuits and electrical power.

-Jaryd

3 Likes

Hey everyone, Chapter 3 just released.

We get a bit more into MicroPython and add some “intelligence” to our projects with decision-making and logic. Hope y’all enjoy!

-Jaryd

3 Likes

I’m doing this workshop at the moment. All was going well until I got to the section on servos and installing the micropython-servo library. I’ve tried installing it from Thonny 4.1.7 (on a Pi 5 running Trixie and Python 3.13.5) to my Pico 2W (MicroPython 1.26.1) as shown in the video, but it always fails with following errors:

“/home/dshan/.cache/pipkin/workspaces/2a749c5df09fe37dfada7a76ccc650af/lib/python3.13/site-packages/pip/_vendor/pkg_resources/init.py”, line 2164, in
register_finder(pkgutil.ImpImporter, find_on_path)
^^^^^^^^^^^^^^^^^^^
AttributeError: module ‘pkgutil’ has no attribute ‘ImpImporter’. Did you mean: ‘zipimporter’?
Error Command ‘[’/home/dshan/.cache/pipkin/workspaces/2a749c5df09fe37dfada7a76ccc650af/bin/python3’, ‘-I’, ‘-m’, ‘pip’, ‘–no-color’, ‘–disable-pip-version-check’, ‘–trusted-host’, ‘127.0.0.1’, ‘install’, ‘–no-compile’, ‘–use-pep517’, ‘–upgrade-strategy’, ‘only-if-needed’, ‘micropython-servo’, ‘–index-url’, ‘http://127.0.0.1:36628’]’ returned non-zero exit status 2.

I tried downloading the tar.gz package manually from PyPi and using Thonny to install it from that, but I get the same error. I’ve also tried installing it on a Debian (Trixie) laptop (also running Thonny 4.1.7 and Python 3.13.5) and got the same errors.

Does anyone know what the problem is and how to get micropython-servo installed on my Pico 2W?

1 Like

Hey @dshan , welcome to the forums!

After some light research, it looks like this may be caused by thonny looking to use some install packages that no longer exist in Python 3.13 and newer versions. Hopefully, this can be fixed by updating the setuptools library that thonny uses to install things.

I would try running this command python3 -m pip install --upgrade pip setuptools wheel , then rebooting your system. Hopefully, this will resolve this issue for you!

Thanks for your reply Samuel, unfortunately that did not work. See output attached.

Hi @dshan ,

I see. You can get around this and install this update system-wide using the following command python3 -m pip install --upgrade –break-system-packages pip setuptools wheel. The ‘note’ section of your error message goes into the reasons why not to do it this way, as this has the potential to cause damage to your base Python files.

The longer but safer method of doing this is outlined in the following guide. I would recommend following this process in general, as running Python code inside a virtual environment is the recommended standard for Raspberry Pi applications.

After you have completed the steps of this guide up to running this command, source "NAME OF VENV"/bin/activate you should then be able to run python3 -m pip install --upgrade pip setuptools wheel successfully. Just make sure you follow the rest of the guide afterwards to let Thonny know which environment it needs to operate in!

Hope this helps! :slight_smile:

Hi Samuel, thanks for the info on virtual environments. I did as instructed and it worked, sort of. I got the Python venv installed on my Pi 5 and then Thonny using the venv Python install, and then I successfully updated pip in the venv and installed micropython-servo using the updated pip, but of course that installed it into the venv also!

I need micropython-servo installed on the Pico, within its MicroPython environment. How do I do that? I still get the original error when I try to install it using Thonny set to use the MicroPython 1.26.1 env, but if I set it to use the venv Python 3.13 on the Pi it gets installed there, not on the Pico. :thinking:

Hi @dshan ,

Ahh, that’s no good. At least you had some luck with a venv. From what I can find, this is a known issue with thonny that is aimed to be addressed in a future update:

As a temporary fix, you could always just use code that interacts with your servo using direct PWM signals instead of the servo wrapper library. This will add a bit of complication to your code, but it should work just the same.

This code will do the same job as the example given by Jaryd in section 3.4 of the workshop. I have modified it so that it uses a function contained within your main code file instead of the servo library:

from machine import Pin, PWM
from time import sleep

# create a PWM object on pin 0 (change pin number to your actual GPIO)
servo = PWM(Pin(0))
servo.freq(50)  # standard servo frequency 50 Hz (20 ms period)

def write_servo(angle):
    # Move servo to given angle between 0 and 180 degrees.
    # Converts angle to an appropriate duty cycle (0.5–2.5 ms pulse).
    min_us = 500    # minimum pulse length
    max_us = 2500   # maximum pulse length
    us = min_us + (angle / 180) * (max_us - min_us)
    duty_u16 = int(us * 65535 / 20000)  # 20 ms period
    servo.duty_u16(duty_u16)

# Sweep the servo from 0 to 180 degrees and back
while True:
    for angle in range(0, 180, 5):   # start at 0 and count in 5s until 180 is reached
        
        # angle will be updated every loop so we will use it to set the servo angle
        write_servo(angle)
        sleep(0.1)
    for angle in range(180, 0, -5): # 180 to 0 degrees, 5 degrees at a time
        
        # angle will be updated every loop so we will use it to set the servo angle
        write_servo(angle)
        sleep(0.1)

Hopefully, this does the trick!

1 Like

Hey @dshan,

Very weird bug you have encountered. I have a workaround for you until it gets fixed. First of all, download and unzip the following file. This is the servo library file I just grabbed from one of my Picos that has it.

servo.zip (576 Bytes)

Then, in Thonny, open up the file view. In the top window (your computer), navigate to the place you unzipped the file. Ensure your Pico is plugged in and connected to the right COM Port (you should see it in the bottom window).

Right-click on the folder you unzipped called “servo” and select “Upload to /”. This should put the library on your Pico, and you should be able to continue as usual.

Hope this helps!

Hi Samuel, Thank you so much for this, I think it’ll get me where I want to go until Thonny is updated at least. Also might save me from trying to figure out how to use mip, etc.

1 Like

Thanks Jaryd, that seems to have done it! I figured there had to be a way to copy the library across without mucking about with mip and stuff!

Now I can get back to the course (which I’m really enjoying, hopefully my grandson will too when he gets a Pico starter kit for Christmas :+1: )

2 Likes

No worries, hope you both have a blast!

1 Like