Pin names, the pin map, digital pins and PWM. More...
Functions | |
| gpio (name) | |
| Gets the GPIO number from the board header name. | |
| pin (name, mode="in", pull=None, value=None) | |
| Configures the GPIO pin from board header name. | |
| pwm (name, freq=1000, duty_u16=0) | |
| Configures GPIO pin for PWM output. | |
Variables | |
| dict | PINS |
| Every pin name on the board and the RP2040 GPIO it connects to. | |
Pin names, the pin map, digital pins and PWM.
Pins use the names printed on the board, as strings: "D0"-"D13", "D18", "D19", "A0"-"A5", "SDA", "SCL" and "LED". Names are not case-sensitive. There are no D14-D17.
| Name | RP2040 | Notes |
|---|---|---|
| D0, D1 | GPIO1, GPIO0 | UART0 RX, TX: uart(0) |
| D2, D3 | GPIO6, GPIO7 | |
| D4, D5 | GPIO8, GPIO9 | UART1 TX, RX: uart(1) |
| D6, D7 | GPIO10, GPIO15 | |
| D8, D9 | GPIO16, GPIO17 | |
| D10-D13 | GPIO13, 11, 12, 14 | SPI1 CS, MOSI, MISO, SCK: spi() |
| D18 / SDA, D19 / SCL | GPIO24, GPIO25 | I2C0: i2c(). No pull-ups on the board |
| LED | GPIO5 | Green built-in LED: On-board LED |
| A0-A2 | GPIO26-28 | RP2040 ADC, 0-3.3 V. Can also be used as digital pins |
| A3-A5 | MAX11635 AIN0-2 | On-board ADC, 0-2.048 V. Analogue only |
Some pairs of pins share a PWM channel, so they can't run different PWM signals at once: D1/D8, D0/D9, D4/D18, D5/D19, D6/A0, D11/A1, D12/A2. pwm() refuses the second pin of a pair until pin() is called on the first.
| gpio | ( | name | ) |
Gets the GPIO number from the board header name.
For MicroPython's own machine module, which numbers pins by GPIO. Two names can share a GPIO: "D18" and "SDA" are both GPIO24.
| name | Pin name, e.g. "D7" (not case-sensitive). |
| ValueError | The name is unknown, or is A3-A5 (no RP2040 GPIO). |
| TypeError | The name is not a string. |
| pin | ( | name, | |
| mode = "in", | |||
| pull = None, | |||
| value = None ) |
Configures the GPIO pin from board header name.
Sets the pin configuration and returns GPIO interface. The following functions can be used to set the state of the pin or read.
A0-A2 can be configured to work as digital pins as well.
In addition to writing & reading the pin states with the returned Pin class, the GPIO can be configured INPUT/OUTPUT or OPEN DRAIN. Internal pull-ups and pull-down resistors are also available. If function parameters listed below for GPIO configuration are left output of the function all the default setting is : DIRECTION := INPUT, PULL := NONE, and VALUE = 0.
If the pin was on PWM, calling pin() reverts the GPIO pin back to GPIO control not the peripheral it was attached to.
Refer to MicroPython documentation for more information about the returned object : https://docs.micropython.org/en/latest/library/machine.Pin.html
| name | Pin name: "D0"-"D13", "D18", "D19", "A0"-"A2", "SDA", "SCL" or "LED". |
| mode | "in", "out" or "open_drain" (drives low for 0, lets go for 1). |
| pull | None, "up" or "down": the RP2040's built-in pull resistor. |
| value | Starting level for outputs, 0 or 1; None leaves it unchanged. |
| ValueError | Unknown name, mode or pull, or an analog-only pin (A3-A5). |
| TypeError | The name is not a string. |
| pwm | ( | name, | |
| freq = 1000, | |||
| duty_u16 = 0 ) |
Configures GPIO pin for PWM output.
PWM generators on the RP2040 are set up in pairs, a PWM sliced with outputs A and B. PWM frequency can set on a per-slice basis. If a 2 PWM pins share the same PWM slice the PWM frequency of both pins will be the same. However, the user can change the duty cycle of each pair separately. PWM that share PWM slices are as follows:
- D1/D8 - D0/D9 - D4/D18 - D5/D19 - D6/A0 - D11/A1 - D12/A2
Calling pin() on a pin frees its output.
Refer to MicroPython documentation for more information about the returned object : https://docs.micropython.org/en/latest/library/machine.PWM.html
| name | Pin name: "D0"-"D13", "D18", "D19", "A0"-"A2", "SDA", "SCL" or "LED". |
| freq | Frequency in Hz, 8 Hz and up. |
| duty_u16 | Starting duty cycle, 0 (always low) to 65535 (always high); 32768 is high half the time. |
| ValueError | Unknown name, an analogue-only pin (A3-A5), or the pin shares its PWM output with one already in use. |
| dict PINS |
Every pin name on the board and the RP2040 GPIO it connects to.
A3-A5 have no RP2040 GPIO; their values are markers for the MAX11635 inputs and are not GPIO numbers. Use gpio() to look a name up.