Introductory Examples - Raspberry Pi Pico¶
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.
Related Pages
Hello¶
This is the default program included in a fresh CircuitPython installation as code.py
.
Direct download: hello.py.
1print("Hello World!")
Blink¶
Direct download: blink.py.
1# pico_blink.py
2
3# Raspberry Pi Pico - Blink demo
4
5# Blink the onboard LED and print messages to the serial console.
6
7import board
8import time
9from digitalio import DigitalInOut, Direction, Pull
10
11#---------------------------------------------------------------
12# Set up the hardware: script equivalent to Arduino setup()
13# Set up built-in green LED
14led = DigitalInOut(board.LED) # GP25
15led.direction = Direction.OUTPUT
16
17#---------------------------------------------------------------
18# Run the main loop: script equivalent to Arduino loop()
19
20while True:
21 led.value = True
22 print("On")
23 time.sleep(1.0)
24
25 led.value = False
26 print("Off")
27 time.sleep(1.0)