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.
Running viam-server
The board component allows you to use the pins on your board. If there is no board model for your board:
- you can still run
viam-server
if your board supports it - you can still access USB ports
Configuration
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:
Add support for other models
If none of the existing models fit your use case, you can create a modular resource to add support for it.
Model | Description |
---|---|
esp32 | An ESP32 microcontroller |
Add support for other models
If none of the existing models fit your use case, you can create a modular resource to add support for it.
viam-micro-server
works differently from the RDK, so creating modular resources for it is different.
Refer to the Micro-RDK Module Template on GitHub for information on how to create custom resources for your viam-micro-server
machine.
You will need to recompile and flash your ESP32 yourself instead of using Viam’s prebuilt binary and installer.
API
The board API supports the following methods:
Method Name | Description | viam-micro-server Support |
---|---|---|
SetGPIO | Set the digital signal output of this pin to low (0V) or high (active, >0V). | |
GetGPIO | Get if the digital signal output of this pin is high (active, >0V). | |
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). | |
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). | |
PWMFrequency | Get the PWM frequency of the GPIO pin. | |
SetPWMFrequency | Set the pin to the given PWM frequency (in Hz). When frequency is 0, it will use the board’s default PWM frequency. | |
GetDigitalInterruptValue | Get the current value of a configured digital interrupt. | |
ReadAnalogReader | Read the current integer value of the digital signal output by the ADC. | |
WriteAnalog | Write an analog value to a pin on the board. | |
StreamTicks | Start a stream of DigitalInterrupt ticks. | |
SetPowerMode | Set the board to the indicated PowerMode . | |
AnalogByName | Get a configured Analog by name . | |
DigitalInterruptByName | Get a DigitalInterrupt by name . | |
GPIOPinByName | Get a GPIOPin by pin number. | |
GetGeometries | Get all the geometries associated with the board in its current configuration, in the frame of the board. | |
Reconfigure | Reconfigure this resource. | |
DoCommand | Execute model-specific commands that are not otherwise defined by the component API. | |
Name | Get the name of the digital interrupt. | |
GetResourceName | Get the ResourceName for this board with the given name. | |
Close | Safely shut down the resource and prevent further use. |
Troubleshooting
If your board is not working as expected, follow these steps:
- Check your machine logs on the LOGS tab to check for errors.
- Review your board model’s documentation to ensure you have configured all required attributes.
- Check that all wires are securely connected.
- Click on the TEST panel on the CONFIGURE or CONTROL tab and test if you can use the board there.
If none of these steps work, reach out to us on the Community Discord and we will be happy to help.
Next steps
For general configuration and development info, see:
Was this page helpful?
Glad to hear it! If you have any other feedback please let us know:
We're sorry about that. To help us improve, please tell us what we can do better:
Thank you!