Le Potato - how to read the GPIO pin state?

I’m trying to control a simple relay and get it’s status.
I’m using a fresh install of the latest 2022-09-22 raspbian.
I tried “sudo lgpio get 38” and “gpioget gpiochip1 82” commands I saw somewhere in the forum, but I guess they do not really work in this case.
Is there a workaround or am I doing something wrong?
Thank you!

Are you trying to read a state you set or trying to get the voltage of the relay? The get command reads the voltage of the GPIO digitally as 0 for 0V or 1 for 3.3V. If you are trying to control the relay, you use set.

I’m trying to read the state I set. I can control the relay using the “gpioset gpiochip1 82=0” or “sudo lgpio set 38=1” commands, but the get commands always return 1, even after the pin was set to 0.

You misunderstand GPIO get and set. Get turns the GPIO into Hi Z mode and reads the voltage level. Set turns the GPIO into push mode where it either pushes the voltage to 3.3V or 0V. You don’t read back the voltage you set with get. You need to track your last state.

So there is no way to read the GPIO pin state, if I’m using it in a push mode? Only tracking the last change?
"raspi-gpio get " is doing exactly what I need on the RPi, is there maybe an alternative on the Le Potato or perhaps a python command instead ? :slight_smile:

For anyone interested, I found a simple workaround, thanks to @librecomputer reply:
Connect the relay to 2 pins, e.g pin 82 & 84.
Control the relay using “gpioset gpiochip1 82=0”
Read the relay (or pin 82) status using “gpioget gpiochip1 84”

GPIOs are suppose to work fast. The pinctrl subsystem doesn’t have a reverse function to read back the state of pinctrl. You need to keep track of the last set state if that matters to you. Alternatively, you can set it again.

Raspberry Pi’s “ecosystem” is close a giant hack of proprietary and incorrectly engineered libraries. They break between versions and people spend a ton of effort re-engineering it. We don’t have that kind of bandwidth to waste.