Examples of using GPIO as input and output on OpenWrt. http://bit.ly/1qcNREa
To make the experience fit your profile, pick a username and tell us what interests you.
We found and based on your interests.
To conect 5V sensors that are intended for use with Arduino you need 5V, GND and a voltage divider
to get a signal in 3.3V range instead of 5V, Just to be on the safe
side I connected a 1K resistor between the voltage devider and the
sensor to limit the current passing trough the GPIO.
Next connect the 5V to the VCC on the sensor, ground to sensor GND and
voltage devider GND, Signal output from the sensor to the voltage
devider input and the voltage devider output to the current limiting
ressistor and then to GPIO.
To be safe you can use a multimeter to mesure voltage before connecting the 3,3V signal to the GPIO pin.
OpenWrt setup
I use GPIO 29 so for input the setup looks like this:
/etc/rc.local:
# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
echo “29″ > /sys/class/gpio/export;
echo “in” > /sys/class/gpio/gpio29/direction
exit 0
And you can get the state of the pin with:
cat /sys/class/gpio/gpio29/value
And this is what you get:
(some sensors send inverted values, its up to you to use what you need)
root@OpenWrt:~# cat /sys/class/gpio/gpio29/value
1
root@OpenWrt:~# cat /sys/class/gpio/gpio29/value
0
root@OpenWrt:~# cat /sys/class/gpio/gpio29/value
1
Output:
And /etc/rc.local for output
# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
echo “29″ > /sys/class/gpio/export;
echo “out” > /sys/class/gpio/gpio29/direction
exit 0
And than you can control the output with 1 or 0:
echo “1″ > /sys/class/gpio/gpio29/value
Create an account to leave a comment. Already have an account? Log In.
Become a member to follow this project and never miss any updates