Path: ...!feeds.phibee-telecom.net!3.eu.feeder.erje.net!feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: =?UTF-8?Q?Josef_M=C3=B6llers?= Newsgroups: comp.sys.raspberry-pi Subject: how to write and read back GPIO pin states with lgpio Date: Sun, 4 Aug 2024 22:13:55 +0200 Lines: 51 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net 7lxu0EKvY1Xmpvs7Cy6x+w525/yMR1zLPziGjJb5xjsMoPUqsD Cancel-Lock: sha1:Ols7CzKPbmqLTltXME47MnnJzP0= sha256:I4ik89nGDwHfcPcl5v4L8UguWaFk8rYfkDb5NBDcbo4= User-Agent: Mozilla Thunderbird Content-Language: en-US Bytes: 2615 Hi, 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. However, I have problems writing and reading back pin states from different programs. My setup is as follows: I have a couple of relays (solid state and mechanical ones) that control various external devices. I use one program to switch devices on and off and want to use another program to read back the state of the device. Doing that with sysfs is easy: 1) export the pin: echo $pin > /sys/class/gpio/export echo $direction > /sys/class/gpio/gpio$pin/direction this needs to be done only once. 2) write the state of the pin, thus switching the device on/off: echo $newstate > /sys/class/gpio/gpio$pin/value this is done every time this is required 3) read back the state of the pin value=$(