Documentation

Buttons and relays on GPIO

Connect push buttons, door contacts, or relay boards to a Player's GPIO pins so your screen application can react to physical inputs, switch external loads, and send events back to your AI agent.

What GPIO does

GPIO (general-purpose input/output) pins let an application read digital inputs (high or low) and drive digital outputs (high or low) individually.

Common inputs:

  • Push buttons (such as "call for service" or "next page").
  • Door or window contacts, reed switches, and limit switches.
  • Any sensor providing a dry contact or relay output (such as a flow switch or motion detector).

Common outputs:

  • Relay boards controlling door strikes, stack lights, or buzzers.
  • Indicator LEDs mounted in push buttons.

Applications access pins through screenrig.device.gpio and notify your agent with emit so physical actions (like "service.requested") appear in your project event log. Your agent builds, uploads, and assigns GPIO apps just like any other web app. See Hardware an application can use for other supported peripherals.

Which Players have GPIO

PlayerGPIO supportInput pull resistorsOutput idle levelPin numbering
Raspberry Pi 4 and 5 (Linux Player)Yes, on the 40-pin header (detected automatically)"up", "down", or "none"YesBCM GPIO numbers
Other Linux boardsYes, via SCREENRIG_GPIO_CHIP"up", "down", or "none"YesChip line numbers
Android and Amazon Signage StickDevices exposing a writable sysfs GPIO chipNo (wire an external resistor)YesChip global line numbers
BrightSignYes: connector pins 0–7, USB GPIO expanders, and BP200/BP900 button boardsBuilt-in pull-upsYesPins 0–7 and bank ranges (see BrightSign)
macOS, Windows, Player web app, Samsung Smart Signage (Tizen), LG webOS SignageNoNoNoNo

capabilities["device.gpio"] is true only for the page's controller (or sole application) on a Player and device with GPIO available, allowing one app build to run safely on screens without GPIO.

Set up the Player

Raspberry Pi

Raspberry Pi 4 and 5 require no manual chip configuration—the Linux Player locates the 40-pin header automatically and uses BCM pin numbers. Make sure the user running the Player has access to /dev/gpiochip*. On Raspberry Pi OS, the default user is already in the gpio group. If you use a custom --kiosk-user (the --kiosk installer only adds video and i2c), add it to gpio and restart the Player:

sudo usermod -aG gpio KIOSK_USER

Other Linux boards

Set SCREENRIG_GPIO_CHIP in the Player's environment to point to the character device carrying your pins:

SCREENRIG_GPIO_CHIP=/dev/gpiochip4

For a --kiosk systemd service, run sudo systemctl edit screenrig-player-kiosk.service and add:

[Service]
Environment=SCREENRIG_GPIO_CHIP=/dev/gpiochip4

Pin numbers correspond to that chip's line numbers, and the Player user needs access to the chip's device file.

Android

GPIO works on Android boards and custom images that expose a writable sysfs GPIO chip (standard TV boxes lack this and report device.gpio: false). Pin numbers use the chip's global line numbers, and the Player holds a line only while the app uses it. Because Android does not configure internal pull resistors, add an external resistor as shown in Wire a button.

Choose a pin

pin is an integer from 0 to 255 representing the chip's line number. On Raspberry Pi, always pass the BCM GPIO number rather than the physical header position (for example, GPIO17 is pin 17, located at physical pin 11):

BCM number (pin)Physical pinNotes
1711Good starting pin
2713—
2215—
2316—
2418—
2522—
529—
631—
1232—
1333—
1636—
2637—
2038—
2140—
2 and 33 and 5I2C lines with fixed pull-ups; leave for I2C
14 and 158 and 10Serial console lines
0 and 127 and 28Reserved for HAT identification

Ground is on physical pins 6, 9, 14, 20, 25, 30, 34, and 39; 3.3 V is on physical pins 1 and 17. Requesting a line held by another process fails with pin_busy; requesting a nonexistent line fails with pin_not_found. The Raspberry Pi documentation lists the whole header.

Wire a button

Connect a push button between a GPIO input and ground, and enable a pull-up resistor. The pin stays high while idle and reads low when pressed:

 GPIO17 (pin 11) -----+
                      |
                   [ button ]
                      |
 GND (pin 9) ---------+

On Raspberry Pi and other Linux boards, enable the internal pull-up with pull: "up":

window.screenrig.device.gpio.onChange(17, handlePress, { pull: "up" });

Use pull: "down" for buttons wired to 3.3 V (which read high when pressed). The default is "none": the Player sets no bias, so an input with nothing connected floats and a button without a resistor reads random changes.

  • Android: Wire an external ~10 kΩ pull-up resistor between the input pin and 3.3 V for buttons wired to ground.
  • BrightSign: Built-in pull-ups are active automatically, so buttons wired to ground work without external resistors.
  • Unsupported pull options: Passing "up" or "down" on a Player that cannot configure pulls still starts watching the line without a pull and logs a single warn with code gpio_pull_unsupported.

Drive a relay

Always switch relays through a relay driver board, never directly from a GPIO pin. GPIO pins supply only a few milliamps at 3.3 V—not enough to switch a relay coil, a door strike, a stack light or a buzzer—and inductive kickback from a bare coil can damage the board. A relay board includes the driver transistor and flyback protection.

 5V (pin 2) -------------- VCC |
 GND (pin 6) ------------- GND | relay board
 GPIO27 (pin 13) --------- IN1 |
                               |  COM ---- supply for the load
                               |  NO  ---- the load (door strike, light, buzzer)

Power the switched load from its own power supply through the relay contacts, and select a relay board whose control input triggers at 3.3 V logic:

const sr = window.screenrig;
await sr.device.gpio.write(27, true);   // relay on
await sr.device.gpio.write(27, false);  // relay off

Most boards energize on high. Many inexpensive relay modules are active-low (energizing when pulled low). Pass idle: true on active-low boards so leaving the page releases the relay in the off state (see Idle level):

await sr.device.gpio.write(27, false, { idle: true }); // active-low board: relay on
await sr.device.gpio.write(27, true, { idle: true });  // relay off

BrightSign outputs drive 3.3 V through 100 Ω and control relay boards the same way.

3.3 V logic only

All GPIO pins use 3.3 V logic. Raspberry Pi pins are not 5 V tolerant—applying 5 V can damage the board. Connect only dry contacts (buttons, switches, or isolated relay outputs). Interface any 5 V, 12 V, 24 V, or mains-voltage signal through a level shifter, optocoupler, or relay.

Debounce

Mechanical contacts bounce for several milliseconds on press and release. The Player automatically filters contact bounce (ignoring transitions shorter than ~20 ms on Linux and Raspberry Pi), so your handler receives one clean transition per press and release. Do not use GPIO inputs for pulses shorter than 20 ms.

Hear a line

Call onChange(pin, handler, options) to watch an input line. The handler receives a boolean (true = high, false = low): the first invocation delivers the level the pin has when the Player starts watching, and subsequent invocations fire on state changes. onChange returns an unsubscribe function:

const stop = window.screenrig.device.gpio.onChange(17, function (high) {
  doorOpen = high;
}, { pull: "up" });

You can watch up to 16 lines simultaneously (a 17th throws invalid_request). Multiple handlers on the same pin must agree on pull or the second call throws invalid_request.

Idle level

write(pin, value, options) accepts an idle boolean specifying the safe state (default false / low) that the Player sets before releasing the pin when the page leaves the screen, its context ends, or screenrig.destroy() is called. Each write updates the pin's stored idle level. Set idle to whatever level turns your hardware off (false for active-high boards, true for active-low boards).

When the page leaves

GPIO ownership lasts only while the page is on the screen. When the page transitions away, input listeners stop and every output returns to its idle level and is released. Outputs also release if the Player stops or power is lost—select fail-safe vs. fail-secure door hardware accordingly.

Limits and errors

  • Valid pin values: integers 0–255.
  • Maximum concurrent watched inputs: 16.
  • write rejects with invalid_request (invalid pin, value, or idle), pin_not_found (pin absent on chip), pin_busy (held by another process), or gpio_unavailable (no accessible GPIO chip). Passing idle on a Player that cannot set it rejects with not_supported.
  • onChange throws invalid_request on a 17th watched line or conflicting pull. Failed watches are logged and never invoke the handler.
  • All calls validate inert, not_supported, and capability_denied before touching hardware (see SDK hardware rules).

Example: call for service

A button on GPIO17 (wired to ground with pull-up) emits "service.requested" to your agent and activates an LED or buzzer relay on GPIO27 for 5 seconds. Because the initial callback reports the pin's starting level, the handler checks for a high-to-low transition:

const sr = window.screenrig;

function active() {
  return sr.readyState === "active";
}

async function start() {
  if (!sr) return;
  await sr.waitUntilActive();
  await sr.ready();
  if (!sr.supports("device.gpio") || !sr.capabilities["device.gpio"]) return;

  let wasHigh = null;
  sr.device.gpio.onChange(17, function (high) {
    const pressed = wasHigh === true && high === false;
    wasHigh = high;
    if (!pressed || !active()) return;
    sr.emit("service.requested");
    document.getElementById("message").hidden = false;
    sr.device.gpio.write(27, true).catch(function () {});
    setTimeout(function () {
      document.getElementById("message").hidden = true;
      if (active()) sr.device.gpio.write(27, false).catch(function () {});
    }, 5000);
  }, { pull: "up" });
}
start();

If the page transitions away during the 5-second window, the Player automatically returns pin 27 to its idle level, low unless you pass idle, so the relay never sticks on.

Your agent reads each press from the event log:

screenrig events list --type application.event --screen-id scr_SCREEN

Example: door-open input

A reed switch wired between GPIO17 and ground reads low when closed and high when opened. The page shows a notice while open and notifies your agent on every change:

const sr = window.screenrig;
const notice = document.getElementById("door-notice");

function show(open) {
  notice.hidden = !open;
  document.body.classList.toggle("door-open", open);
}

async function start() {
  show(false);
  if (!sr) return;
  await sr.waitUntilActive();
  await sr.ready();
  if (!sr.supports("device.gpio") || !sr.capabilities["device.gpio"]) return;
  sr.device.gpio.onChange(17, function (high) {
    show(high);
    if (sr.readyState === "active") sr.emit(high ? "door.opened" : "door.closed");
  }, { pull: "up" });
}
start();

BrightSign

BrightSign players use the same GPIO API. Onboard DA-15 connector pins map directly to 0–7 (on XT, XD, and HD models) with built-in input pull-ups (pull is not offered), full idle support, and 3.3 V / 100 Ω outputs suitable for driving relay boards.

BrightSign also maps USB GPIO accessories to dedicated pin banks:

Pin rangeHardware bank
0–7Onboard GPIO connector
8–39Up to 4 USB GPIO expanders (8 pins each: 8–15, 16–23, 24–31, 32–39)
100–110BP200 / BP900 button board 0 (100+k: watch reads button k, write drives LED k)
120–130, 140–150, 160–170Button boards 1, 2, and 3 using the same base+k mapping

Addressing a disconnected expander or button board rejects with pin_not_found.

Try it in app dev

screenrig app dev includes a built-in GPIO simulator with a chip toggle and three virtual lines: 17 (low), 27 (high), and 22 (busy, returning pin_busy). The examples above use 17 and 27. Click any line to toggle its input state and verify your handlers, writes, pull, and idle settings locally before deploying to hardware (see Develop locally). A write from the application moves the line, and the panel shows the idle level it set.

Reference

Questions

Can a screen drive a relay?
Yes, through a relay driver board. Your application sets a GPIO pin high or low, and the board switches the door strike, stack light, or buzzer. Never connect a relay coil directly to a GPIO pin.
Does a button need a resistor?
On Raspberry Pi and other Linux boards, no—enable the internal pull-up and wire the button to ground. On Android, add an external ~10 kΩ pull-up resistor to 3.3 V. BrightSign inputs have built-in pull-ups.
Which number do I pass for a pin?
On Raspberry Pi, pass the BCM GPIO number (for example, 17 for GPIO17 at physical pin 11). On other Linux boards, pass the GPIO chip line number. On BrightSign, use the pin ranges listed in the BrightSign section.
What happens to a relay when the page changes?
The Player drives the pin to its configured idle level (low by default) and releases it. Pass idle: true for active-low relay boards so the relay turns off cleanly.
Does the application need to run all the time?
No. The application listens while its page is on the screen; when the page leaves, inputs stop and outputs return to their idle levels.
What does it cost?
screenRIG is free. You only pay for your own board, buttons, and relays.