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.
1 | print("Hello World!")
|
Blink¶
Direct download: blink.py.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | # 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)
|