Configure a Raspberry Pi 5 Board

Configure a pi5 board to integrate a Raspberry Pi 5 into your machine.

To configure a Raspberry Pi 4 or earlier, see Configure a Raspberry Pi 4, 3, or Zero 2 W board.

Enable hardware PWM

(Optional) If you want to use hardware PWM on pins 12 and 35, edit /boot/config.txt on your Pi, adding the following line:

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.

Configuration

Navigate to the Config tab of your machine’s page in the Viam app. Click on the Components subtab and click Create component. Select the board type, then select the pi5 model. Enter a name for your board and click Create.

An example board configuration in the app builder UI. The name (local), type (board) and model (pi5) are shown. No other attributes are configured.

Copy and paste the following attribute template into your board’s Attributes box. Then remove and fill in the attributes as applicable to your board, according to the table below.

{
  "analogs": [
    {
      "name": "<your-analog-reader-name>",
      "pin": "<pin-number-on-adc>",
      "spi_bus": "<your-spi-bus-index>",
      "chip_select": "<chip-select-pin-number-on-board>",
      "average_over_ms": <int>,
      "samples_per_sec": <int>
    }
  ],
  "digital_interrupts": [
    {
      "name": "<your-digital-interrupt-name>",
      "pin": "<pin-number>"
    }
  ]
}
{
  "digital_interrupts": [
    {
      "name": "your-interrupt-1",
      "pin": "15"
    },
    {
      "name": "your-interrupt-2",
      "pin": "16"
    }
  ]
}
{
  "components": [
    {
      "name": "<your-pi-board-name>",
      "model": "pi5",
      "type": "board",
      "namespace": "rdk",
      "attributes": {
        "analogs": [
          <...See table below...>
        ],
        "digital_interrupts": [
          <...See table below...>
        ]
      },
      "depends_on": []
    }
  ]
}

The following attributes are available for pi5 boards:

NameTypeInclusionDescription
analogsobjectOptionalAttributes of any pins that can be used as analog-to-digital converter (ADC) inputs. See configuration info.
digital_interruptsobjectOptionalAny digital interrupts’s pin number and name. See configuration info.

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.


Have questions, or want to meet other people working on robots? Join our Community Discord.

If you notice any issues with the documentation, feel free to file an issue or edit this file.