I am using Linux (kernel v5.8.17) on an embedded custom board and have a script doing some gpioget
and gpioset
operations with the libgpiod package.
Setting output pins with gpioset
works great, as does getting value of input pins with gpioget
. But when I need to know the current value of an output pin, using gpioget
changes the pin value, and the direction.
Here is an example:
gpioinfo | grep MB_AC_ON
line 230: "MB_AC_ON" unused output active-high
gpioset $(gpiofind "MB_AC_ON")=1
gpioget $(gpiofind "MB_AC_ON")
0
gpioinfo | grep MB_AC_ON
line 230: "MB_AC_ON" unused input active-high
Setting the pin to '1' works. But then checking the current value of that same pin using gpioget, the value changes to '0' and the direction is changed to input. Is it even possible to get the value of a gpio output using libgpiod?
When I checked the detail by
gpioset -h
there was a note: I think this is the answer to your question.Also if we look at the code (
gpioset
: ../libgpiod/tools/gpioset.c) in more detail. We can see that these code blocks below, which lead to the line getting default value (you cannot keep the value you set using bygpioset
).