How to use GPIO Raspberry Pi 2
(Model B v1.1 2014)
based on Raspbian OS
Basic using GPIO with shell, example with led blink
J8 header connector on Raspberry Pi 2 Model B v1.1 2014
Connect Led between GPIO4 and GND with 1K resistor.
Make sure root to gpio access:
$ sudo su
Command line probe:
# echo "4" > /sys/class/gpio/export
# echo "out" > /sys/class/gpio/gpio4/direction
# echo "1" > /sys/class/gpio/gpio4/value
# echo "0" > /sys/class/gpio/gpio4/value
# echo "4" > /sys/class/gpio/unexport
Create file: "ledblink.sh" with contains:
#---------------------------------------------------------------------------------
# reserve resources export gpio_4
echo "4" > /sys/class/gpio/export
# make gpio_4 to ouput
echo "out" > /sys/class/gpio/gpio4/direction
# set gpio_4 value to logical '1'
echo "1" > /sys/class/gpio/gpio4/value
# wait 2 seconds
sleep 2s
# set gpio_4 value to logical '0'
echo "0" > /sys/class/gpio/gpio4/value
# wait 2 seconds
sleep 2s
# set gpio_4 value to logical '1'
echo "1" > /sys/class/gpio/gpio4/value
# wait 2 seconds
sleep 2s
# set gpio_4 value to logical '0'
echo "0" > /sys/class/gpio/gpio4/value
# wait 2 seconds
sleep 2s
# release reserved resources and unexport gpio_4
echo "4" > /sys/class/gpio/unexport
#---------------------------------------------------------------------------------
Save and close file.
Make file to executable:
chmod +x ledblink.sh
Execute shell script:
./ledblink.sh
Няма коментари:
Публикуване на коментар