GPIO scripts and examples for linux / Armbian, RPI alternatives using i2c pcf8574 IO Expander found in cheap GPIO breakout boards.
My personal use case was to make a uart and gpio control hat for a Libre Computer Tritium H5 to control power for SBCs and collect consoles.
Because I wired relays to be normally closed. Relay Off == power on, Relay On == power off. My shell library functions reflect that use case.
- Be sure to enable your i2c bus in
armbian-config
and reboot - install
i2c-utils
package - Figure out your address of the io expander.. default is 0x38. See resources below on how to confirm with i2cdetect, etc
My gpio breakout board showed up as gpio504
this means the gpio pin names are gpio504-gpio511
I added folllowing lines into my /etc/rc.local
script to load kernel module and load driver for i2c and expander
modprobe gpio-pcf857x
echo pcf8574 0x38 > sys/bus/i2c/devices/i2c-0/new_device
requires running as root....
source lib/gpio.sh
demo
source lib/gpio.sh
gpio_init
gpio_show_all
gpio_set 505 value 1
gpio_show_all
sleep 1s
gpio_bounce 506
gpio_bounce 507
gpio_show_all
gpio_unexport_all
Running on Orange Pi PC; with 2 LEDs on gpio 12 and 13
sudo python3 lib/api.py -c /dev/gpiochip0 -l 12 13
Then, on the same device
curl localhost:5000/on
curl localhost:5000/off
Or form an other device on the same network
curl orangepipc.local:5000/12/toggle
curl orangepipc.local:5000/13/bounce
curl orangepipc.local:5000/toggle
curl -s orangepipc.local:5000/state | jq
{
"12": {
"active": "high",
"direction": "output",
"value": 0
},
"13": {
"active": "high",
"direction": "output",
"value": 1
}
}
curl orangepipc.local:5000/13/toggle
curl -s orangepipc.local:5000/13/state | jq
{
"active": "high",
"direction": "output",
"value": 0
}
routes /gpio-num/# impacts a single gpio while /# impacts all configured lines