Board Component

The board component provides an API for setting GPIO pins to high or low, setting PWM, and working with analog and digital interrupts.

If you have GPIO pins you wish to control, use a board component.

Your GPIO pins can be present as:

  • The GPIO pins on a single-board computer (SBC).
  • 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.

In other words, the board of a machine is its signal wire hub. Signaling controls the flow of electricity to these pins to change their state between “high” (active) and “low” (inactive), and 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.

Available models

To use GPIO pins, you need to add a board component to your machine’s configuration. Go to your machine’s CONFIGURE page, and add a model that supports your board.

The following list shows the available board models. If your board is not among them, you may be able to use the pins on your board with an experimental periph.io-based modular component. This works for boards such as the RockPi S.

For additional configuration information, click on the model name:

Model
Description
ModelDescription
esp32An ESP32 microcontroller

API

The board API supports the following methods:

Method NameDescriptionviam-micro-server Support
SetGPIOSet the digital signal output of this pin to low (0V) or high (active, >0V).

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

GetPWMGet 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).

SetPWMSet 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).

PWMFrequencyGet the PWM frequency of the GPIO pin.

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

AnalogNamesGet the name of every configured Analog on the board.

AnalogByNameGet a configured Analog by name.

WriteWrite an analog value to a pin on the board.

GetDigitalInterruptValueGet a configured DigitalInterrupt by name.

StreamTicksStart a stream of DigitalInterrupt ticks.

SetPowerModeSet the board to the indicated PowerMode.

GetGeometriesGet all the geometries associated with the board in its current configuration, in the frame of the board.

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

ValueGet the current value of this interrupt.

DigitalInterruptNamesGet the name of every configured DigitalInterrupt on the board.

GPIOPinByNameGet a GPIOPin by pin number.

ReconfigureReconfigure this resource.

DoCommandExecute model-specific commands that are not otherwise defined by the component API.

NameGet the name of the digital interrupt.

GetResourceNameGet the ResourceName for this board with the given name.

CloseSafely shut down the resource and prevent further use.

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

For general configuration and development info, see: