Configure a GPIO/ADC-Based Input Controller
Configure a gpio
input controller to use a GPIO- or ADC-based device to communicate with your machine.
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 input_controller
type, then select the gpio
model.
Enter a name or use the suggested name for your input controller and click Create.
Copy and paste the following attribute template into your input controller’s attributes field. Then remove and fill in the attributes as applicable to your input controller, according to the table below.
{
"board": "<your-board-name>",
"buttons": {
"<your-button-name>": {
"control": "<button-control-name>",
"invert": <boolean>,
"debounce_msec": <int>
}
},
"axes": {
"<your-axis-name>": {
"control": "<axis-control-name>",
"min": <int>,
"max": <int>,
"poll_hz": <int>,
"deadzone": <int>,
"min_change": <int>,
"bidirectional": <boolean>,
"invert": <boolean>
}
},
"depends_on": ["<your-board-name>"]
}
{
"board": "piboard",
"buttons": {
"interrupt1": {
"control": "ButtonNorth",
"invert": false,
"debounce_msec": 5
},
"interrupt2": {
"control": "ButtonSouth",
"invert": true,
"debounce_msec": 5
}
},
"axes": {
"analog1": {
"control": "AbsoluteX",
"min": 0,
"max": 1023,
"poll_hz": 50,
"deadzone": 30,
"min_change": 5,
"bidirectional": false,
"invert": false
},
"analog2": {
"control": "AbsoluteY",
"min": 0,
"max": 1023,
"poll_hz": 50,
"deadzone": 30,
"min_change": 5,
"bidirectional": true,
"invert": true
}
},
"depends_on": ["piboard"]
}
{
"components": [
{
"name": "<your-gpio-input-controller-name>",
"model": "gpio",
"type": "input_controller",
"namespace": "rdk",
"attributes": {
"board": "<your-board-name>",
"buttons": {
"<your-button-name>": {
"control": "<button-control-name>",
"invert": <boolean>,
"debounce_msec": <int>
}
},
"axes": {
"<your-axis-name>": {
"control": "<axis-control-name>",
"min": <int>,
"max": <int>,
"poll_hz": <int>,
"deadzone": <int>,
"min_change": <int>,
"bidirectional": <boolean>,
"invert": <boolean>
}
}
},
"depends_on": ["<your-board-name>"]
}
]
}
{
"components": [
{
"name": "my_gpio_ic",
"model": "gpio",
"type": "input_controller",
"namespace": "rdk",
"attributes": {
"board": "piboard",
"buttons": {
"interrupt1": {
"control": "ButtonNorth",
"invert": false,
"debounce_msec": 5
},
"interrupt2": {
"control": "ButtonSouth",
"invert": true,
"debounce_msec": 5
}
},
"axes": {
"analog1": {
"control": "AbsoluteX",
"min": 0,
"max": 1023,
"poll_hz": 50,
"deadzone": 30,
"min_change": 5,
"bidirectional": false,
"invert": false
},
"analog2": {
"control": "AbsoluteY",
"min": 0,
"max": 1023,
"poll_hz": 50,
"deadzone": 30,
"min_change": 5,
"bidirectional": true,
"invert": true
}
}
},
"depends_on": ["piboard"]
}
]
}
The following attributes are available for gpio
input controllers:
Name | Type | Inclusion | Description |
---|---|---|---|
board | string | Required | The name of the board component with GPIO or ADC pins to use as the controlling device. |
buttons | object | Required | The Buttons available for control. These should be connected to the GPIO/ADC board. Each button has the following fields:
|
axes | object | Required | The Axes available for control. These should be connected to the GPIO/ADC board. Each axis has the following fields:
|
Test the input controller
After you configure your input controller, navigate to the Control tab and select the dropdown panel dedicated to the input controller. View the current value of each input on your controller.
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.
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.
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!