home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.sys.raspberry-pi      Raspberry Pi computers & related hardwar      26,127 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 24,720 of 26,127   
   =?UTF-8?Q?Josef_M=C3=B6llers?= to All   
   how to write and read back GPIO pin stat   
   04 Aug 24 22:13:55   
   
   From: josef@invalid.invalid   
      
   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=$(

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca