Previous
fake
Follow the setup guide to prepare your Pi for running viam-server
before configuring a pi5
board.
Configure a pi5
board to integrate a Raspberry Pi 5 into your machine.
To configure a Raspberry Pi 4 or earlier, see viam:raspberry-pi:rpi
.
(Optional) If you want to use hardware PWM on pins 12 (GPIO 18) and 35 (GPIO 19), edit
dtoverlay=pwm-2chan
Then reboot the Pi for the change to take effect.
If you do not enable hardware PWM, these pins will have no function.
To test your board as you configure it, power it on. If you plan to connect hardware to the board’s pins, connect the hardware while it’s powered off. Then, configure the board:
Navigate to the CONFIGURE tab of your machine’s page in the Viam app.
Click the + icon next to your machine part in the left-hand menu and select Component.
Select the board
type, then select the pi5
model.
Enter a name or use the suggested name for your board and click Create.
Edit the attributes as applicable to your board, according to the table below.
{
"components": [
{
"name": "<your-pi-board-name>",
"model": "pi5",
"type": "board",
"namespace": "rdk",
"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>
}
],
"digital_interrupts": [
{
"name": "<your-digital-interrupt-name>",
"pin": "<pin-number>"
}
],
"depends_on": []
}
]
}
The following attributes are available for pi5
boards:
Name | Type | Required? | Description |
---|---|---|---|
analogs | object | Optional | Attributes of any pins that can be used as analog-to-digital converter (ADC) inputs. See configuration info. |
digital_interrupts | object | Optional | Any digital interrupts’s pin number and name. See configuration info. |
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 following the Config Builder instructions or by adding the following to your board’s JSON configuration:
On your board’s panel, click Show more, then select Add analog. Assign a name to your analog and then fill in the required properties outlined below.
// "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
:
Name | Type | Required? | Description |
---|---|---|---|
name | string | Required | Your name for the analog reader. |
pin | string | Required | The 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_select | string | Required | The chip select index of the board’s connection pin, wired to the ADC. |
spi_bus | string | Required | The index of the SPI bus connecting the ADC and board. |
average_over_ms | int | Optional | Duration in milliseconds over which the rolling average of the analog input should be taken. |
samples_per_sec | int | Optional | Sampling rate of the analog input in samples per second. |
analogs
Once you have configured your analogs, open the board’s TEST panel on the CONFIGURE or CONTROL tabs to monitor analogs. The numbers displayed next to each analog name represent the digital signal received from the analog inputs.
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.
StreamTicks()
, or get the current value of the digital interrupt with Value()
.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 following the Config Builder instructions, or by adding the following to your board’s JSON configuration:
On your board’s panel, click Show more, then select Add digital interrupt. Assign a name to your digital interrupt and then enter a pin number.
// "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
:
Name | Type | Required? | Description |
---|---|---|---|
name | string | Required | Your name for the digital interrupt. |
pin | string | Required | The pin number of the board’s GPIO pin that you wish to configure the digital interrupt for. |
digital_interrupts
Once you have configured your digital interrupts, open the board’s TEST panel on the CONFIGURE or CONTROL tabs to monitor interrupt activity. The value displayed next to each interrupt name represents the total count of interrupts triggered by the corresponding digital interrupt.
If your board is not working as expected, follow these steps:
If none of these steps work, reach out to us on the Community Discord and we will be happy to help.
For more configuration and usage 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!