Quote:
Originally Posted by justwantin
Cheers
Code:
#!/bin/bash
##################################################################################
# /usr/local/bin/pi-stop.sh RM20140629
# monitor GPIO pin 17 (GPIO pin 11) for shutdown signal
##################################################################################
LED_GPIO_PIN="22" # This corresponds to GPIO header pin 15.
echo "$LED_GPIO_PIN" > /sys/class/gpio/export 2> /dev/null
echo "out" > /sys/class/gpio/gpio$LED_GPIO_PIN/direction
echo "1" > /sys/class/gpio/gpio$LED_GPIO_PIN/value
while [ true ]
do
if [ "$(cat /sys/class/gpio/gpio$LED_GPIO_PIN/value)" == '0' ]
then
shutdown -h now
fi
sleep 1
done
|
I had a better look at your code and I think you're doing something potentially harmfull to the output drivers on the pin:
You are setting the pin to output (which enables the gpio pin output diver circuitry), then setting the output status to high and lastly you bare reading the status which in theory should now be always high as log as you stay within the output driver's max current specification.
When you push the button you are shorting to ground, pushing the output circuitry beyond specification and forcing it to low.
Now the PI evidently has output over-current protection or you would have blown the output driver in other circumstances.
The correct way to do this would have been to set the gpio pin to input and enable internal pullup, if it is available else use an external pullup resistor (10K would probabbly work fine) connected to a logic level 1 compatible voltage.
Altough this may be safe on the PI it may damage permanently some other device without internal over-current protection.
You should correct your post or at least warn people that this may be unsafe on devices different form the PI.
Now on the Allwinner SOC's the pullup thing can be done via script.bin: here's the corresponding clear text fex section of my gpio pins setup:
Code:
[gpio_para]
gpio_used = 1
gpio_num = 12
gpio_pin_1 = port:PE00<1><1><default><default>
gpio_pin_2 = port:PE01<1><1><default><default>
gpio_pin_3 = port:PE02<1><1><default><default>
gpio_pin_4 = port:PE03<1><default><default><default>
gpio_pin_5 = port:PE04<1><default><default><default>
gpio_pin_6 = port:PE05<1><default><default><default>
gpio_pin_7 = port:PE06<1><default><default><default>
gpio_pin_8 = port:PE07<1><default><default><default>
gpio_pin_9 = port:PE08<1><default><default><default>
gpio_pin_10 = port:PE09<1><default><default><default>
gpio_pin_11 = port:PE10<1><default><default><default>
gpio_pin_12 = port:PE11<1><default><default><default>
The first 3 pins have an extra <1> which enables the internal pullup circuitry only if the pin is set to input. On the A13 those 3 pins are input only so I just export them via sys and that's it.
Although I've a PI I'm not sure myself if the PI's gpio pins have selectable/fixed pullup/down or if they are left floating when the pins are in input mode.