Problem to configurate the GPIO as inputs in the Beaglebone black

Hello

I have been trying to configurate the GPIO’s as inputs , using this code ( I just show the main section).

import Adafruit_BBIO.GPIO as GPIO.
DOOR= "P9_15"
GPIO.setup(DOOR, GPIO.IN)
print ( “test”)

However, I get an error message.

Traceback (most recent call last):
File “/var/lib/cloud9/examples/alarm.py”, line 4, in
GPIO.setup(DOOR, GPIO.IN)
ValueError: Set gpio mode failed, missing file or invalid permissions.

When I configurate the GPIO’s as outputs, I have not problem.

I believe that probably I will need update the libraries of Adafruit( I don’t sure)

Can someone please help me to find how solve this issue?

I have reading the Adafruit libraries in Python and I believe that is possible for me to write the program to my application. I require to use the digital and analog inputs and outputs , send emails, and probably to use the LCD display.

Thanks in advance

Hugo

On Fri, 5 Oct 2018 12:18:39 -0700 (PDT),
hcasalncasal1963@gmail.com declaimed the
following:

Hello

I have been trying to configurate the GPIO’s as inputs , using this code (
I just show the main section).

*import Adafruit_BBIO.GPIO as GPIO.*
*DOOR= "P9_15" *
*GPIO.setup(DOOR, GPIO.IN)*
*print ( “test”)*

However, I get an error message.

*Traceback (most recent call last):*
*File "/var/lib/cloud9/examples/alarm.py", line 4, in <module>*
*GPIO.setup(DOOR, GPIO.IN)*
*ValueError: Set gpio mode failed, missing file or invalid permissions.*

  Please cut&paste the actual code and traceback... since line 4 of the
posted code is the print statement...

  Also, you seem to have a period at the end of the import statement, and
that shouldn't be there.

  What release of the OS are you using?

  From an interactive (SSH via PuTTY) session (NOT using cloud9):

Using username "debian".
debian@beaglebone's password:

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Fri Sep 14 11:44:20 2018 from fe80::c932:bd85:577:9922%eth0
debian@beaglebone:~$ uname -a
Linux beaglebone 4.14.49-ti-r54 #1 SMP PREEMPT Fri Jun 15 22:14:13 UTC 2018
armv7l GNU/Linux
debian@beaglebone:~$ python3
Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170118] on linux
Type "help", "copyright", "credits" or "license" for more information.

import Adafruit_BBIO.GPIO as GPIO
DOOR = "P9_15"
GPIO.setup(DOOR, GPIO.IN)
print("test")

test

  Also worked in Python 2.x

GPIO.cleanup()
exit

Use exit() or Ctrl-D (i.e. EOF) to exit

exit()

debian@beaglebone:~$ python
Python 2.7.13 (default, Nov 24 2017, 17:33:09)
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import Adafruit_BBIO.GPIO as GPIO
DOOR = "P9_15"
GPIO.setup(DOOR, GPIO.IN)
print "test"

test

debian@beaglebone:~$

When I configurate the GPIO’s as outputs, I have not problem.

  Perhaps because that is the default direction? (I don't recall the
defaults)

Hello

Thank for your response

Bellow can you find a print screen with the information you ask me. I just write a short code to show the error . I tried to write the line print (“test”) , but the program always generate an error message and is not possible write the line .

Regards

Hugo

image.png

On Sat, 6 Oct 2018 13:10:00 -0500, Hugo Casal
<hcasalncasal1963@gmail.com> declaimed the
following:

Bellow can you find a print screen with the information you ask me. I just

  Doesn't anyone cut&paste TEXT anymore... a console with less than 1K of
text takes near 50KB as a compressed image and the image is practically
illegible (and that's after saving it to my system and opening it in a
graphic editor -- I don't write code using paint programs).
.

write a short code to show the error . I tried to write the line print
("test") , but the program always generate an error message and is not
possible write the line .

  Based upon what I can read, you are apparently running the August 30
IoT cut-down image, and not the June LXQT full image.

  The next step I would suggest is to run using

sudo python

to see if the problem IS in the permissions. The last few images I've used
(all LXQT) include setting the regular debian user account into the gpio
group. Before the images did that, one had to use sudo to run the program
with root privileges. Possibly the IoT images don't have the gpio group
set.

  If it runs using sudo, try following the instructions in the first box
of https://adafruit-beaglebone-io-python.readthedocs.io/en/latest/GPIO.html
(Note that the description of .cleanup() implies the default state would
already be as an input).

  Lastly -- do you have some other card plugged into the BBB, which may
be corrupting the normal device tree and reserving pins for itself? Or are
you using some other device tree overlay?

debian@beaglebone:~$ config-pin -i p9.15
Pin name: P9_15
Function if no cape loaded: gpio
Function if cape loaded: default gpio gpio_pu gpio_pd gpio_input pwm
Function information: gpio1_16 default gpio1_16 gpio1_16 gpio1_16 gpio1_16
ehrpwm1_tripzone_input
Kernel GPIO id: 48
PRU GPIO id: 80

  Note that P9_15 is kernel ID 48

debian@beaglebone:~$ config-pin -l p9.15
default gpio gpio_pu gpio_pd gpio_input pwm
debian@beaglebone:~$ config-pin -q p9.15
P9_15 Mode: default Direction: in Value: 1
debian@beaglebone:~$

... and it IS already set as an input, and appears to float HIGH...

debian@beaglebone:~$ ls /sys/class/gpio
export gpio116 gpio15 gpio23 gpio30 gpio45 gpio49 gpio60 gpio67
gpiochip0 unexport
gpio112 gpio12 gpio2 gpio26 gpio31 gpio46 gpio5 gpio61 gpio68
gpiochip32
gpio114 gpio13 gpio20 gpio27 gpio4 gpio47 gpio50 gpio65 gpio69
gpiochip64
gpio115 gpio14 gpio22 gpio3 gpio44 gpio48 gpio51 gpio66 gpio7
gpiochip96
debian@beaglebone:~$

Please run and the share the output of:

sudo /opt/scripts/tools/version.sh

Regards,

Hello

I used sudo python command and the issue was solved.

Now, I can run the code line, GPIO.input (“P9_15”, GPIO.IN)

I am going to continue writing my script to my telemetry project.

I thank you very much for the help.

Hi all,
I tried sudo python and sudo python3 and it did not work.

Hi Robert,
I tried sudo/opt/scripts/tools/version.sh but it displayed “command not found”. Attached is the snapshot for your reference.

I have LCD, motorbridge capes and MAX3223E eval board (communicating through UART4) connected to my BBB. I tried updating bootloader and kernel, and it disabled SPI 2 and GPIO input is not working as well. Please comment on this issue. Your help is much appreciated.

Thanks and regards,
Krish.

Error.PNG

Hi all,
I tried sudo python and sudo python3 and it did not work.

Hi Robert,
I tried sudo/opt/scripts/tools/version.sh but it displayed “command not found”. Attached is the snapshot for your reference.

Then it’s probally an old image, that script allowed us to figure out all the important bits so we can pin point the problem… So without it, it’s mostly a guessing game…

There needs to be a space between sudo and /opt/scripts/tools/version.sh like this:
sudo /opt/scripts/tools/version.sh

Hi John,
Yes, there is a space between sudo and the command and you could see that in the attached snapshot…

Thanks and regards,
Krish