Download Print this page

Pio Support - Raspberry Pi Pico Python SDK Manual

A micropython environment for rp2040 microcontrollers

Advertisement

Raspberry Pi Pico Python SDK
 8 pwm = PWM(Pin(25))
 9
10
# Set the PWM frequency.
11 pwm.freq(1000)
12
13
# Fade the LED in and out a few times.
14 duty =
15 direction =
16
for
_ in
17
duty += direction
18
if
19
20
21
elif
22
23
24
pwm.duty_u16(duty * duty)
25
time.sleep(0.001)

3.9. PIO Support

Current support allows you to define Programmable IO (PIO) Assembler blocks and using them in the PIO peripheral, more
documentation around PIO can be found in
C/C++ SDK
book.
The Raspberry Pi Pico MicroPython introduces a new
PIO program, and the configuration of the state machine, into 2 logical parts:
The program definition, including how many pins are used and if they are in/out pins. This goes in the
definition. This is close to what the
in Python).
The program instantiation, which sets the frequency of the state machine and which pins to bind to. These get set
when setting a SM to run a particular program.
The aim was to allow a program to be defined once and then easily instantiated multiple times (if needed) with different
GPIO. Another aim was to make it easy to basic things without getting weighed down in too much PIO/SM configuration.
Example usage, to blink the on-board LED connected to GPIO 25,
Pico MicroPython Examples:
 1
import
 2
from
 3
from
 4
 5
# Define the blink program.
 
output pin.
 6
# Use lots of delays to make the blinking visible by eye.
 7 @asm_pio(set_init=rp2.PIO.OUT_LOW)
 8
def
blink():
 9
wrap_target()
10
set(pins, 1)
11
nop()
12
nop()
13
nop()
14
nop()
15
set(pins, 0)
16
nop()
17
nop()
3.9. PIO Support
0
1
range(8
* 256):
duty > 255:
duty =
255
direction =
-1
duty < 0:
duty =
0
direction =
1
pioasm
https://github.com/raspberrypi/pico-micropython-examples/tree/master/pio/pio_blink.py
time
rp2
import
PIO, asm_pio
machine
import
Pin
It has one GPIO to bind to on the set instruction, which is an
[31]
[31]
[31]
[31]
[31]
[31]
[31]
[31]
Chapter 3
of the
RP2040 Datasheet
@rp2.asm_pio
decorator, along with a
tool from the SDK would generate from a
and
Chapter 4
of the
Raspberry Pi Pico
rp2.PIO
class. The definition of a
.pio
file (but here it's all defined
Lines 1 - 28
@rp2.asm_pio
17

Advertisement

loading
Need help?

Need help?

Do you have a question about the Pico Python SDK and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Pico seriesPico 2