Skip to content
Xila

Control GPIO pins

List the GPIO pins of a board and read or write them through the character devices under /devices/gpio/.

Last updatedEdit page

Xila mounts the GPIO pins of a board as character devices under /devices/gpio/. This guide shows how to list the pins of your board and read or write them. Install Xila on a board first, then log in on the serial console. For the features of each board, see Supported hardware.

  • Xila installed on the board and a logged-in command-line shell. See Install Xila on a board.
  • A board whose firmware mounts GPIO devices. The tabs below list the devices of each board.
  1. In the Xila shell, list the mounted GPIO devices:
ls /devices/gpio

The output lists the devices of your board:

GPIO device Board resource Notes
/devices/gpio/d0 to /devices/gpio/d13 Header digital pins
/devices/gpio/a0 to /devices/gpio/a7 Header analog pins
/devices/gpio/d13 Onboard yellow LED Active-high, initially off
/devices/gpio/led_red, /devices/gpio/led_green, /devices/gpio/led_blue Onboard RGB LEDs Active-low, initially off

Internal power-enable lines (sensor power rails and I2C pull-ups) remain reserved and cannot be altered through GPIO devices.

  1. In the Xila shell, read the device file of the pin to read its state:
cat /devices/gpio/d13

The device outputs 0 or 1 followed by a newline.

  1. Write to the device file of the pin to update its output level:
# Turn on the yellow LED:
echo 1 > /devices/gpio/d13
# Turn off the yellow LED:
echo 0 > /devices/gpio/d13

For the active-low RGB LEDs, writing 0 turns the LED on, and writing 1 turns it off:

# Turn on the red LED:
echo 0 > /devices/gpio/led_red
# Turn off the red LED:
echo 1 > /devices/gpio/led_red

Writing any character other than 0 or 1 (surrounded by optional whitespace) returns an error.

  1. In the serial terminal, verify that the shell prompt (user@host:directory$) appears after logging in.
  2. Run ls /devices/gpio and check that the output lists the pins of your board.
  1. Run echo 1 > /devices/gpio/d13 and observe that the yellow onboard LED lights up.
  2. Run echo 0 > /devices/gpio/d13 and observe that the yellow LED turns off.