2

I am trying to find out if a specific GPIO is set on OUT or IN
I need something similar to this php command exec ("gpio read ".$i, $val_array[$i], $return );
but instead of returning LOW or HIGH (0 or 1) in the case of wiringpi, i need it to return out or in. as a variable/

(real beginner here)
Is it possible?

3

pigpio offers a method to read the GPIO mode from C, Python, and the shell.

From the shell use pigs, e.g. pigs mg 4 will return the mode of GPIO 4 (assuming that the pigpio daemon is running (sudo pigpiod)).

The returned value is as follows.

Value     0     1      2    3    4    5    6    7
Mode    Input Output ALT5 ALT4 ALT0 ALT1 ALT2 ALT3
  • Thanks @joan, that seems pretty straightforward. Works well. Could i have a quick input on how to set the pigpiod to run on startup and reboot? (as i said, total beginner here) – krasatos May 4 '17 at 21:30
  • 1
    @krasatos sudo systemctl enable pigpiod will start the pigpio daemon at boot. – joan May 4 '17 at 21:39
  • Thanks a ton, works as a charm, you saved me a lot of time! – krasatos May 4 '17 at 21:40
  • Is there a way to use pigs with the wPi numbering instead of the bcm? Or do i have to translate the numbers? – krasatos May 4 '17 at 21:50
  • 1
    @krasatos No, pigpio only uses (Broadcom) GPIO numbers. – joan May 4 '17 at 22:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.