Download Print this page

Spi; Pwm - Raspberry Pi Pico Python SDK Manual

A micropython environment for rp2040 microcontrollers

Advertisement

Raspberry Pi Pico Python SDK

3.7. SPI

Example usage:
Pico MicroPython Examples:
 1
from
 2
 3 spi = SPI(0)
 4 spi = SPI(0, 100_000)
 5 spi = SPI(0, 100_000, polarity=1, phase=1)
 6
 7 spi.write('test')
 8 spi.read(5)
 9
10 buf = bytearray(3)
11 spi.write_readinto('out', buf)
NOTE
The chip select must be managed separately using a
Table 4. Default SPI
Function
pins
SPI_BAUDRATE
SPI_POLARITY
SPI_PHASE
SPI_BITS
SPI_FIRSTBIT
SPI0_SCK
SPI0_MOSI
SPI0_MISO
SPI1_SCK
SPI1_MOSI
SPI1_MISO

3.8. PWM

Example of using PWM to fade an LED:
Pico MicroPython Examples:
 1
# Example using PWM to fade an LED.
 2
 3
import
 4
from
 5
 6
 7
# Construct PWM object, with LED on Pin(25).
3.7. SPI
https://github.com/raspberrypi/pico-micropython-examples/tree/master/spi/spi.py
machine
import
SPI
https://github.com/raspberrypi/pico-micropython-examples/tree/master/pwm/pwm_fade.py
time
machine
import
Pin, PWM
Lines 1 - 11
machine.Pin
.
Default
1,000,000
0
0
8
MSB
Pin 6
Pin 7
Pin 4
Pin 10
Pin 11
Pin 8
Lines 1 - 25
16

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