Board Component

A board component on your machine communicates with the other components of the machine.

A board can be:

  • A single-board computer (SBC) with GPIO pins and a CPU capable of running viam-server.
  • A GPIO peripheral device that must connect to an external computer.
  • A PWM peripheral device that must connect to an SBC that has a CPU and GPIO pins.

The board of a machine is also its signal wire hub that provides access to general purpose input/output (GPIO) pins: a collection of pins on the motherboard of a computer that can receive electrical signals.

Signaling is overseen by a computer running viam-server which allows you to control the flow of electricity to these pins to change their state between “high” (active) and “low” (inactive), and wire them to send digital signals to and from other hardware.

Figure: Two different board options: a single-board computer with GPIO pins running `viam-server` locally, or a GPIO peripheral plugged into a desktop computer's USB port, with the computer running `viam-server`.
Image showing two board options: First, running viam-server locally and second, running via a peripheral plugged into the USB port of a computer that is running the viam-server.

Supported models

To use your board with Viam, check whether one of the following built-in models or modular resources supports your board.

Built-in models

For configuration information, click on the model name:

ModelDescription
piRaspberry Pi 4, Raspberry Pi 3 or Raspberry Pi Zero 2 W
jetsonNVIDIA Jetson AGX Orin, NVIDIA Jetson Orin Nano, NVIDIA Jetson Xavier NX, NVIDIA Jetson Nano
upboardAn Intel-based board like the UP4000
tiTexas Instruments TDA4VM
beagleboneBeagleBoard’s BeagleBone AI-64
numatoNumato GPIO Modules, peripherals for adding GPIO pins
pca9685PCA9685 Arduino I2C Interface, a 16-channel I2C PWM/servo driver peripheral
customlinuxA model for other Linux boards.
fakeA model used for testing, with no physical hardware

Modular resources

Search for additional board models that you can add from the Viam Registry:

For configuration information, click on the model name:

Model
Description

Micro-RDK

If you are using the micro-RDK, navigate to Micro-RDK Board for supported model information.

Attribute configuration

Configuring these attributes on your board allows you to integrate analog-to-digital converters and digital interrupts into your machine.

analogs

An analog-to-digital converter (ADC) takes a continuous voltage input (analog signal) and converts it to an discrete integer output (digital signal).

ADCs are useful when building a robot, as they enable your board to read the analog signal output by most types of sensors and other hardware components.

To integrate an ADC into your machine, you must first physically connect the pins on your ADC to your board.

Then, integrate analogs into the attributes of your board by adding the following to your board’s JSON configuration:

// "attributes": { ... ,
"analogs": [
  {
    "name": "<your-analog-reader-name>",
    "pin": "<pin-number-on-adc>",
    "spi_bus": "<your-spi-bus-index>",
    "chip_select": "<chip-select-index>",
    "average_over_ms": <int>,
    "samples_per_sec": <int>
  }
]
{
  "components": [
    {
      "model": "pi",
      "name": "your-board",
      "type": "board",
      "attributes": {
        "analogs": [
          {
            "name": "current",
            "pin": "1",
            "spi_bus": "1",
            "chip_select": "0"
          },
          {
            "name": "pressure",
            "pin": "0",
            "spi_bus": "1",
            "chip_select": "0"
          }
        ]
      }
    }
  ]
}

The following properties are available for analogs:

NameTypeInclusionDescription
namestringRequiredYour name for the analog reader.
pinstringRequiredThe pin number of the ADC’s connection pin, wired to the board. This should be labeled as the physical index of the pin on the ADC.
chip_selectstringRequiredThe chip select index of the board’s connection pin, wired to the ADC.
spi_busstringRequiredThe index of the SPI bus connecting the ADC and board.
average_over_msintOptionalDuration in milliseconds over which the rolling average of the analog input should be taken.
samples_per_secintOptionalSampling rate of the analog input in samples per second.

digital_interrupts

Interrupts are a method of signaling precise state changes. Configuring digital interrupts to monitor GPIO pins on your board is useful when your application needs to know precisely when there is a change in GPIO value between high and low.

  • When an interrupt configured on your board processes a change in the state of the GPIO pin it is configured to monitor, it calls Tick() to record the state change and notify any interested callbacks to “interrupt” the program.
  • Calling GetGPIO() on a GPIO pin, which you can do without configuring interrupts, is useful when you want to know a pin’s value at specific points in your program, but is less precise and convenient than using an interrupt.

Integrate digital_interrupts into your machine in the attributes of your board by adding the following to your board’s JSON configuration:

// "attributes": { ... ,
"digital_interrupts": [
  {
    "name": "<your-digital-interrupt-name>",
    "pin": "<pin-number>",
  }
]
{
  "components": [
    {
      "model": "pi",
      "name": "your-board",
      "type": "board",
      "attributes": {
        "digital_interrupts": [
          {
            "name": "your-interrupt-1",
            "pin": "15"
          },
          {
            "name": "your-interrupt-2",
            "pin": "16"
          }
        ]
      }
    }
  ]
}

The following properties are available for digital_interrupts:

NameTypeInclusionDescription
namestringRequiredYour name for the digital interrupt.
pinstringRequiredThe pin number of the board’s GPIO pin that you wish to configure the digital interrupt for.
typestringOptionalOnly applies to pi model boards.
  • basic: Recommended. Tracks interrupt count.
  • servo: For interrupts configured for a pin controlling a servo. Tracks pulse width value.

Control your board with Viam’s client SDK libraries

To get started using Viam’s SDKs to connect to and control your machine, go to your machine’s page on the Viam app, navigate to the Code sample tab, select your preferred programming language, and copy the sample code generated.

When executed, this sample code will create a connection to your machine as a client. Then control your machine programmatically by getting your board component from the machine with FromRobot and adding API method calls, as shown in the following examples.

These examples assume you have a board called “my_board” configured as a component of your machine. If your board has a different name, change the name in the code.

Be sure to import the board package for the SDK you are using:

from viam.components.board import Board
import (
  "go.viam.com/rdk/components/board"
)

API

The board component supports the following methods:

Method NameDescription
ReadAnalogReaderGet an AnalogReader by name.
GetDigitalInterruptValueGet a DigitalInterrupt by name.
GetGPIOGet a GPIOPin by its pin number.
SetGPIOSet a GPIOPin by its pin number.
AnalogReaderNamesGet the name of every AnalogReader.
DigitalInterruptNamesGet the name of every DigitalInterrupt.
StatusGet the current status of this board.
SetPWMSet the board to the indicated power mode.
WriteAnalogWrite an analog value to a pin on the board.
GetGeometriesGet all the geometries associated with the board in its current configuration, in the frame of the board.
DoCommandSend or receive model-specific commands.
CloseSafely shut down the resource and prevent further use.

Additionally, the nested GPIOPin, AnalogReader, and DigitalInterrupt interfaces support the following methods:

GPIOPin API:

Method NameDescription
SetGPIOSet the output of this pin to high/low.
GetGPIOGet if this pin is active (high).
GetPWMGet the pin’s pulse-width modulation duty cycle.
SetPWMSet the pin’s pulse-width modulation duty cycle.
PWMFreqGet the pulse-width modulation frequency of this pin.
SetPWMFreqSet the pulse-width modulation frequency of this pin.
CloseSafely shut down the resource and prevent further use.

AnalogReader API:

Method NameDescription
ReadRead the current integer value of the digital signal output by the ADC.
CloseSafely shut down the resource and prevent further use.

DigitalInterrupt API:

Method NameDescription
ValueGet the current value of this interrupt.
TickRecord an interrupt.
AddCallbackAdd a channel as a callback for Tick().
AddPostProcessorAdd a PostProcessor function for Value().
CloseSafely shut down the resource and prevent further use.

ReadAnalogReader

Get an AnalogReader by name.

Parameters:

  • name (str): Name of the analog reader you want to retrieve.

Returns:

  • (AnalogReader): An interface representing an analog reader configured and residing on the board.

For more information, see the Python SDK Docs.

my_board = Board.from_robot(robot=robot, name="my_board")

# Get the AnalogReader "my_example_analog_reader".
reader = await my_board.analog_reader_by_name(name="my_example_analog_reader")

Parameters:

Returns:

  • (AnalogReader): An interface representing an analog reader configured and residing on the board.
  • (bool): True if there was an analog reader of this name found on your board.

For more information, see the Go SDK Docs.

myBoard, err := board.FromRobot(robot, "my_board")

// Get the AnalogReader "my_example_analog_reader".
reader, err := myBoard.AnalogReaderByName("my_example_analog_reader")

GetDigitalInterruptValue

Get an DigitalInterrupt by name.

Parameters:

  • name (str): Name of the digital interrupt you want to retrieve. Set as the "name" property in configuration.

Returns:

For more information, see the Python SDK Docs.

my_board = Board.from_robot(robot=robot, name="my_board")

# Get the DigitalInterrupt "my_example_digital_interrupt".
interrupt = await my_board.digital_interrupt_by_name(
    name="my_example_digital_interrupt")

Parameters:

Returns:

  • (DigitalInterrupt): An interface representing a configured interrupt on the board.
  • (bool): True if there was a digital interrupt of this name found on your board.

For more information, see the Go SDK Docs.

myBoard, err := board.FromRobot(robot, "my_board")

// Get the DigitalInterrupt "my_example_digital_interrupt".
interrupt, ok := myBoard.DigitalInterruptByName("my_example_digital_interrupt")

GPIOPinByName

Get a GPIOPin by pin number.

Parameters:

  • name (str): Pin number of the GPIO pin you want to retrieve as a GPIOPin interface. Refer to the pinout diagram and data sheet of your board model for pin numbers.

Returns:

  • (GPIOPin): An interface representing an individual GPIO pin on the board.

For more information, see the Python SDK Docs.

my_board = Board.from_robot(robot=robot, name="my_board")

# Get the GPIOPin with pin number 15.
pin = await my_board.gpio_pin_by_name(name="15")

Parameters:

  • name (string): pin number of the GPIO pin you want to retrieve as a GPIOPin interface. Refer to the pinout diagram and data sheet of your board model for pin numbers.

Returns:

  • (GPIOPin): An interface representing an individual GPIO pin on the board.
  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

myBoard, err := board.FromRobot(robot, "my_board")

// Get the GPIOPin with pin number 15.
pin, err := myBoard.GPIOPinByName("15")

AnalogReaderNames

Get the name of every AnalogReader configured and residing on the board.

Parameters:

  • None

Returns:

For more information, see the Python SDK Docs.

my_board = Board.from_robot(robot=robot, name="my_board")

# Get the name of every AnalogReader configured on the board.
names = await my_board.analog_reader_names()

Parameters:

  • None

Returns:

For more information, see the Go SDK Docs.

myBoard, err := board.FromRobot(robot, "my_board")

// Get the name of every AnalogReader configured on the board.
names := myBoard.AnalogReaderNames()

DigitalInterruptNames

Get the name of every DigitalInterrupt configured on the board.

Parameters:

  • None

Returns:

For more information, see the Python SDK Docs.

my_board = Board.from_robot(robot=robot, name="my_board")

# Get the name of every DigitalInterrupt configured on the board.
names = await my_board.digital_interrupt_names()

Parameters:

  • None

Returns:

For more information, see the Go SDK Docs.

myBoard, err := board.FromRobot(robot, "my_board")

// Get the name of every DigitalInterrupt configured on the board.
names := myBoard.DigitalInterruptNames()

Status

Get the current status of the board as a BoardStatus.

Parameters:

  • extra (Optional[Dict[str, Any]]): Extra options to pass to the underlying RPC call.
  • timeout (Optional[float]): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

For more information, see the Python SDK Docs.

my_board = Board.from_robot(robot=robot, name="my_board")

# Get the current status of the board.
status = await my_board.status()

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
  • extra (map[string]interface{}): Extra options to pass to the underlying RPC call.

Returns:

For more information, see the Go SDK Docs.

myBoard, err := board.FromRobot(robot, "my_board")

// Get the current status of the board.
err := myBoard.Status(context.Background(), nil)

SetPWM

Set the board to the indicated PowerMode.

Parameters:

  • mode (PowerMode): Options to specify power usage of the board: PowerMode.POWER_MODE_UNSPECIFIED, PowerMode.POWER_MODE_NORMAL, and PowerMode.POWER_MODE_OFFLINE_DEEP.
  • duration (Optional[datetime.timedelta]): If provided, the board will exit the given power mode after the specified duration.
  • timeout (Optional[float]): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

  • None

For more information, see the Python SDK Docs.

my_board = Board.from_robot(robot=robot, name="my_board")

# Set the power mode of the board to OFFLINE_DEEP.
status = await my_board.set_power_mode(mode=PowerMode.POWER_MODE_OFFLINE_DEEP)

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
  • mode (PowerMode): Options to specify power usage of the board: boardpb.PowerMode_POWER_MODE_UNSPECIFIED, boardpb.PowerMode_POWER_MODE_NORMAL, and boardpb.PowerMode_POWER_MODE_OFFLINE_DEEP.
  • duration (*time.Duration): If provided, the board will exit the given power mode after the specified duration.

Returns:

  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

myBoard, err := board.FromRobot(robot, "my_board")

// Set the power mode of the board to OFFLINE_DEEP.
err := myBoard.Status(context.Background(), nil)
myBoard.SetPowerMode(context.Background(), boardpb.PowerMode_POWER_MODE_OFFLINE_DEEP, nil)

WriteAnalog

Write an analog value to a pin on the board.

Parameters:

  • pin (string): Name of the pin (pin number).
  • value (int): Value to write to the pin.
  • extra (Optional[Dict[str, Any]]): Extra options to pass to the underlying RPC call.
  • timeout (Optional[float]): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

  • None
my_board = Board.from_robot(robot=robot, name="my_board")

# Set pin 11 to value 48.
await my_board.write_analog(pin="11", value=48)

For more information, see the Python SDK Docs.

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
  • pin (string): Name of the pin (pin number).
  • value (int): Value to write to the pin.
  • extra (map[string]interface{}): Extra options to pass to the underlying RPC call.

Returns:

  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

myBoard, err := board.FromRobot(robot, "my_board")

// Set pin 11 to value 48.
err := myBoard.WriteAnalog(context.Background(), "11", 48, nil)

GetGeometries

Get all the geometries associated with the board in its current configuration, in the frame of the board. The motion and navigation services use the relative position of inherent geometries to configured geometries representing obstacles for collision detection and obstacle avoidance while motion planning.

Parameters:

  • extra (Optional[Dict[str, Any]]): Extra options to pass to the underlying RPC call.
  • timeout (Optional[float]): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

For more information, see the Python SDK Docs.

my_board = Board.from_robot(robot=robot, name="my_board")

geometries = await my_board.get_geometries()

if geometries:
    # Get the center of the first geometry
    print(f"Pose of the first geometry's centerpoint: {geometries[0].center}")

DoCommand

Execute model-specific commands that are not otherwise defined by the component API. For built-in models, model-specific commands are covered with each model’s documentation. If you are implementing your own board and add features that have no built-in API method, you can access them with DoCommand.

Parameters:

  • command (Dict[str, Any]): The command to execute.\
  • timeout (Optional[float]): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

my_board = Board.from_robot(robot=robot, name="my_board")

my_command = {
  "command": "dosomething",
  "someparameter": 52
}

await my_board.do_command(my_command)

For more information, see the Python SDK Docs.

Parameters:

Returns:

myBoard, err := board.FromRobot(robot, "my_board")

resp, err := myBoard.DoCommand(ctx, map[string]interface{}{"command": "dosomething", "someparameter": 52})

For more information, see the Go SDK Code.

Close

Safely shut down the resource and prevent further use.

Parameters:

  • None

Returns:

  • None
my_board = Board.from_robot(robot, "my_board")

await my_board.close()

For more information, see the Python SDK Docs.

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.

Returns:

  • (error) : An error, if one occurred.
myBoard, err := board.FromRobot(robot, "my_board")

err := myBoard.Close(ctx)

For more information, see the Go SDK Docs.

GPIOPin API

SetGPIO

Set the digital signal output of this pin to low (0V) or high (active, >0V).

Parameters:

  • high (bool): If true, set the state of the pin to high. If false, set the state of the pin to low.
  • extra (Optional[Dict[str, Any]]): Extra options to pass to the underlying RPC call.
  • timeout (Optional[float]): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

  • None

For more information, see the Python SDK Docs.

my_board = Board.from_robot(robot=robot, name="my_board")

# Get the GPIOPin with pin number 15.
pin = await my_board.gpio_pin_by_name(name="15")

# Set the pin to high.
await pin.set(high="true")

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
  • high (bool): If true, set the state of the pin to high. If false, set the state of the pin to low.
  • extra (map[string]interface{}): Extra options to pass to the underlying RPC call.

Returns:

  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

myBoard, err := board.FromRobot(robot, "my_board")

// Get the GPIOPin with pin number 15.
pin, err := myBoard.GPIOPinByName("15")

// Set the pin to high.
err := pin.Set(context.Background(), "true", nil)

GetGPIO

Get if the digital signal output of this pin is high (active, >0V).

Parameters:

  • extra (Optional[Dict[str, Any]]): Extra options to pass to the underlying RPC call.
  • timeout (Optional[float]): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

  • (bool): If true, the state of the pin is high. If false, the state of the pin is low.

For more information, see the Python SDK Docs.

my_board = Board.from_robot(robot=robot, name="my_board")

# Get the GPIOPin with pin number 15.
pin = await my_board.gpio_pin_by_name(name="15")

# Get if it is true or false that the state of the pin is high.
high = await pin.get()

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
  • extra (map[string]interface{}): Extra options to pass to the underlying RPC call.

Returns:

  • (bool): If true, the state of the pin is high. If false, the state of the pin is low.
  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

myBoard, err := board.FromRobot(robot, "my_board")

// Get the GPIOPin with pin number 15.
pin, err := myBoard.GPIOPinByName("15")

// Get if it is true or false that the state of the pin is high.
high := pin.Get(context.Background(), nil)

GetPWM

Get the pin’s pulse-width modulation (PWM) duty cycle: a float [0.0, 1.0] representing the percentage of time the digital signal output by this pin is in the high state (active, >0V) relative to the interval period of the PWM signal (interval period being the mathematical inverse of the PWM frequency).

Parameters:

  • extra (Optional[Dict[str, Any]]): Extra options to pass to the underlying RPC call.
  • timeout (Optional[float]): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

  • (float): A float [0.0, 1.0] representing the percentage of time the digital signal output by this pin is in the high state relative to the interval period of the PWM signal.

For more information, see the Python SDK Docs.

my_board = Board.from_robot(robot=robot, name="my_board")

# Get the GPIOPin with pin number 15.
pin = await my_board.gpio_pin_by_name(name="15")

# Get if it is true or false that the state of the pin is high.
duty_cycle = await pin.get_pwm()

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
  • extra (map[string]interface{}): Extra options to pass to the underlying RPC call.

Returns:

  • (float64): A float [0.0, 1.0] representing the percentage of time the digital signal output by this pin is in the high state relative to the interval period of the PWM signal.
  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

myBoard, err := board.FromRobot(robot, "my_board")

// Get the GPIOPin with pin number 15.
pin, err := myBoard.GPIOPinByName("15")

// Get if it is true or false that the state of the pin is high.
duty_cycle := pin.PWM(context.Background(), nil)

SetPWM

Set the pin’s Pulse-width modulation (PWM) duty cycle: a float [0.0, 1.0] indicating the percentage of time the digital signal output of this pin is in the high state (active, >0V) relative to the interval period of the PWM signal (interval period being the mathematical inverse of the PWM frequency).

Parameters:

  • cycle (float64): A float [0.0, 1.0] representing the percentage of time the digital signal output by this pin is in the high state relative to the interval period of the PWM signal.
  • extra (Optional[Dict[str, Any]]): Extra options to pass to the underlying RPC call.
  • timeout (Optional[float]): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

  • (bool): If true, the state of the pin is high. If false, the state of the pin is low.

For more information, see the Python SDK Docs.

my_board = Board.from_robot(robot=robot, name="my_board")

# Get the GPIOPin with pin number 15.
pin = await my_board.gpio_pin_by_name(name="15")

# Set the duty cycle to .6, meaning that this pin will be in the high state for
# 60% of the duration of the PWM interval period.
await pin.set_pwm(cycle=.6)

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
  • cycle (float64): A float [0.0, 1.0] representing the percentage of time the digital signal output by this pin is in the high state relative to the interval period of the PWM signal.
  • extra (map[string]interface{}): Extra options to pass to the underlying RPC call.

Returns:

  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

myBoard, err := board.FromRobot(robot, "my_board")

// Get the GPIOPin with pin number 15.
pin, err := myBoard.GPIOPinByName("15")

// Set the duty cycle to .6, meaning that this pin will be in the high state for 60% of the duration of the PWM interval period.
err := pin.SetPWM(context.Background(), .6, nil)

PWMFreq

Get the Pulse-width modulation (PWM) frequency in Hertz (Hz) of this pin, the count of PWM interval periods per second. The optimal value for PWM Frequency depends on the type and model of component you control with the signal output by this pin. Refer to your device’s data sheet for PWM Frequency specifications.

Parameters:

  • extra (Optional[Dict[str, Any]]): Extra options to pass to the underlying RPC call.
  • timeout (Optional[float]): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

  • (int): The PWM Frequency in Hertz (Hz) (the count of PWM interval periods per second) the digital signal output by this pin is set to.

For more information, see the Python SDK Docs.

my_board = Board.from_robot(robot=robot, name="my_board")

# Get the GPIOPin with pin number 15.
pin = await my_board.gpio_pin_by_name(name="15")

# Get the PWM frequency of this pin.
freq = await pin.get_pwm_frequency()

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
  • extra (map[string]interface{}): Extra options to pass to the underlying RPC call.

Returns:

  • (unit): The PWM Frequency in Hertz (Hz) (the count of PWM interval periods per second) the digital signal output by this pin is set to.
  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

myBoard, err := board.FromRobot(robot, "my_board")

// Get the GPIOPin with pin number 15.
pin, err := myBoard.GPIOPinByName("15")

// Get the PWM frequency of this pin.
freqHz, err := pin.PWMFreq(context.Background(), nil)

SetPWMFreq

Set the Pulse-width modulation (PWM) frequency in Hertz (Hz) of this pin, the count of PWM interval periods per second. The optimal value for PWM Frequency depends on the type and model of component you control with the PWM signal output by this pin. Refer to your device’s data sheet for PWM Frequency specifications.

Parameters:

  • extra (Optional[Dict[str, Any]]): Extra options to pass to the underlying RPC call.
  • timeout (Optional[float]): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

  • (int): The PWM Frequency in Hertz (Hz), the count of PWM interval periods per second, to set the digital signal output by this pin to.

For more information, see the Python SDK Docs.

my_board = Board.from_robot(robot=robot, name="my_board")

# Get the GPIOPin with pin number 15.
pin = await my_board.gpio_pin_by_name(name="15")

# Set the PWM frequency of this pin to 1600 Hz.
high = await pin.set_pwm_frequency(frequency=1600)

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
  • freqHz (unit): The PWM Frequency in Hertz (Hz), the count of PWM interval periods per second, to set the digital signal output by this pin to.
  • extra (map[string]interface{}): Extra options to pass to the underlying RPC call.

Returns:

  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

myBoard, err := board.FromRobot(robot, "my_board")

// Get the GPIOPin with pin number 15.
pin, err := myBoard.GPIOPinByName("15")

// Set the PWM frequency of this pin to 1600 Hz.
high := pin.SetPWMFreq(context.Background(), 1600, nil)

Close

Safely shut down the resource and prevent further use.

Parameters:

  • None

Returns:

  • None
my_board = Board.from_robot(robot=robot, name="my_board")

# Get the GPIOPin with pin number 15.
pin = await my_board.gpio_pin_by_name(name="15")

# Close the pin.
await pin.close()

For more information, see the Python SDK Docs.

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.

Returns:

  • (error) : An error, if one occurred.
myBoard, err := board.FromRobot(robot, "my_board")

// Get the GPIOPin with pin number 15.
pin, err := myBoard.GPIOPinByName("15")

// Close the pin.
err := pin.Close(ctx)

For more information, see the Go SDK Docs.

AnalogReader API

Read

Read the current integer value of the digital signal output by the ADC.

Parameters:

  • extra (Optional[Dict[str, Any]]): Extra options to pass to the underlying RPC call.
  • timeout (Optional[float]): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

  • (int): The value of the digital signal output by the analog reader.

For more information, see the Python SDK Docs.

my_board = Board.from_robot(robot=robot, name="my_board")

# Get the GPIOPin with pin number 15.
pin = await my_board.gpio_pin_by_name(name="15")

# Get if it is true or false that the pin is set to high.
duty_cycle = await pin.get_pwm()

# Get the AnalogReader "my_example_analog_reader".
reader = await my_board.analog_reader_by_name(
    name="my_example_analog_reader")

# Get the value of the digital signal "my_example_analog_reader" has most
# recently measured.
reading = reader.read()

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
  • extra (map[string]interface{}): Extra options to pass to the underlying RPC call.

Returns:

  • (int): The value of the digital signal output by the analog reader.
  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

myBoard, err := board.FromRobot(robot, "my_board")

// Get the AnalogReader "my_example_analog_reader".
reader, err := myBoard.AnalogReaderByName("my_example_analog_reader")

// Get the value of the digital signal "my_example_analog_reader" has most recently measured.
reading := reader.Read(context.Background(), nil)

Close

Safely shut down the resource and prevent further use.

Parameters:

  • None

Returns:

  • None
my_board = Board.from_robot(robot=robot, name="my_board")

# Get the AnalogReader "my_example_analog_reader".
reader = await my_board.analog_reader_by_name(
    name="my_example_analog_reader")

# Close the reader.
await reader.close()

For more information, see the Python SDK Docs.

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.

Returns:

  • (error) : An error, if one occurred.
myBoard, err := board.FromRobot(robot, "my_board")

// Get the AnalogReader "my_example_analog_reader".
reader, err := myBoard.AnalogReaderByName("my_example_analog_reader")

// Close the reader.
err := reader.Close(ctx)

For more information, see the Go SDK Docs.

DigitalInterrupt API

Value

Get the current value of this interrupt. If a post processor function has been added with AddPostProcessor(), it will be applied to this value before it is returned.

Calculation of value differs between the "type" of interrupt configured:

Parameters:

  • extra (Optional[Dict[str, Any]]): Extra options to pass to the underlying RPC call.
  • timeout (Optional[float]): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

For more information, see the Python SDK Docs.

my_board = Board.from_robot(robot=robot, name="my_board")

# Get the DigitalInterrupt "my_example_digital_interrupt".
interrupt = await my_board.digital_interrupt_by_name(
    name="my_example_digital_interrupt")

# Get the amount of times this DigitalInterrupt has been interrupted with a
# tick.
count = await interrupt.value()

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
  • extra (map[string]interface{}): Extra options to pass to the underlying RPC call.

Returns:

For more information, see the Go SDK Docs.

myBoard, err := board.FromRobot(robot, "my_board")

// Get the DigitalInterrupt "my_example_digital_interrupt".
interrupt, ok := myBoard.DigitalInterruptByName("my_example_digital_interrupt")

// Get the amount of times this DigitalInterrupt has been interrupted with a tick.
count, err := interrupt.Value(context.Background(), nil)

Parameters:

  • extra (Optional[Dict[str, Any]]): Extra options to pass to the underlying RPC call.
  • timeout (Optional[float]): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

  • (int): The RollingAverage of the time in nanoseconds between two successive low signals (pulse width) recorded by Tick(), computed over a window of size 10.

For more information, see the Python SDK Docs.

my_board = Board.from_robot(robot=robot, name="my_board")

# Get the DigitalInterrupt "my_example_digital_interrupt".
interrupt = await my_board.digital_interrupt_by_name(
    name="my_example_digital_interrupt")

# Get the rolling average of the pulse width across each time the
# DigitalInterrupt is interrupted with a tick.
rolling_avg = await interrupt.value()

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
  • extra (map[string]interface{}): Extra options to pass to the underlying RPC call.

Returns:

  • (int64): The RollingAverage of the time in nanoseconds between two successive low signals (pulse width) recorded by Tick(), computed over a window of size 10.
  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

myBoard, err := board.FromRobot(robot, "my_board")

// Get the DigitalInterrupt "my_example_digital_interrupt".
interrupt, ok := myBoard.DigitalInterruptByName("my_example_digital_interrupt")

// Get the rolling average of the pulse width across each time the DigitalInterrupt is interrupted with a tick.
rolling_avg, err := interrupt.Value(context.Background(), nil)

Tick

Record an interrupt and notify any channels that have been added with AddCallback().

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
  • high (bool): If true, the state of the pin is set to high. If false, the state of the pin is set to low.
  • now (uint64): The time that has elapsed in nanoseconds since the last time the interrupt was ticked.

Returns:

  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

myBoard, err := board.FromRobot(robot, "my_board")

// Get the DigitalInterrupt "my_example_digital_interrupt".
interrupt, ok := myBoard.DigitalInterruptByName("my_example_digital_interrupt")

// Record an interrupt and notify any interested callbacks.
err := interrupt.Tick(context.Background(), true, 12345)

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
  • high (bool): If true, the state of the pin is set to high. If false, the state of the pin is set to low.
  • nanoseconds (uint64): The time in nanoseconds between two successive low signals (pulse width).

Returns:

  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

myBoard, err := board.FromRobot(robot, "my_board")

// Get the DigitalInterrupt "my_example_digital_interrupt".
interrupt, ok := myBoard.DigitalInterruptByName("my_example_digital_interrupt")

// Record an interrupt and notify any interested callbacks.
err := interrupt.Tick(context.Background(), true, 12345)

AddCallback

Add a channel as a listener for when the state of the configured GPIO pin changes. When Tick() is called, callbacks added to an interrupt will be sent the returned value high.

Parameters:

  • callback (chan Tick): The channel to add as a listener for when the state of the GPIO pin this interrupt is configured for changes between high and low.

Returns:

  • None

For more information, see the Go SDK Docs.

myBoard, err := board.FromRobot(robot, "my_board")

// Get the DigitalInterrupt "my_example_digital_interrupt".
interrupt, ok := myBoard.DigitalInterruptByName("my_example_digital_interrupt")

// Make the channel for Tick().
ch := make(chan Tick)

// Add the channel to "my_example_digital_interrupt" as a callback.
interrupt.AddCallback(ch)

AddPostProcessor

Add a PostProcessor function that takes an integer input and transforms it into a new integer value. Functions added to an interrupt will be used to modify values before they are returned by Value().

Parameters:

Returns:

  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

myBoard, err := board.FromRobot(robot, "my_board")

// Get the GPIOPin with pin number 15.
pin, err := myBoard.GPIOPinByName("15")

// Get the DigitalInterrupt "my_example_digital_interrupt".
interrupt, ok := myBoard.DigitalInterruptByName("my_example_digital_interrupt")

// Create a simple post processing function calculating absolute value of integers.
MySimplePP := int64(math.Abs)

// Add "MySimplePP" as a post processor to "my_example_digital_interrupt".
interrupt.AddPostProcessor(MySimplePP)

Close

Safely shut down the resource and prevent further use.

Parameters:

  • None

Returns:

  • None
my_board = Board.from_robot(robot=robot, name="my_board")

# Get the DigitalInterrupt "my_example_digital_interrupt".
interrupt = await my_board.digital_interrupt_by_name(
    name="my_example_digital_interrupt")

# Close the interrupt.
await interrupt.close()

For more information, see the Python SDK Docs.

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.

Returns:

  • (error) : An error, if one occurred.
myBoard, err := board.FromRobot(robot, "my_board")

// Get the DigitalInterrupt "my_example_digital_interrupt".
interrupt, ok := myBoard.DigitalInterruptByName("my_example_digital_interrupt")

// Close the interrupt.
err := interrupt.Close(ctx)

For more information, see the Go SDK Docs.

Troubleshooting

You can find additional assistance in the Troubleshooting section.

You can also ask questions in the Community Discord and we will be happy to help.

Next steps