How To Use Thonny To Program The Pico 2 W

This post will explain how to program the Pico 2 W using MicroPython and Thonny. This assumes you have already completed the initial setup of the Pico as described in this post: How To Set Up A Raspberry Pi Pico 2 W

To write and upload code to the Pico, you’ll need a development environment. Thonny is a beginner-friendly IDE for MicroPython.  I like Thonny because they have done a nice job of integrating it with the RPI Pico.

Steps To Configure and Test Thonny integration with Pico

  1. Install Thonny:
    • Download Thonny from thonny.org for your operating system (Windows, macOS, or Linux). 
    • Install it by following the installer instructions. 
  2. Configure Thonny for Pico:
    • Open Thonny. 
    • Go to View and make sure that “Files” is checked. This will display the Thonny file explorer on the left side of the screen.
    • Go to Tools > Options > Interpreter. 
    • Select MicroPython (Raspberry Pi Pico) from the interpreter dropdown. 
    • If the Pico is connected via USB, Thonny should detect it automatically. If not, ensure the USB cable is data-capable (not just power) and try reconnecting the Pico. When the Pico is connected, Thonny will display the Pico file system at the bottom of the right hand file viewer.
  3. Test the Connection:
    • In Thonny, open the Shell (bottom panel). 
    • Type print(“Hello, Pico!”) and press Enter. If MicroPython is set up correctly, the Shell should respond with Hello, Pico!. 

Write and Run Your First Program 

Here’s a simple example to blink the Pico’s onboard LED (on GPIO 25 for Pico, or the built-in LED for Pico W). 

  1. Create a New Script:  
  • In Thonny, click File > New to open a new script. 
  • Copy and paste the following code: 
from machine import Pin  

import time  

led = Pin(25, Pin.OUT) # Use "LED" instead of 25 for Pico W  

while True:  

led.toggle()  

time.sleep(1)

  1. Save and Run:
    • Save the file to the Pico by clicking File > Save As, selecting Raspberry Pi Pico, and naming it main.py. 
    • Click the green Run button in Thonny or press F5. The onboard LED should blink every second. 

Finally…

This post described how to use Thonny to program the Pico. If you want to explore how to use the RPI-APP-FRAMEWORK check out the related posts.

Total
0
Shares
Related Posts