-
Notifications
You must be signed in to change notification settings - Fork 9
GPIO
We use BCM pad 18 for testing with a LED + serial resistor. Connect the LED cathode (shorer wire) to GND (J8 pin 14) and LED anode (longer wire) via a serial resistor for current limiting to J8 pin 12 which is routed to BCM pin 18.
Now, boot, login and from the command prompt on your running Pi:
Export (==make visible) GPIO pin 18:
echo 18 > /sys/class/gpio/export
Make pin 18 an output:
echo out > /sys/class/gpio/gpio18/direction
Set its value to 1 (high), the LED should switch on:
echo 1 > /sys/class/gpio/gpio18/value
Set its value to 0 (low), the LED should switch off:
echo 0 > /sys/class/gpio/gpio18/value
If you like bash hacking, let the LED blink from the console:
while [ true ] do echo 1 > /sys/class/gpio/gpio18/value sleep 1 echo 0 > /sys/class/gpio/gpio18/value sleep 1 done
Export must be done only once in the beginning when @/sys/class/gpio/gpio18/@ does not yet exists. Its good style to unexport the pin if no longer needed (which also switches the LED off):
echo 18 > /sys/class/gpio/unexport
This code can be one-to-one translated into C code using POSIX style file access functions. For a complete example see: http://www.netzmafia.de/skripten/hardware/RasPi/RasPi_GPIO_C.html