Skip to content

Digital outputs

Pigeon computer has 8 open drain digital outputs. Fig. 1 shows the recommended connection of an LED (a) and relays (b, c) to open-drain outputs. The internal diodes protect the output transistors from transient voltage spikes (b). In the case of long cables to the relay, using an external diode (c) is recommended.

digital-outputs

Fig. 1. Example of digital output connections

Table 1. Digital outputs parameters

PARAMETER VALUE
Quantity of outputs 8
Maximum current 500 mA
Maximum voltage 28 V DC

Linux kernel GPIO user space interface

gpiod

Installation of the gpiod tools:

$ apt install gpiod 

Change the state of output O1:

$ gpioset -t 0 -c gpiochip14 0=0 
$ gpioset -t 0 -c gpiochip14 0=1

Change state of output O8:

$ gpioset -t 0 -c gpiochip14 7=0 
$ gpioset -t 0 -c gpiochip14 7=1

Table 2. Digital outputs - gpiod

SIGNAL BIT Trixie gpiochip Bookworm gpiochip
O1 0 gpiochip14 gpiochip2
O2 1 gpiochip14 gpiochip2
O3 2 gpiochip14 gpiochip2
O4 3 gpiochip14 gpiochip2
O5 4 gpiochip14 gpiochip2
O6 5 gpiochip14 gpiochip2
O7 6 gpiochip14 gpiochip2
O8 7 gpiochip14 gpiochip2

Note on gpiochip numbering. The gpiochip numbering may vary between different Linux kernel versions. The binary outputs and opto-isolated binary inputs are provided by the MCP23017 I/O expander and are identified by the gpiochip corresponding to this device. If the gpiochip number is unknown or differs between systems, the recommended approach is to use the gpiodetect command, which lists all available GPIO controllers along with their identifiers.

$ gpiodetect
...
gpiochip14 [mcp23017]

Direct control via the I2C interface

If you want to control the outputs directly via the I2C interface, you need to comment out the following line in the /boot/firmware/config.txt file (or /boot/config.txt in older distributions):

#dtoverlay=mcp23017,addr=0x20,gpiopin=23 

Otherwise, you will get the following message:

Unable to select I2C device: Device or resource busy. 

Setting ports to output mode:

$ i2cset -y 1 0x20 0x00 0x00 

Setting output O1 to high:

$ gpio -x mcp23017:100:0x20 write 100 1 

Setting output O1 to low:

$ gpio -x mcp23017:100:0x20 write 100 0 

Setting output O2 to high:

$ gpio -x mcp23017:100:0x20 write 101 1 

Setting output O2 to low:

$ gpio -x mcp23017:100:0x20 write 101 0 

To control subsequent outputs, you need to adjust the second-to-last argument accordingly: O3=102, O4=103, and so on.

Information for Codesys Users

If you want to use binary inputs/outputs in Codesys, you need to comment out the following line in the /boot/firmware/config.txt file (or /boot/config.txt for older distributions):

dtoverlay=mcp23017,addr=0x20,gpiopin=23