I am having trouble doing the tutorial for switches and libgpio.
Manually, I am using a toggle switch and need to set the input via gpioctl in one line.
gpioctl -c 31 IN
gpioctl -c 31 PU
Does not work, Must be one line like so:
gpioctl -c 31 IN PU
No problem at all. Now I am coming to learn C library libgpio and I am trying to do the same.
Set the toggle button pin 31 to both IN and PU.
My problem is the tutorial only sets the pin with libgpio function input:
gpio_pin_input(handle, button_pin);
I can trigger the LED with one toggle of the switch, beyond that it does not detect any input(due to missing PU resistor)
When I add the following for pullup it seems the entire input fails according to
gpio 31 is blank. It is not set to either IN or OUT. Prior to running my app it is set to Pin31 IN PU by default.
So how do I combine these two functions? gpio_pin_input and gpio_pin_pullup
It seems there is something I missed. This should be common.
The same for the output side. How to set OUT PU with libgpio?
If I manually adjust the pins from another shell with my program running then the switch and LED works fine.
gpioctl -c 31 IN PU
Blinking Lights With GPIO
In my last post we looked at a basic query of the GPIO bus just to show that we could read it. This time I want to actually control something. Blinking a light is the IoT equivalent of Hello World, so we’ll try that. In this setup, the anode (short lead) of the LED is connected to pin 19 by a...
claydowling.com
Manually, I am using a toggle switch and need to set the input via gpioctl in one line.
gpioctl -c 31 IN
gpioctl -c 31 PU
Does not work, Must be one line like so:
gpioctl -c 31 IN PU
No problem at all. Now I am coming to learn C library libgpio and I am trying to do the same.
Set the toggle button pin 31 to both IN and PU.
My problem is the tutorial only sets the pin with libgpio function input:
gpio_pin_input(handle, button_pin);
I can trigger the LED with one toggle of the switch, beyond that it does not detect any input(due to missing PU resistor)
When I add the following for pullup it seems the entire input fails according to
gpioctl -l
where the IN mode never gets set or PU.gpio 31 is blank. It is not set to either IN or OUT. Prior to running my app it is set to Pin31 IN PU by default.
Code:
gpio_pin_input(handle, button_pin);
gpio_pin_pullup(handle, button_pin);/*My ADDED line*/
gpio_pin_output(handle, led_pin);
gpio_pin_low(handle, led_pin);
gpio_pin_low(handle, button_pin);
It seems there is something I missed. This should be common.
The same for the output side. How to set OUT PU with libgpio?
If I manually adjust the pins from another shell with my program running then the switch and LED works fine.
gpioctl -c 31 IN PU
Last edited: