DLI Atomic Pi user guide
20190502T140852Z
GPIO pin reference

The Atomic Pi has 6 GPIO pins available to users, and additional lines connected to the BNO055 sensor. Here's a overview of them.

Addressing

In order to use GPIO pins from Linux, it's important to understand how they are addressed in various situations.

Each GPIO has a global number in the integer GPIO namespace used with the legacy GPIO interface (e.g. through sysfs). This is considered a legacy interface but there are currently no plans to remove it. However, in addition to that, recent Linux kernels expose GPIO chips, which are basically named sets of GPIOs of the same hardware origin with a single base number; GPIOs are numbered sequentially within a chip, but the global GPIO namespace itself needn't be contiguous.

Pin description

Generally available pins:

Schematic nameGPIO chip idChip pin numberGlobal pin numberConnected devices
ISH_GPIO_0gpiochip321335
ISH_GPIO_1gpiochip318332LED Green (active low)
ISH_GPIO_2gpiochip324338LED Yellow (active low)
ISH_GPIO_3gpiochip315329
ISH_GPIO_4gpiochip322336
ISH_GPIO_7gpiochip316330

These signals are available on the Atomic Pi's 26-pin connector. If you have the Enchilada breakout board, the signals are available as on it as well. Connector pin numbers are as follows:

Schematic name26-pin connector numberEnchilada connector number
ISH_GPIO_0249
ISH_GPIO_12510
ISH_GPIO_22611
ISH_GPIO_3183
ISH_GPIO_4194
ISH_GPIO_7205

"Volume control button" pins (available on the "VOLUME"/"VOL" connectors, can be used as regular GPIO pins):

Schematic nameGPIO chip idChip pin numberGlobal pin numberDescription
GPIO_DFX_2gpiochip17348Volume up pin
GPIO_DFX_4gpiochip15346Volume down pin

Other pins (not on the 26-pin connector or the Enchilada connector):

Schematic nameGPIO chip idChip pin numberGlobal pin numberConnected devices
I2C2_3P3_SDAgpiochip062476BNO055 I2C SDA
I2C2_3P3_SCLgpiochip066480BNO055 I2C SCL
AU_MIC_SELgpiochip10341XMOS Audio microphone loopback selector
XMOS_RESETgpiochip18349XMOS Audio reset (active low)
BN_INTgpiochip117358BNO055-generated interrupt (active low)
BN_RESETgpiochip125366BNO055 reset (active low)

The XMOS_RESET line is controlled by a system service, atomicpi-hold-xmos, to bring up the XMOS Audio device.

The AU_MIC_SEL line must be configured to logical 0 to record audio from microphone, or to logical 1 for loopback (recording audio being played back).

Using the interrupt and reset lines is not strictly required for BNO055 operation. Additional devices may be connected to its I2C bus but that would require soldering.

Note that the system core contains other GPIO pins, some connected to internal circuits. Reading the datasheet is strongly recommended before attempting to configure them!

Using GPIOs from the shell

GPIO pin constants can be pulled in by including /usr/lib/atomicpi.sh:

. /usr/lib/atomicpi.sh

The traditional sysfs way of manipulating GPIOs from the command line is documented at:

https://www.kernel.org/doc/Documentation/gpio/sysfs.txt

It is listed as deprecated but there are no plans to remove it.

. /usr/lib/atomicpi.sh
echo $ATOMICPI_ISH_GPIO_1 >/sys/class/gpio/export
echo $ATOMICPI_ISH_GPIO_2 >/sys/class/gpio/export
echo low >/sys/class/gpio/$ATOMICPI_ISH_GPIO_1/direction
while true; do
    echo low > /sys/class/gpio/$ATOMICPI_ISH_GPIO_2/direction
    sleep 1
    echo high > /sys/class/gpio/$ATOMICPI_ISH_GPIO_2/direction
    sleep 1
done
echo $ATOMICPI_ISH_GPIO_2 >/sys/class/gpio/unexport
echo $ATOMICPI_ISH_GPIO_1 >/sys/class/gpio/unexport

Constants storing global GPIO indices are prefixed by ATOMICPI_.

Additionally, several utilities allow GPIO control using the more modern interface (and chip id + pin index addressing):

Constants storing "<chip id> <pin index>" are prefixed by ATOMICPICHIP_. Due to shell expansion rules, ${ATOMICPICHIP_ISH_GPIO_0} (without quotes) will expand to two arguments, the chip id and the pin index, which is what most of the following utilities expect.

List all GPIO chips, print their labels and number of GPIO lines:

gpiodetect

Find a GPIO line by name (the output of this command can be used as input for gpioget/gpioset):

gpiofind <name>

Print information about all lines of the specified GPIO chip(s) (or all chips if none are specified):

gpioinfo <gpiochip1> ...

Read line value(s) from a GPIO chip:

gpioget [-l] <chip name/number> <offset 1> <offset 2> ...

Options:
  -l, --active-low:     set the line active state to low

Set GPIO line values of a GPIO chip:

 gpioset [OPTIONS] <chip name/number> <offset1>=<value1> <offset2>=<value2> ...

 Options:
   -l, --active-low:     set the line active state to low
   -m, --mode=[exit|wait|time|signal] (defaults to 'exit'):
                 tell the program what to do after setting values
   -s, --sec=SEC:        specify the number of seconds to wait (only valid for --mode=time)
   -u, --usec=USEC:      specify the number of microseconds to wait (only valid for --mode=time)
   -b, --background:     after setting values: detach from the controlling terminal

 Modes:
   exit:         set values and exit immediately
   wait:         set values and wait for user to press ENTER
   time:         set values and sleep for a specified amount of time
   signal:       set values and wait for SIGINT or SIGTERM

Wait for events on GPIO lines:

gpiomon [OPTIONS] <chip name/number> <offset 1> <offset 2> ...

Options:
  -l, --active-low:     set the line active state to low
  -n, --num-events=NUM: exit after processing NUM events
  -s, --silent:         don't print event info
  -r, --rising-edge:    only process rising edge events
  -f, --falling-edge:   only process falling edge events
  -F, --format=FMT      specify custom output format

Format specifiers:
  %o:  GPIO line offset
  %e:  event type (0 - falling edge, 1 rising edge)
  %s:  seconds part of the event timestamp
  %n:  nanoseconds part of the event timestamp

See /usr/lib/atomicpi.sh for details.

Using GPIOs from Node.JS

var atomicpi = require("atomicpi");
var GPIO = require("sysfs-gpio");
console.log("Control by signal ID");
GPIO.export(atomicpi.signals.ISH_GPIO_0.global_idx, (pin) => {
   pin.out();
   pin.high();
});
console.log("Control with signal ID lookup on Enchilada connector first");
GPIO.export(atomicpi.signals[atomicpi.connectors.enchilada.leds.green].global_idx, (pin) => {
   pin.out();
   pin.low();
});
process.stdin.resume();

atomicpi.signals contains a mapping from the signal name (e.g. "ISH_GPIO_0") to {chip,chip_idx,global_idx}. You will need global_idx most of the time as sysfs-gpio uses the legacy sysfs interface.

See /usr/lib/node/atomicpi.js and sysfs-gpio documentation for details.

Using GPIOs from Python

import atomicpi
import gpio as GPIO
# Control by signal ID
GPIO_0=atomicpi.signals.ISH_GPIO_0.global_idx
GPIO.setup(GPIO_0, GPIO.OUT)
GPIO.output(GPIO_0, True)
# Control with signal ID lookup on Enchilada connector first
GREEN_LED=atomicpi.signals[atomicpi.connectors.enchilada.leds.green].global_idx
GPIO.setup(GREEN_LED, GPIO.OUT)
GPIO.output(GREEN_LED, False)
GPIO.cleanup(GPIO_0)
GPIO.cleanup(GREEN_LED)

atomicpi.signals contains a mapping from the signal name (e.g. "ISH_GPIO_0") to {chip,chip_idx,global_idx}. You will need global_idx most of the time as gpio uses the legacy sysfs interface.

The gpio library largely mimics the Raspberry Pi RPIO library.

See /usr/lib/python/dist-packages/atomicpi.py and gpio documentation for details.