Homepage Wiki Forum Buy



severity (level) requirement Gnublin family
Gnublin logo advanced.png Kernel compile, Toolchain Alle


You can add 8 relay to your project with this relay module. You can easily control the module with one of two programs or the GPIO-sysfs

MODULE-RELAY schraeg.jpg

Attention: the Gnublin connector cable has a red wire. This wire must be on GPA0/GPA1 on the Gnublin board!!


The easiest way to interact with the module is the program gnublin-relay. You can run it with the following command:

root@gnublin:~# gnublin-relay -o 1 -p 1


root@gnublin:~# gnublin-relay -o 0 -p 1

or with -p 1 or -p 2 maximum is -p 8.

If you want to know the state of a specific relay, you should try:

root@gnublin:~# gnublin-relay -p 1 -r

If the module is not addressed with the default address 0x20 you have to set the address in the command.

root@gnublin:~# gnublin-relay -a 0x22 -o 1 -p 2

The Help command gives you an overview of all possible parameters.

root@gnublin:~# gnublin-relay -h
This program was designed to easily interact with the relay module for GNUBLIN.
-h show this help
-p <Y> specify the relay number (1-8)
-o <value> set pin as output with given <value>(0= low / 1 = high)
-a <Address> specifiy the module address (default is 0x20)
-j show output in json format
-b show output in raw format
Set relay 1 high
gnublin-relay -p 1 -o 1
Set relay 1 on a Module connected to Address 0x21 low
gnublin-relay -a 0x21 -p 1 -o 0


You can also use the program gnublin-pca9555

root@gnublin:~# gnublin-pca9555 -o 1 -p 0


root@gnublin:~# gnublin-pca9555 -o 0 -p 0

or with -p 1 or -p 2 maximum is -p 7.

The Address of the module can be set in this command too.

root@gnublin:~# gnublin-pca9555 -a 0x21 -o 1 -p 1


First of all you need to load the driver like its described in the following line:

root@gnublin:~# modprobe pca953x cnt=<Int> addr1=<I2C-Adresse>
  1. cnt is the number of port expanders(relay modules) connected (default=1)
  2. addr1 I2C Address of the first relay module or port expander (Hex)
  3. addr2 I2C Address of the second relay module or port expander (Hex)
  4. addr3, addr4 , and addr5 analogue to addr1 addr2

If you have one relay module with I2C address 0x20 you can type the following:

root@gnublin:~# modprobe pca953x addr1=0x20

If you have two relay modules one with I2C address 0x20 and the other with I2C address 0x24 you should type in the following:

root@gnublin:~# modprobe pca953x cnt=2 addr1=0x20 addr2=0x24

The I2C address of a module depends on how the jumpers are plugged.

You can display the I2C addresses with the command i2cdetect -y 1. The range of the addresses is between 0x20 and 0x27.

Relay as output

Now you can switch on the first relay of your relay-module:

root@gnublin:~# gnublin-gpio -o 1 -p 98

or you can switch the relais off with the following command:

root@gnublin:~# gnublin-gpio -o 0 -p 98

Read the status of the relay

You can read out the state of the relay with the following command:

root@gnublin:~# gnublin-gpio -i -p <pin>

You must change <pin> to the value for the relay you want to read out. Look at the table to discover the values and the value for <pin>.

Relay and gpio-sysfs values

here is a table with the relays and the corresponding numbers for the gpio-sysfs. You can use the commands from the examples above.

Relay number Number for /sys/class/gpio/export
Relay 0 98
Relay 1 99
Relay 2 100
Relay 3 101
Relay 4 102
Relay 5 103
Relay 6 104
Relay 7 105
In other languages