How to use Raspberry Pi Pico with Thonny

Here’s a new Raspberry Pi Pico guide :slight_smile: “How to use Raspberry Pi Pico with Thonny”

4 Likes

After weeks of searching this is the only webpage that tells me how to set up Micropython for Win10 - the crucial SET UP THONNY section.

By this I mean that at last I can BLINK the Pico onboard LED.

On Win10, strictly following the book brought up error: ModuleNotFoundError: No module named ‘machine’.

This webpage was clear and simple AND WORKS!

Thanks from UK!

5 Likes

Hey David,

Welcome to the forum! :partying_face:

That’s brilliant, glad to hear that Michaels’ tutorial was helpful to you, I’ll let him know! Have a great day! And please let us know if you have any questions about the Pico.

3 Likes

Hi,

It’s also handy to know that if you are using the wifi version, pin 25 is not directly connected to the LED.
So the line

led = Pin(25, Pin.OUT)

Should be changed to

led = Pin(“LED”, Pin.OUT)

For the code to work properly.

https://forums.raspberrypi.com/viewtopic.php?t=336836

1 Like

Am I doing something wrong here?
I have a replacement computer and trying to look at my Pico which has a Python program to see if my backup is the latest. Any ideas?
Thanks,
Brian Steinke

1 Like

Thanks. I am playing to buy a pico. This one may help me a great deal.

1 Like

Welcome back Brian :slight_smile:

At a glance it seems your doing everything right, I have a feeling it might be wifi related but if you cant install micropython through Thonny you can manually install it by:

  1. Downloading a UF2 image: MicroPython - Python for microcontrollers
  2. As you did before hold down the bootsel button and load up Windows explorer
  3. Pop the UF2 you downloaded into the folder and observe it closes
  4. Open Thonny and connect to the Pico again - fingers crossed everything should be working!

Thonny version 4.0.0 has the links for the Pico W in the “Install and update Micropython” area.
But I have found it to be a “hit and miss”, sometimes it works other times not. It also takes some time for the links to appear, sometimes.

Manual drag and drop of the .uf2 file is what I tend to do now, it works and is much faster.

The names have been changed on the Pico W Micropython web page, they no longer have “unstable” in the name and the Pico W is on Nightly Builds, no release version. It is possible the name change has caused the links in Thonny no longer work.

Links to download pages.

Micropython Pico
Micropython Pico W

Regards
Jim

EDIT: @Brian22570 it also looks like you are running an older version of Thonny. This is what I get on Thonny 4.0.0. Although it lists with “unstable” in the name and not the lastest build.

This what I get for a Pico. Thonny seems to work better than it did a few days ago.

1 Like

Thanks Liam. All fixed.
Keep up the good work, you are a real asset to us would be makers.
Cheers,
Brian

2 Likes

Thanks James. All fixed.
Keep up the good work for us would be makers.
Cheers,
Brian

PS I can now work on submitting my parking sensor as a project for your site.

2 Likes

Hi ,thank you for your very helpful tutorial.
Your code to make the on board led flash worked but the code from the supplier Ercrow didn’t.
It throws up a syntax error at the while statement?
Can you explain what is wrong with their code or is it my set up?
Cheers Steve

Hi @Stephen232509, welcome to the forums. :smiley:
It would be helpful if you included the code in question, along with the error messages from Thonny

Wrap your code in ‘backticks’ to format it correctly. you can copy and paste the following block to get started:

```
your code here
```

Hi Michael, thanks for taking the time to help me with this.
This code posted by Elecrow, the company I purchased the micro Pi kit from does not work.
I am not sure if I have set set up the uF2 file correctly either.
Their code is:

from machine import Pin
import utime
led=Pin(25,Pin.OUT)
if_name_==“main”:
while True:
led.value(1)
utime.sleep_ms(100)
led.value(0)
utime.sleep_ms(100)

Hope you manage to get this!
Cheers Steve

PS: I can’t find the back ticks on my phone. Sorry.

Hope you don’t mind me butting in.
The problem is with the inverted commas around “Main” as far as I can tell.
They have been translated to the wrong value. Quotes rather than inverted commas.

Regards
Jim

Errored Code:

from machine import Pin
import utime
led=Pin(25,Pin.OUT)
if_name_==“*main* ”:
while True:
led.value(1)
utime.sleep_ms(100)
led.value(0)
utime.sleep_ms(100)

Correct code:

from machine import Pin
import utime
led=Pin(25,Pin.OUT)
if _name_ == "main":
    while True:
    led.value(1)
    utime.sleep_ms(100)
    led.value(0)
    utime.sleep_ms(100)

EDIT: That is the syntax error, but really if _name_ == "main": is not needed if this it the complete code.

2 Likes

Hi Jim,
thank you very much.
You were right and yes, it does work fine without the if statement.
I have never really used a forum like this before; it’s great! I am a noob so still finding my way round!
Looking forward to making progress now.
Thank you very much.
Steve

1 Like