Raspberry Pi GPIO Control
Allows to display the state of the GPIO for the target Raspberry Pi device using the latest attribute values. You should set the label of the selected data key to the GPIO PIN (e.g., ‘1’) and use boolean values for the widget to display the data.
Who it’s for
Anyone driving a Raspberry Pi’s GPIO pins from a dashboard — switching relays on a home-automation build, enabling outputs on a prototype, toggling a test rig. The panel arrives laid out for the Pi’s own pin numbering rather than needing it built from scratch.
What it does
The Raspberry Pi GPIO Control presents a grid of switches covering the Pi’s usable GPIO pins and sends an RPC command whenever one is flipped. It reads the current pin states with getGpioStatus and writes changes with setGpioStatus, sending the pin number and the desired state in the request body.
- Preconfigured for the Pi — seventeen switches covering the usable GPIO pins, rather than a blank panel.
- Pin states are read back from the device rather than assumed, so the panel reflects the hardware.
- The request bodies are templates with
{$pin}and{$enabled}placeholders, so the payload matches whatever the firmware or script expects. - A parse function converts the status response into per-pin booleans, so no particular response format is required.
- Switch positions are set by row and column, so the panel can be arranged to match the physical header.
- The Raspberry Pi GPIO Control requires an agent on the Pi that implements both RPC methods; nothing works until that exists.
How to set up
Data keys
The Raspberry Pi GPIO Control takes no data keys — it communicates entirely over RPC.
| Method | Direction | Parameters | Sent when |
|---|---|---|---|
getGpioStatus | Two-way (request-response) | {} | On load and refresh, to read every pin’s state |
setGpioStatus | Two-way (request-response) | {"pin": "{$pin}", "enabled": "{$enabled}"} | Whenever a switch is flipped |
GPIO
| Setting | Default | Effect |
|---|---|---|
| GPIO switches | Seventeen switches for the Pi’s usable pins | Each carries a pin number, a label and a row and column position |
| GPIO status request | getGpioStatus, body {} | The method that reads the current pin states |
| GPIO status change request | setGpioStatus, body with {$pin} and {$enabled} | The method that writes a pin |
| Parse gpio status function | return body[pin] === true; | Turns the status response into a per-pin boolean |
| RPC request timeout | 500 | How long each call waits, in milliseconds |
Confirm which pin numbering the agent on the Pi expects. BCM and physical header numbering differ for almost every pin, and a panel built against the wrong scheme switches the wrong hardware while appearing to work.
How to customize
- To keep only the pins in use — remove the unused switches from the GPIO switches list, which makes the panel far easier to operate.
- To match the physical header — set each switch’s row and column so the layout mirrors the board.
- To match the agent’s API — set the method names and bodies in the status and status change requests.
- To handle a different response shape — edit the Parse gpio status function.
- To distinguish panels — set the Background color.
- To suit a remote Pi — raise the RPC request timeout from its 500 ms default.
Tips
- Cut the panel down to the pins actually wired. Seventeen switches is a complete header and an invitation to flip the wrong one, whereas four labelled with what they drive is a control panel.
- Label each switch with the hardware rather than the pin. Anyone reading the dashboard six months later knows what Greenhouse fan does and has no idea what GPIO 23 is connected to.
Share Your Widget with the Community
Built a custom widget? Export it as a JSON from ThingsBoard and publish it to the IoT Hub through a simple 4-step wizard (Upload, Listing, Readme, Review & Submit). Share it with thousands of ThingsBoard developers worldwide and get featured in the catalog.