Official Logo

IoT Unlocked: Your Journey to Innovation Starts Now

How To Get Started with Raspberry Pi Pico in 2024

If you are beginner or want to start with Raspberry Pi Pico and MicroPython for Internet of Things projects. Here’s is How to Get Started with Raspberry Pi Pico in 2024.

In the ever-expanding world of DIY electronics, Raspberry Pi Pico has emerged as a game-changer, offering a powerful yet affordable microcontroller platform for enthusiasts and professionals alike. In 2024, Raspberry Pi Pico continues to be a popular choice for DIY enthusiasts and IoT professionals due to its affordability, versatility, and powerful RP2040 chip.

If you’re new to the world of microcontrollers or looking to dive into the latest advancements, this step-by-step guide will help you get started with Raspberry Pi Pico and embark on your coding journey. From setting up your development environment to diving into hands-on projects, this guide will equip you with the knowledge and skills to unlock the full potential of Raspberry Pi Pico.

What You’ll Need To Get Started with Raspberry Pi Pico

  • Raspberry Pi Pico: Choose the Pico H or W variant for pre-soldered headers.
  • Micro-USB Cable: For connecting the Pico to your computer.
  • Thonny Python IDE: A user-friendly IDE for writing MicroPython code

Step 1: Connecting the Raspberry Pi Pico

  • Connect the Raspberry Pi Pico to your computer using the Micro-USB cable by pressing the Boot shell button.
  • Your computer should recognize the Pico as an external device.
  • You need to go to download the latest firmware https://micropython.org/download/
  • Look for Pico Raspberry Pi and click to find the latest available firmware
  • Download the latest xxx.uf2 firmware from the Releases
Raspberry Pi Pico Instruction - Connecting the Raspberry Pi Pico
Credit: Raspberry Pi

Once you drop the firmware file into the external drive created by Raspberry Pi Pico, it will be auto closed and you will get a new port for the device.

Step 2: Download and Setup the Thonny IDE

  • To download the Thonny you need to go to it’s official website https://thonny.org/
  • Click on download as per your operation system
  • Install the Thonny IDE from your downloaded folder
  • Open the Thonny and click on Run -> Configure Interpreter
    How To Get Started with Raspberry Pi Pico - Thonny IDE
  • You need to choose MicroPython (Raspberry Pi Pico) from the list and also choose the PORT for Raspberry Pi Pico
    Thonny IDE Setup for Raspberry Pi Pico

Now you are good to go for running your first Raspberry Pi Pico and MicroPython.

Step 3: Writing Your First LED Blinking Program

Now that Raspberry Pi Pico is connected, let’s write your first program to blink the onboard LED.

  • In Thonny, create a new MicroPython file.
  • Write a simple LED blinking program for onboard LED of the Pico.
import machine
import time

led =  machine.Pin('LED', machine.Pin.OUT)

while True:
    led.on()
    time.sleep(0.5)
    led.off()
    time.sleep(0.5)
    
  1. Importing Modules
    • import machine: This imports the machine module, which provides access to the hardware-specific features of the microcontroller, such as GPIO (General Purpose Input/Output) pins, ADC (Analog to Digital Converter), and others.
    • import time: This imports the time module, which includes functions related to time, such as delays (pausing the program for a specified amount of time).
  2. Setting Up the LED
    • led = machine.Pin('LED', machine.Pin.OUT): This line initializes a GPIO pin as an output pin to control an LED. The machine.Pin class is used to interact with the GPIO pins. 'LED' specifies the pin identifier (which, in this case, is a placeholder and should be replaced with the actual pin number or identifier on your specific device). The second argument, machine.Pin.OUT, configures the pin as an output, meaning it can send power out from the microcontroller to an external component (in this case, an LED).
  3. The Blinking Loop
    • The while True: creates an infinite loop, meaning the code inside this loop will repeat forever, or until the device is turned off or the program is otherwise interrupted.
      • led.on(): This turns the LED on by sending a high signal (typically 3.3V or 5V, depending on the microcontroller) to the pin connected to the LED.
      • time.sleep(0.5): This pauses the program for 0.5 seconds (500 milliseconds), leaving the LED on during this time.
      • led.off(): This turns the LED off by sending a low signal (0V) to the pin, which stops the current flow to the LED.
      • time.sleep(0.5): Again, the program pauses for 0.5 seconds, this time with the LED off.

Note: The exact pin identifier 'LED' in the line led = machine.Pin('LED', machine.Pin.OUT) is a placeholder and should be replaced with the specific identifier or pin number used for the LED on your device. Some boards might have a built-in LED that could be referenced by a name like 'LED', but for others, you’ll need to use the pin number (e.g., machine.Pin(25, machine.Pin.OUT) for the Raspberry Pi Pico’s onboard LED).

Step 4: Running Your Program

  • Click on Save button form Menu bar
  • Popup will come up and will ask where you want to save the code
  • Save your MicroPython script on the Pico by giving name as “blink.py“.
  • Run the script and observe the onboard LED blink, it should started blinking in every half second.

Step 5: Exploring Further

Once you’ve successfully made the LED blink, you can start experimenting with more complex projects:

  • Connect external LEDs, buttons, or sensors to the GPIO pins.
  • Write programs to interact with these components.

Controlling an external LED with a button

Raspberry Pi Pico features a plethora of GPIO pins that can be used to interface with various sensors and actuators. We’ll explore how to interact with GPIO pins using MicroPython and connect external components like LEDs, buttons, and sensors.

import machine
import time

led_pin = machine.Pin(15, machine.Pin.OUT)
button_pin = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_DOWN)

while True:
    if button_pin.value():
        led_pin.on()
    else:
        led_pin.off()
    time.sleep(0.1)
Checkout : What Is a Raspberry Pi Pico W and What Can You Use It For?

Conclusion

Congratulations! You’ve now completed How to get started with Raspberry Pi Pico programming in 2024. Armed with this knowledge, you’re ready to embark on your own DIY electronics adventures, whether it’s building robots, creating IoT devices, or prototyping new inventions.

The Raspberry Pi Pico is a gateway to endless possibilities in electronics and programming. With these steps, you’re well on your way to creating amazing projects and learning new skills.


Remember, the key to mastering the Raspberry Pi Pico is practice and experimentation. Have fun exploring the capabilities of your new microcontroller! 🚀

Share your love