Computers for industrial control and automation systems

Digital outputs

Digital outputs

Pigeon computers are equipped with 8 open drain digital outputs. Two of them (O6 and O7) can function as PWM outputs. Table 1 outlines the assignment of outputs to the GPIO. The output becomes active when the state of the corresponding GPIO is high. The ENABLE signal operates on an active low basis. If the ENABLE signal is high, then all digital outputs are turned off.

Figure 1 illustrates the recommended connections of LED (a) and relays (b,c) to the open drain outputs. The internal diodes provide protection for the output transistors against transient voltage peaks (b). In the scenario of long cables to relays, it is advisable to employ an external diode (c).

digital-outputs

Fig. 1. Example digital outputs connections

Table 1. Digital outputs - GPIO

Signal GPIO
ENABLE GPIO34
O1 GPIO35
O2 GPIO36
O3 GPIO37
O4 GPIO38
O5 GPIO39
O6 GPIO40
O7 GPIO41
O8 GPIO42

Table 2. Digital outputs parameters

Parameter Value
Quantity of outputs 8
Maximum current 500 mA
Maximum voltage 28 V DC

Software

Bash

Change state of output O1:

#export GPIOs to userspace
echo "34" > /sys/class/gpio/export
echo "35" > /sys/class/gpio/export

#Set GPIOs as an output
echo "out" > /sys/class/gpio/gpio34/direction
echo "out" > /sys/class/gpio/gpio35/direction

#ENABLE active
echo "0" > /sys/class/gpio/gpio34/value

#Turn on O1
echo "1" > /sys/class/gpio/gpio35/value

#Turn off O1
echo "0" > /sys/class/gpio/gpio35/value

#unexports GPIOs
echo "34" > /sys/class/gpio/unexport
echo "35" > /sys/class/gpio/unexport

WiringPi library comes pre-installed, offering utilities to manage the GPIO. Below are some examples:

#Set GPIOs as an output
gpio mode 34 out
gpio mode 35 out

#ENABLE active
gpio write 34 0

#Turn on O1
gpio write 35 1

#Turn off O1
gpio write 35 0

#Set O6 mode to PWM
gpio mode 40 pwm

#Set O6 PWM value 500 (0-1023 is supported)
gpio pwm 40 500

Python

To change the state of output O1, you can use the following commands:

python

>>> import RPi.GPIO as GPIO
>>> GPIO.setmode(GPIO.BCM)
>>> GPIO.setup(34, GPIO.OUT)
>>> GPIO.setup(35, GPIO.OUT)
>>> GPIO.output(34, False) #ENABLE active
>>> GPIO.output(35, True) #Turn on O1
>>> GPIO.output(35, False) #Turn off O1

Links

Back to Top