Re: how to write and read back GPIO pin states with lgpio

Liste des GroupesRevenir à cs raspberry-pi 
Sujet : Re: how to write and read back GPIO pin states with lgpio
De : josef (at) *nospam* invalid.invalid (Josef Möllers)
Groupes : comp.sys.raspberry-pi
Date : 08. Aug 2024, 11:35:28
Autres entêtes
Message-ID : <lhjlbgFt0mvU1@mid.individual.net>
References : 1 2
User-Agent : Mozilla Thunderbird
On 05.08.24 01:04, Computer Nerd Kev wrote:
Josef M?llers <josef@invalid.invalid> wrote:
I used to use the sysfs interface to the GPIO pins (/sys/class/gpio) but
I understand that is deprecated nowadays. So I tried to switch to lgpio
which looks OK.
 Personally I switched to using the "gpio" command that's one of the
example programs included with the bcm2835 library. If you're just
trying to build C programs to replace the /sys/class/gpio devices
in a shell script, it's an existing option. It does have some bugs
though.
 https://www.airspayce.com/mikem/bcm2835/
 See examples/gpio/gpio.c in the source code.
I'll have a look at that, thanks!

However, I have problems writing and reading back pin
states from different programs.
[snip]
However ... When I set the pin's state to "1", I still read back "0"!
>
What am I doing wrong? Thanks in advance for any pointers.
 At a GUESS, you're reading the input buffer instead of the output
buffer. In output mode the input is disabled and always reads zero
or is meaningless.
Well, the documentation (https://abyz.me.uk/lg/py_lgpio.html#gpio_read) says "This command will work for any claimed GPIO (even if a member of a group). For an output GPIO the value returned will be that last written to the GPIO."
So, I was thinking that that would happen.

Unfortunately I've forgotten whether this is the case with the Pi,
or at least where to look to confirm I'm not mis-remembering, so
check for yourself. But this is a common way for IO hardware to
work.
OK, that sounds logical ... at the hardware level. However, I read the documentation such that either it works eg like the ATMega port pins, where you can read back the state of an output pin, OR the kernel driver would keep a copy of the output state and return that upon a read  OR the library function would do that, but shame on me I have not checked the latter myself.
Thanks anyway,
Josef

Date Sujet#  Auteur
4 Aug 24 * how to write and read back GPIO pin states with lgpio4Josef Möllers
5 Aug 24 +* Re: how to write and read back GPIO pin states with lgpio2Computer Nerd Kev
8 Aug 24 i`- Re: how to write and read back GPIO pin states with lgpio1Josef Möllers
5 Aug 24 `- Re: how to write and read back GPIO pin states with lgpio1The Natural Philosopher

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal