Skip to content

Instantly share code, notes, and snippets.

@themactep
Last active March 4, 2023 17:54
Show Gist options
  • Save themactep/24adfe43d3d29f20eacb75294d9d4035 to your computer and use it in GitHub Desktop.
Save themactep/24adfe43d3d29f20eacb75294d9d4035 to your computer and use it in GitHub Desktop.
#!/bin/sh
# GPIO switcher
# Paul Philippov <[email protected]>
PIN=$1
MODE=$2
if [ -z "$PIN" ] || [ -z "$MODE" ]; then
echo "Usage: $0 <pin#> <1|0|x>"
exit 1
fi
if [ "x" = "$MODE" ]; then
if [ ! -d "/sys/class/gpio/gpio${PIN}" ]; then
echo "Pin ${PIN} is not exported."
exit 2
fi
echo $PIN > /sys/class/gpio/unexport
else
if [ ! -d "/sys/class/gpio/gpio${PIN}" ]; then
echo $PIN > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio${PIN}/direction
fi
echo $MODE > /sys/class/gpio/gpio${PIN}/value
fi
dmesg | tail -10
ls -l /sys/class/gpio/
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment