Connect to the Dev Board I/O pins

The Coral Dev Board provides access to several peripheral interfaces through the 40-pin expansion header, including GPIO, I2C, UART, and SPI.

All I/O pins on the 40-pin header are powered by the 3.3V power rail, with a programmable impedance of 40 - 255 ohms, and a max current of ~82 mA. You can interact with each pin using standard Linux interfaces such as device files (/dev) and sysfs files (/sys).

Figure 1. Location of pin 1 on the 40-pin header

Header pinout

Table 1 shows the header pinout, including the sysfs paths for each port, which is often the name required when using the periphery library. For a pinout that includes the SoM pin names, instead see the Dev Board datasheet.

You can also see the header pinout from the command line by typing pinout on the Dev Board.

Note: All I/O pins have a 90k pull-down resistor inside the iMX8M SoC that is used by default during bootup, except for the I2C pins, which instead have a pull-up to 3.3V on the SoM.
Caution: Do not connect a device that draws more than ~ 82 mA of power or you will brownout the system.
Table 1. Pinout for the 40-pin I/O header
sysfs path Pin function Pin Pin function sysfs path
+3.3V Power 1 2 +5V Power
/dev/i2c-1 I2C 2 (SDA) 3 4 +5V Power
/dev/i2c-1 I2C 2 (SCL) 5 6 Ground
/dev/ttymxc2 UART 3 (TXD) 7 8 UART 1 (TXD) /dev/ttymxc0
Ground 9 10 UART 1 (RXD) /dev/ttymxc0
/dev/ttymxc2 UART 3 (RXD) 11 12 SAI 1 (TXC)
/sys/class/gpio/gpio6 GPIO 6 13 14 Ground
/sys/class/pwm/pwmchip2/pwm0 PWM 3 15 16 GPIO 73 /sys/class/gpio/gpio73
+3.3V Power 17 18 GPIO 138 /sys/class/gpio/gpio138
/dev/spidev32766 SPI 1 (MOSI) 19 20 Ground
/dev/spidev32766 SPI 1 (MISO) 21 22 GPIO 140 /sys/class/gpio/gpio140
/dev/spidev32766 SPI 1 (SCLK) 23 24 SPI 1 (SS0) /dev/spidev32766.0
Ground 25 26 SPI 1 (SS1) /dev/spidev32766.1
/dev/i2c-2 I2C 3 (SDA) 27 28 I2C 3 (SCL) /dev/i2c-2
/sys/class/gpio/gpio7 GPIO 7 29 30 Ground
/sys/class/gpio/gpio8 GPIO 8 31 32 PWM 1 /sys/class/pwm/pwmchip0/pwm0
/sys/class/pwm/pwmchip1/pwm0 PWM 2 33 34 Ground
SAI 1 (TXFS) 35 36 GPIO 141 /sys/class/gpio/gpio141
/sys/class/gpio/gpio77 GPIO 77 37 38 SAI 1 (RXD)
Ground 39 40 SAI 1 (TXD)
Warning: Use caution when handling the GPIO pins to avoid electrostatic discharge or contact with conductive materials (metals). Failure to properly handle the Dev Board can result in a short circuit, electric shock, serious injury, death, fire, or damage to your board and other property.

Using the Periphery library

To access the header pins on the Dev Board, you can use standard Linux sysfs interfaces. But if you'd like a Python API, we recommend you use the python-periphery library, which is built atop the sysfs interfaces.

You can install the library on your Dev Board as follows:

sudo apt-get install python3-pip

sudo pip3 install python-periphery
Note:
  • To access peripheral hardware resources on the Dev Board, you need to run your code with sudo privileges.
  • You should install the Python 3 version of Periphery because that's the Python version required by the Edge TPU Python API.

The Periphery library allows you to select a GPIO or PWM pin with a pin number. Other interfaces, such as I2C and UART pins must be specified using the pin's device path. See the following examples.

GPIO

The following code shows how to instantiate each of the GPIO pins with Periphery:

gpio6 = GPIO(6, "in")
gpio7 = GPIO(7, "in")
gpio8 = GPIO(8, "in")
gpio138 = GPIO(138, "in")
gpio140 = GPIO(140, "in")
gpio141 = GPIO(141, "in")

gpio73 = GPIO(73, "out")
gpio77 = GPIO(77, "out")
Note: GPIO73 and GPIO77 currently support only the "out" direction.

For more examples, see the periphery GPIO documentation.

PWM

The following code shows how to instantiate each of the PWM pins with Periphery:

# PWM1 = pwmchip0, pwm0
pwm1 = PWM(0, 0)
# PWM1 = pwmchip1, pwm0
pwm2 = PWM(1, 0)
# PWM1 = pwmchip2, pwm0
pwm3 = PWM(2, 0)

For usage examples, see the periphery PWM documentation.

I2C

The following code shows how to instantiate each of the I2C ports with Periphery:

i2c2 = I2C("/dev/i2c-1")
i2c3 = I2C("/dev/i2c-2")

For usage examples, see the periphery I2C documentation.

SPI

The following code shows how to instantiate each of the SPI ports with Periphery:

# SPI1, SS0, Mode 0, 10MHz
spi1_0 = SPI("/dev/spidev32766.0", 0, 10000000)
# SPI1, SS1, Mode 0, 10MHz
spi1_1 = SPI("/dev/spidev32766.1", 0, 10000000)

For usage examples, see the periphery SPI documentation.

UART

The following code shows how to instantiate each of the UART ports with Periphery:

# UART1, 115200 baud
uart1 = Serial("/dev/ttymxc0", 115200)
# UART3, 9600 baud
uart3 = Serial("/dev/ttymxc2", 9600)
Caution: UART1 is shared with the Linux serial console. To use the UART1 port in your application, you must disable the serial console with the following command:
systemctl stop serial-getty@ttymxc0.service
Note: UART3 is not enabled by default in Mendel 3.0 (Chef), but we've released a package update to enable it. First check to see if it's available on your board:
ls /dev | grep ttymxc

If you see ttymxc2 listed, then you're all good. If not, then you need to update as follows:

sudo apt-get update

sudo apt-get dist-upgrade

sudo reboot now

For usage examples, see the periphery Serial documentation.