client_picod module

Declares constants and interfaces for compatibility with picod.

As common in picod, methods return a tuple of the status of the operation and the actual result (payload).

Interfaces

class gpiosvr.client_picod.PicodApi

Bases: PigpioMinimalApi

Interface representing a stripped-down, async version of picod’s picod class.

abstract async serial_open(channel: int, tx: int, rx: int, baud: int, cts: int = 255, rts: int = 255, data_bits: int = 8, stop_bits: int = 1, parity: int = 0) tuple

Opens a serial UART channel.

Parameters:
  • channel (int) – The UART channel to open on the Pico device, 0 or 1. Note: In pigpio, the parameter is called handle.

  • tx (int) – The GPIO to use for transmit. The allowed values depend on the channel. See TX.

  • rx (int) – The GPIO to use for receive. The allowed values depend on the channel. See RX.

  • baud (int) – The baud rate in bits per second, from 120 to 4000000.

  • cts (int) – The GPIO to use for CTS. The allowed values depend on the channel. See CTS.

  • rts (int) – The GPIO to use for RTS. The allowed values depend on the channel. See RTS.

  • data_bits (int) – The number of data bits, from 5 to 8.

  • stop_bits (int) – The number of stop bits, 1 or 2.

  • parity (int | PARITY_NONE | PARITY_EVEN | PARITY_ODD) – The parity bit.

Returns:

A tuple of the processing status and the accepted baud rate.

Return type:

tuple(Status, int)

abstract async serial_read(channel: int, count: int) tuple

Reads bytes from a serial UART channel.

Parameters:

channel (int) – The UART channel to read from. Note: In pigpio, the parameter is called handle.

Returns:

A tuple of status and up to count bytes.

Return type:

tuple(Status, bytearray)

abstract async serial_write(channel: int, data: bytes) tuple

Writes bytes to a serial UART channel.

Parameters:
  • channel (int) – The UART channel to write to. Note: In pigpio, the parameter is called handle.

  • data – The bytes to write.

Tyoe data:

bytes | bytearray

Returns:

A tuple of status and None.

Return type:

tuple(Status, None)

abstract async serial_close(channel: int) tuple

Closes a serial UART channel and frees the associated GPIO.

Parameters:

channel – The UART channel to close. Note: In pigpio, the parameter is called handle.

Returns:

A tuple of status and None.

Return type:

tuple(Status, None)

abstract async reset() tuple

Resets the Pico device, i.e. frees GPIOs, closes I2C, SPI, serial (UART) and PWM interfaces.

All the GPIOs will be unassigned.

Returns:

A tuple of status and None.

Return type:

tuple(Status, None)

abstract async uid() tuple

Returns the unique ID of the Pico device (64-bit number).

The Raspberry Pico does not have an on-board unique identifier as all instances of RP2040 silicon are identical and have no persistent state. However, the Pico boots from serial NOR flash devices which have a 64-bit unique ID as a standard feature, and there is a 1:1 association between the Pico device and the flash, so this is suitable for use as a unique identifier.

Returns:

A tuple of status and the UID.

Return type:

tuple(Status, int)

abstract async sleep(time_s: float) tuple

Sleeps the Pico device for the given duration in seconds.

Sleeping the Pico device may be useful if you are expecting a burst of GPIO level changes. Sleeping will help prevent USB activity during the burst, minimizing lost GPIO level changes.

Parameters:

time_s (float) – The sleep time in seconds, which may also be a fraction of a second.

Returns:

A tuple of status and None.

Return type:

tuple(Status, None)

abstract async tick() tuple

Returns the current tick of the Pico device, i.e. a value representing its internal clock time.

Returns:

A tuple of status and the tick value.

Return type:

tuple(Status, int)

Constants and defaults

class gpiosvr.client_picod.GpioFunction(value)

int values representing the functions of specific GPIOs.

XIP = 0
SPI = 1
UART = 2
I2C = 3
PWM = 4
GPIO = 5
PIO0 = 6
PIO1 = 7
GPCK = 8
USB = 9
NULL = 15
class gpiosvr.client_picod.Status(value)

int values representing the processing status of a request.

OKAY = 0
BAD_CHANNEL = 1
CHANNEL_CLOSED = 2
NO_REPLY = 7
GPIO_IN_USE = 8
TIMED_OUT = 10
ERROR = -1
class gpiosvr.client_picod.Uart(value)

Constants for the initialization of UART channels.

TX = ((0, 12, 16, 28, 255), (4, 8, 20, 24, 255))
RX = ((1, 13, 17, 29, 255), (5, 9, 21, 25, 255))
CTS = ((2, 14, 18, 255), (6, 10, 22, 26, 255))
RTS = ((3, 15, 19, 255), (7, 11, 23, 27, 255))
PARITY_NONE = 0
PARITY_EVEN = 1
PARITY_ODD = 2
class gpiosvr.client_picod.Pwm(value)

Constants for the initialization of pulse width modulation (PWM).

CLOCK_HZ = 125000000.0