Raspberry Pi Pico Python SDK
Pico MicroPython Examples:
1
from
machine
2
3 led = Pin(25, Pin.OUT)
4 tim = Timer()
5
def
tick(timer):
6
global
7
led.toggle()
8
9 tim.init(freq=2.5, mode=Timer.PERIODIC, callback=tick)
Typing this program into the REPL will cause the LED to start blinking, but the prompt will appear again:
>>>
The
Timer
we created will run in the background, at the interval we specified, blinking the LED. The MicroPython prompt is
still running in the foreground, and we can enter more code, or start more timers.
3.2. UART
USB serial is available from MicroPython, but the REPL is also available over UART0 by default. The default settings for
UARTs are taken from the C SDK.
Table 2. Default UART
Function
UART_BAUDRATE
UART_BITS
UART_STOP
UART0_TX
UART0_RX
UART1_TX
UART1_RX
3.3. ADC
An analogue-to-digital converter (ADC) measures some analogue signal and encodes it as a digital number. The ADC on
RP2040 measures voltages.
An ADC has two key features: its resolution, measured in digital bits, and its channels, or how many analogue signals it
can accept and convert at once. The ADC on RP2040 has a resolution of 12-bits, meaning that it can transform an
analogue signal into a digital signal as a number ranging from 0 to 4095 – though this is handled in MicroPython
transformed to a 16-bit number ranging from 0 to 65,535, so that it behaves the same as the ADC on other MicroPython
microcontrollers.
RP2040 has five ADC channels total, four of which are brought out to chip GPIOs: GP26, GP27, GP28 and GP29. On
Raspberry Pi Pico, the first three of these are brought out to GPIO pins, and the fourth can be used to measure the VSYS
voltage on the board.
The ADC's fifth input channel is connected to a temperature sensor built into RP2040.
3.2. UART
https://github.com/raspberrypi/pico-micropython-examples/tree/master/blink/blink.py
import
Pin, Timer
led
Lines 1 - 9
Default
115,200
8
1
Pin 0
Pin 1
Pin 4
Pin 5
13
Need help?
Do you have a question about the Pico Python SDK and is the answer not in the manual?