Raspberry Pi Pico Python SDK
16
wrap_target()
17
label("bitloop")
18
out(x, 1)
19
jmp(not_x, "do_zero")
20
jmp("bitloop")
21
label("do_zero")
22
nop()
23
wrap()
24
25
26
# Create the StateMachine with the ws2812 program, outputting on Pin(22).
27 sm = rp2.StateMachine(0, ws2812, freq=8_000_000, sideset_base=Pin(22))
28
29
# Start the StateMachine, it will wait for data on its FIFO.
30 sm.active(1)
31
32
# Display a pattern on the LEDs via an array of LED RGB values.
33 ar = array.array("I",
34
35
# Cycle colours.
36
for
i in
37
for
38
39
40
41
42
43
44
sm.put(ar, 8)
45
time.sleep_ms(50)
46
47
# Fade out.
48
for
i in range(24):
49
for
50
51
sm.put(ar, 8)
52
time.sleep_ms(50)
3.9.3. UART TX
A UART TX example,
Pico MicroPython Examples:
1
# Example using PIO to create a UART TX interface
2
3
from
4
from
5
6 UART_BAUD =
7 PIN_BASE =
8 NUM_UARTS =
9
10
11 @asm_pio(sideset_init=PIO.OUT_HIGH, out_init=PIO.OUT_HIGH, out_shiftdir=PIO.SHIFT_RIGHT)
12
def
uart_tx():
13
# Block with TX deasserted until data available
14
pull()
15
# Initialise bit counter, assert start bit for 8 cycles
16
set(x, 7)
3.9. PIO Support
.side(0)
.side(1)
.side(1)
.side(0)
[0
for
_ in range(NUM_LEDS)])
range(4
* NUM_LEDS):
j in range(NUM_LEDS):
r = j *
100
// (NUM_LEDS - 1)
b =
100
- j *
100
// (NUM_LEDS - 1)
if
j != i % NUM_LEDS:
r >>=
3
b >>=
3
ar[j] = r <<
16
| b
j in range(NUM_LEDS):
ar[j] >>=
1
https://github.com/raspberrypi/pico-micropython-examples/tree/master/pio/pio_uart_tx.py
machine
import
Pin
rp2
import
PIO, StateMachine, asm_pio
115200
10
8
.side(0)
[T3 - 1]
[T1 - 1]
[T2 - 1]
[T2 - 1]
[7]
Lines 1 - 42
22
Need help?
Do you have a question about the Pico Python SDK and is the answer not in the manual?