Raspberry Pi Pico Introductory Examples

The following short Python programs will demonstrate essential operation of the Raspberry Pi Pico board. These use only the onboard hardware and the serial console. Each can be run by copying the program into code.py on the CIRCUITPY drive offered by the board. The text can be pasted directly from this page, or each file can be downloaded from the CircuitPython sample code folder on this site.

Hello

This is the default program included in a fresh CircuitPython installation as code.py.

Direct download: hello.py.

1 print(“Hello World!”)

Blink

Direct download: blink.py.

# pico_blink.py

# Raspberry Pi Pico - Blink demo

# Blink the onboard LED and print messages to the serial console.

import board
import time
from digitalio import DigitalInOut, Direction, Pull

#---------------------------------------------------------------
# Set up the hardware: script equivalent to Arduino setup()
# Set up built-in green LED
led = DigitalInOut(board.LED)  # GP25
led.direction = Direction.OUTPUT

#---------------------------------------------------------------
# Run the main loop: script equivalent to Arduino loop()

while True:
    led.value = True
    print("On")
    time.sleep(1.0)

    led.value = False
    print("Off")
    time.sleep(1.0)

Source: Raspberry Pi Pico Introductory Examples


About The Author

Muhammad Bilal

I am highly skilled and motivated individual with a Master's degree in Computer Science. I have extensive experience in technical writing and a deep understanding of SEO practices.