viam.components.board

Submodules

Package Contents

Classes

Board

Board represents a physical general purpose compute board that contains various

class viam.components.board.Board(name: str)[source]

Board represents a physical general purpose compute board that contains various components such as analog readers, and digital interrupts.

This acts as an abstract base class for any drivers representing specific board implementations. This cannot be used on its own. If the __init__() function is overridden, it must call the super().__init__() function.

class Attributes[source]
remote :bool

Indicates whether this board is accessed over a remote connection, e.g. gRPC.

class AnalogReader(name: str)[source]

AnalogReader represents an analog pin reader that resides on a Board.

abstract async read(*, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs) int[source]

Read the current value.

Returns

The current value.

Return type

int

class DigitalInterrupt(name: str)[source]

DigitalInterrupt represents a configured interrupt on the Board that when interrupted, calls the added callbacks. Post processors can be added to modify what Value it ultimately returns.

abstract async value(*, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs) int[source]

Get the current value of the interrupt, which is based on the type of interrupt.

Returns

The current value.

Return type

int

abstract async tick(high: bool, nanos: int)[source]

This method is to be called either manually if the interrupt is a proxy to some real hardware interrupt or for tests.

Parameters
  • high (bool) – If the signal of the interrupt is high.

  • nanos (int) – Nanoseconds from an arbitrary point in time, but always increasing and always needs to be accurate. Using time.time_ns() would be acceptable.

abstract async add_callback(queue: multiprocessing.Queue)[source]

Add a callback to be sent the low/high value on tick().

Parameters

queue (Queue) – The receiving queue.

abstract async add_post_processor(processor: PostProcessor)[source]

Add a post processor that should be used to modify what is returned by self.value()

Parameters

processor (PostProcessor) – The post processor to add.

class GPIOPin(name: str)[source]

Abstract representation of an individual GPIO pin on a board

abstract async set(high: bool, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs)[source]

Set the pin to either low or high.

Parameters

high (bool) – When true, sets the pin to high. When false, sets the pin to low.

abstract async get(*, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs) bool[source]

Get the high/low state of the pin.

Returns

Indicates if the state of the pin is high.

Return type

bool

abstract async get_pwm(*, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs) float[source]

Get the pin’s given duty cycle.

Returns

The duty cycle.

Return type

float

abstract async set_pwm(duty_cycle: float, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs)[source]

Set the pin to the given duty_cycle.

Parameters

duty_cycle (float) – The duty cycle.

abstract async get_pwm_frequency(*, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs) int[source]

Get the PWM frequency of the pin.

Returns

The PWM frequency.

Return type

int

abstract async set_pwm_frequency(frequency: int, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs)[source]

Set the pin to the given PWM frequency (in Hz). When frequency is 0, it will use the board’s default PWM frequency.

Parameters

frequency (int) – The frequency, in Hz.

SUBTYPE :Final
abstract async analog_reader_by_name(name: str) AnalogReader[source]

Get an AnalogReader by name.

Parameters

name (str) – Name of the analog reader to be retrieved.

Returns

The analog reader.

Return type

AnalogReader

abstract async digital_interrupt_by_name(name: str) DigitalInterrupt[source]

Get a DigitalInterrupt by name.

Parameters

name (str) – Name of the digital interrupt.

Returns

the digital interrupt.

Return type

DigitalInterrupt

abstract async gpio_pin_by_name(name: str) GPIOPin[source]

Get a GPIO Pin by name.

Parameters

name (str) – Name of the GPIO pin.

Returns

the pin.

Return type

GPIOPin

abstract async analog_reader_names() List[str][source]

Get the names of all known analog readers.

Returns

The names of the analog readers..

Return type

List[str]

abstract async digital_interrupt_names() List[str][source]

Get the names of all known digital interrupts.

Returns

The names of the digital interrupts.

Return type

List[str]

abstract async status(*, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs) viam.proto.common.BoardStatus[source]

Return the current status of the board.

Returns

the status.

Return type

BoardStatus

abstract async model_attributes() Attributes[source]

Get the attributes related to the model of this board.

Returns

The attributes.

Return type

Attributes