This chip is inter alia integrated into UniPi and functioning properly.
Script filename: i2csetrelay
Use it as follows:
script: // i2csetrelay A BB C D
A = bus
BB = module address
C = Relay
D = 1 (on) or 0 (off)
Example relay 1 on
script: // i2csetrelay 1 20 1 1
Example relay 1 off
script: // i2csetrelay 1 20 1 0
Code: Select all
#!/bin/sh
READ_HEX=$(i2cget -y $1 0x$2 0x09 | cut -c 3-4 | tr '[:lower:]' '[:upper:]')
READ_BIN=$(printf "%08d" $(echo "obase=2; ibase=16; $READ_HEX" | bc))
CHANGE_BIN=$(echo $READ_BIN | sed s/./$4/$3)
CHANGE_HEX=$(echo "obase=16; ibase=2; $CHANGE_BIN" | bc)
i2cset -y 1 0x20 0x00 0x00
i2cset -y $1 0x$2 0x09 0x$CHANGE_HEX