PIAST スクリプト

2016年2月29日 (月) 00:14時点におけるTakahashi (トーク | 投稿記録)による版 (ページの作成:「(今のところ)俺メモ ===GPIO初期化=== *GPIO設定(gpioinit.sh) #!/bin/sh PINNS="4 6 13 19 26" GPIOPATH="/sys/class/gpio" for i in $PINNS do GPORT...」)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)

(今のところ)俺メモ

GPIO初期化

  • GPIO設定(gpioinit.sh)
#!/bin/sh

PINNS="4 6 13 19 26"
GPIOPATH="/sys/class/gpio"

for i in $PINNS
do
    GPORT=gpio$i

    if [ ! -d $GPIOPATH/$GPORT ]
    then
        echo $i > $GPIOPATH/export
        echo "out" > $GPIOPATH/$GPORT/direction
    fi
done
  • GPIO解放(gpiounconfig.sh)
#!/bin/sh

PINNS="4 6 13 19 26"
GPIOPATH="/sys/class/gpio"

for i in $PINNS
do
    GPORT=gpio$i
 
    if [ -d $GPIOPATH/$GPORT ]
    then
        echo $i > $GPIOPATH/unexport
    fi
done

リレー制御用

  • リレーオン(relayon.sh)
#!/bin/sh

PINNO=4
RELAYPORT=gpio$PINNO
GPIOPATH="/sys/class/gpio"

if [ ! -d $GPIOPATH/$RELAYPORT ]
then
    echo $PINNO > $GPIOPATH/export
    echo "out" > $GPIOPATH/$RELAYPORT/direction
fi

echo "1" > $GPIOPATH/$RELAYPORT/value
  • リレーオフ(relayoff.sh)
#!/bin/sh

PINNO=4
RELAYPORT=gpio$PINNO
GPIOPATH="/sys/class/gpio"

if [ ! -d $GPIOPATH/$RELAYPORT ]
then
    echo $PINNO > $GPIOPATH/export
    echo "out" > $GPIOPATH/$RELAYPORT/direction
fi

echo "0" > $GPIOPATH/$RELAYPORT/valu

LED制御

  • LED点灯(ledon.sh)
#!/bin/sh

PINNOS="6 13 19 26"
GPIOPATH="/sys/class/gpio"

PINNO=`echo $PINNOS | cut -f$1 -d' '`

if [ "$PINNO" = "" ]
then
    echo "Usage: ledon.sh [LED](1-4)"
    exit
fi

LEDPORT=gpio$PINNO

if [ ! -d $GPIOPATH/$LEDPORT ]
then
    echo $PINNO > $GPIOPATH/export
    echo "out" > $GPIOPATH/$LEDPORT/direction
fi

echo "1" > $GPIOPATH/$LEDPORT/value
  • LED消灯(ledoff.sh)
#!/bin/sh

PINNOS="6 13 19 26"
GPIOPATH="/sys/class/gpio"

PINNO=`echo $PINNOS | cut -f$1 -d' '`

if [ "$PINNO" = "" ]
then
    echo "Usage: ledon.sh [LED](1-4)"
    exit
fi

LEDPORT=gpio$PINNO

if [ ! -d $GPIOPATH/$LEDPORT ]
then
    echo $PINNO > $GPIOPATH/export
    echo "out" > $GPIOPATH/$LEDPORT/direction
fi

echo "0" > $GPIOPATH/$LEDPORT/value