Digital Input and Output
Digital Input
Set a GPIO to input mode and read digital signals. For example, to set GPIO1 to input and read its level (try connecting it to GND with a jumper wire):
The dir subcommand sets input mode. The pull subcommand enables the pull-up resistor to fix the signal high when unconnected. get reads the GPIO signal level.
On the Pico, you can read the digital signal level from the CPU even if the function is not SIO. For example, you can monitor UART RX on GPIO1:
Digital Output
Set a GPIO to output mode and output a digital signal. For example, to turn on the built-in LED (GPIO25) with a high signal:
The func subcommand sets the function to sio (Single-cycle IO). SIO is a special block that the CPU can access in one cycle, and some of its registers are assigned to GPIO I/O. The dir subcommand sets output mode, and put sets the output value.
The gpio command also has repeat and sleep subcommands for repeating actions and adding delays. For example, to blink the LED:
You can also use the toggle subcommand to invert the output value and blink the LED more simply:
You can observe GPIO signals with a logic analyzer:
L:/>la enable -p 25
L:/>gpio 25 -B func:sio dir:out repeat:20 {toggle sleep:100}
L:/>la print
Time [usec] P25
│
:
0.00 └─┐
:
99208.00 ┌─┘
:
199199.52 └─┐
:
299194.56 ┌─┘
:
Start capture with la enable, operate the GPIO, then display the captured data with la print.
If you set the function to something other than SIO, the output value set by put is ignored. For example, assigning UART RX to GPIO1 and setting output high:
L:/>gpio 1 func:uart dir:out put:1
GPIO1 lo~ func:UART0 RX dir:out pull:down drive:4mA slew:slow hyst:on
The pin state is lo~, indicating the set value is ignored. The ~ means the set value and actual signal differ.
Even with SIO, if the direction is input, the set value is ignored:
It may look like the set value is reflected, but this is due to the pin state being high for another reason (e.g., a hardware bug in Pico 2). Setting the value to 0 shows it is ignored:
Conclusion: To output digital signals from the CPU, set the function to SIO and the direction to output. Otherwise, the output value does not affect the pin state, so there are no side effects.