Skip to content

GPIO scripts and examples for linux, RPI alternatives using pcf8574 IO Expander

Notifications You must be signed in to change notification settings

lanefu/sbc-gpio-pcf857x

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

sbc-gpio-pcf857x

GPIO scripts and examples for linux / Armbian, RPI alternatives using i2c pcf8574 IO Expander found in cheap GPIO breakout boards.

background

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.

i2c and uart breakout hat my relay board for usb power

Getting Started

prerequisites

  • 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

initialize

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

example - bash

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

example - python

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

resources

About

GPIO scripts and examples for linux, RPI alternatives using pcf8574 IO Expander

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published