This module implements the rdk:component:board API and rdk:component:servo API
Two models are provided in this module:
viam:raspberry-pi:rpi- Configure a Raspberry Pi 4, 3 and Zero 2 W, board to access GPIO functionality: input, output, PWM, power, serial interfaces, etc.viam:raspberry-pi:rpi-servo- Configure a servo controlled by the GPIO pins on the board.
Navigate to the CONFIGURE tab of your machine's page in the Viam app, searching for raspberry-pi
Fill in the attributes as applicable to your board, according to the example below. The configuration is the same as the board docs.
{
{
"components": [
{
"name": "<your-pi-board-name>",
"model": "viam:raspberry-pi:rpi",
"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>"
}
]
},
}
]
"modules": [
{
"type": "registry",
"name": "viam_raspberry-pi",
"module_id": "viam:raspberry-pi",
"version": "0.0.1"
}
],
}We use our genericlinux implementation for SPI and I2C.
Navigate to the CONFIGURE tab of your machine's page in the Viam app, searching for rpi-servo
Fill in the attributes as applicable to your servo, according to the example below. The configuration is the same as the servo docs.
{
"components": [
{
"name": "<your-servo-name>",
"model": "viam:raspberry-pi:rpi-servo",
"type": "servo",
"namespace": "rdk",
"attributes": {
"pin": "<your-pin-number>",
"board": "<your-board-name>",
"min": <float>,
"max": <float>,
"starting_position_deg": <float>,
"hold_position": <int>,
"max_rotation_deg": <int>,
"frequency_hz": <int>
}
}
],
"modules": [
{
"type": "registry",
"name": "viam_raspberry-pi",
"module_id": "viam:raspberry-pi",
"version": "0.0.1"
}
],
}Module needs to be built from within canon. As of August 2024 this module is being built only in bullseye and supports bullseye and bookworm versions of Debian.
make module will create raspberry-pi-module.tar.gz.
canon
make moduleThen copy the tar.gz over to your pi
scp /path-to/raspberry-pi-module.tar.gz your_rpi@pi.local:~Now you can use it as a local module!
Linting also needs to be done from within canon
canon
make lintNote
All tests require a functioning raspberry pi4!
Run the following in a pi
make testThis will create binaries for each test file in /bin and run them.
The directory structure is as follows:
rpi: Contains all files necessary to defineviam:raspberry-pi:rpi. Files are organized by functionality.rpi-servo: Contains all files necessary to defineviam:raspberry-pi:rpi-servo. Files are organized by functionalityutils: Any utility functions that are either universal to the boards or shared betweenrpiandrpi-servo. Included are daemon errors, pin mappings, and digital interruptstesting: External package exports. Tests the components how an outside package would use the components (w/o any internal functions).
The module relies on the pigpio daemon to carry out GPIO functionality. The daemon accepts socket and pipe connections over the local network. Although many things can be configured, from DMA allocation mode to socket port to sample rate, we use the default settings, which match with the traditional pigpio library's defaults. More info can be seen here: https://abyz.me.uk/rpi/pigpio/pigpiod.html.
The daemon essentially supports all the same functionality as the traditional library. Instead of using pigpio.h C library, it uses the daemon library, which is mostly identical: pigpiod_if2.h. Details can be found here: https://abyz.me.uk/rpi/pigpio/pdif2.html