Controlling GPIO's
About
This short tutorial describes how to get GPIO working. For this you need tool called gpioctl
.
Building/installing
- Type
make menucongfig
- Under
Utilities
select packagegpioctl
and build carambola firmware (although you can do it directly on carambola typingopkg update; opkg install gpioctl
) - In latest OpenWrt revisions gpioctl become deprecated.
Testing
Prepare GPIO as output
gpioctl dirout 1; gpioctl dirout 2
Set both to 1
gpioctl set 1; gpioctl set 2
Clear both
gpioctl clear 1; gpioctl clear 2
Read status
gpioctl dirin 1; gpioctl dirin 2; gpioctl get 1; gpioctl get 2
Controlling gpio pins as files in /sys
Another method for controlling gpios using files instead of commands:
cd /sys/class/gpio echo 1 > export
this will make the virtual directory "gpio1" available in /sys/class/gpio/gpio1 inside "gpio1" you will find, among others:
- direction ("in" or "out")
- value (0 or 1)
Just write/read those file to do I/O. For example
echo out > direction echo 1 > value
will put the pin in output mode and high
echo in > direction cat value
will read the pin instead