Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPIO setup to in problems #206

Closed
Grincas opened this issue Nov 30, 2017 · 19 comments
Closed

GPIO setup to in problems #206

Grincas opened this issue Nov 30, 2017 · 19 comments
Assignees
Labels

Comments

@Grincas
Copy link

Grincas commented Nov 30, 2017

Hello i have a problem with GPIO. I cant set up on input mode. Get this error: ValueError: Set gpio mode failed, missing file or invalid permissions.

`import Adafruit_BBIO.GPIO as GPIO
import sys
import time

def main(argv):

Frequency = 10
# CS
GPIO.setup("P9_28", GPIO.OUT)
GPIO.output("P9_28", GPIO.HIGH)
# CLK
GPIO.setup("P9_31", GPIO.OUT)
# MOSI
GPIO.setup("P9_29", GPIO.OUT)
# MISO
GPIO.setup("P8_14",GPIO.IN)


count = 0
while (count < 9):
    if GPIO.input("P9_27"):
        break
    GPIO.output("P9_28", GPIO.LOW)
    time.sleep(5)

    GPIO.output("P9_28", GPIO.HIGH)
    time.sleep(5)

    count = count + 1

GPIO.output("P9_28", GPIO.HIGH)
print "Good bye!"

if name == "main":
main(sys.argv)
`

sudo /opt/scripts/tools/version.sh
git:/opt/scripts/:[2ce750d881941c5189db9e189af90517e11c079f]
eeprom:[A335BNLTEIA04816BBBK376B]
dogtag:[BeagleBoard.org Debian Image 2017-08-31]
bootloader:[eMMC-(default)]:[/dev/mmcblk1]:[U-Boot 2017.09-rc2-00002-g7c9353]
kernel:[4.4.84-ti-r120]
nodejs:[v6.11.2]
uboot_overlay_options:[enable_uboot_overlays=1]
uboot_overlay_options:[uboot_overlay_addr0=/lib/firmware/BB-UART1-00A0.dtbo]
uboot_overlay_options:[uboot_overlay_addr1=/lib/firmware/BB-UART2-00A0.dtbo]
uboot_overlay_options:[uboot_overlay_addr2=/lib/firmware/BB-UART4-00A0.dtbo]
uboot_overlay_options:[uboot_overlay_pru=/lib/firmware/AM335X-PRU-RPROC-4-4-TI-00A0.dtbo]
uboot_overlay_options:[enable_uboot_cape_universal=1]
pkg:[bb-cape-overlays]:[4.4.20170728.0-0rcnee1stretch+20170728]
pkg:[bb-wl18xx-firmware]:[1.20170829-0rcnee1
stretch+20170829]
pkg:[firmware-ti-connectivity]:[20170823-1rcnee0~stretch+20170830]

@pdp7 pdp7 self-assigned this Dec 1, 2017
@pdp7 pdp7 added the question label Dec 1, 2017
@pdp7
Copy link
Collaborator

pdp7 commented Dec 1, 2017

@Grincas Please try running your Python program as root using sudo.

Alternatively, you can run the Debian 9.2 "Stretch" iot (2017-10-29) image and install Linux kernel 4.14.x to enable non-root control of GPIO and PWM (commit)

@Grincas
Copy link
Author

Grincas commented Dec 1, 2017

I have tried to run as root get the same error , i look for a file in sys directory and i sow that pin have been changed to a input but get that error , so solution to downgrade from 4.4 to 4.1 ?

@Grincas
Copy link
Author

Grincas commented Dec 1, 2017

root@beaglebone:/# sudo python SPI_new.py
Traceback (most recent call last):
File "SPI_new.py", line 18, in main
GPIO.setup("P8_14",GPIO.IN)
ValueError: Set gpio mode failed, missing file or invalid permissions.

Out put is the same

@pdp7
Copy link
Collaborator

pdp7 commented Dec 1, 2017

Please upgrade to the 4.14.x kernel, reboot and try running the Python program again:

sudo apt-get update
sudo apt-get upgrade
cd /opt/scripts/tools/update_kernel.sh
git pull
sudo ./update_kernel.sh --lts-4_14

If you get the error message again, then please try running strace to see what /sys files it is trying to open:

sudo strace -e open python ./SPI_new.py 2>&1 | grep /sys/

If strace is not installed, then run:

sudo apt-get install strace

@pdp7
Copy link
Collaborator

pdp7 commented Dec 2, 2017

@Grincas Also, I noticed in your example code at the top of this issue that P9_27 is used as input but never setup:

    if GPIO.input("P9_27"):

There needs to be a call to GPIO.setup() first such as:

GPIO.setup("P9_27")

@rd-tyler
Copy link

Hi @pdp7 ,

Not to interject but I too am experiencing some issues and they are likely related to this issue as they are reporting similar errors to @Grincas .

When trying to run the prebuilt Adafruit_CharLCD example "char_lcd_rgb_pwm.py" as shown here from the Cloud9 IDE:
https://github.com/adafruit/Adafruit_Python_CharLCD/blob/master/examples/char_lcd_rgb_pwm.py

I get the following:

debian@beaglebone:~/Adafruit_Python_CharLCD/examples$ sudo ./char_lcd_rgb_pwm.py
Traceback (most recent call last):
  File "./char_lcd_rgb_pwm.py", line 71, in <module>
    enable_pwm=True)
  File "build/bdist.linux-armv7l/egg/Adafruit_CharLCD/Adafruit_CharLCD.py", line 367, in __init__
  File "build/bdist.linux-armv7l/egg/Adafruit_CharLCD/Adafruit_CharLCD.py", line 152, in __init__
  File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/GPIO.py", line 278, in setup
ValueError: Set gpio value failed, missing file or invalid permissions.

Same for if I attempt to execute using:

sudo python ./char_lcd_rgb_pwm.py

So, following your attempts at a repair I have attempted to update and upgrade everything, including the kernel as I'm currently using 4.4.91 as included in the latest image on the BBB main site.

When attempting to execute the update_kernel script I get the following:

debian@beaglebone:/opt/scripts/tools$ sudo ./update_kernel.sh --lts-4_14
info: checking archive
2018-01-23 23:47:42 URL:https://rcn-ee.com/repos/latest/stretch-armhf/LATEST-ti [136/136] -> "LATEST-ti" [1]
-----------------------------
Kernel Options:
ABI:1 LTS41 4.1.30-ti-r70
ABI:1 LTS44 4.4.110-ti-r143
ABI:1 LTS49 4.9.77-ti-r92
ABI:1 LTS414 4.14.14-ti-r27
-----------------------------
Kernel version options:
-----------------------------
LTS44: --lts-4_4
LTS49: --lts-4_9
LTS414: --lts-4_14
STABLE: --stable
TESTING: --testing
-----------------------------
info: you are running: [4.4.91-ti-r133], latest is: [4.14.14-ti-r27] updating...
Ign:1 http://deb.debian.org/debian stretch InRelease                          
Hit:2 http://repos.rcn-ee.com/debian stretch InRelease                        
Hit:3 http://deb.debian.org/debian stretch-updates InRelease
Hit:4 http://deb.debian.org/debian-security stretch/updates InRelease
Hit:5 http://deb.debian.org/debian stretch Release
Reading package lists... Done
Building dependency tree       
Reading state information... Done
1 package can be upgraded. Run 'apt list --upgradable' to see it.
Checking dpkg...
Checking apt-cache...
debug: installing: [linux-image-4.14.14-ti-r27]
E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem.

Blindly following the direction to execute

sudo dpkg --configure -a

just temporarily disconnects the beaglebone, resets it to the standard landing screen and doesn't actually resolve the issue as it persists and repeats the message. My initial attempts at finding a fix for that has yielded very little. Any insight you can offer would be greatly appreciated.

@RobertCNelson
Copy link
Contributor

RobertCNelson commented Jan 24, 2018

@rd-tyler please list what this shows:

sudo apt list --upgradable

Regards,

@rd-tyler
Copy link

rd-tyler commented Jan 24, 2018

Hi @RobertCNelson,

debian@beaglebone:~$ sudo apt list --upgradable
[sudo] password for debian:
Listing... Done
bb-node-red-installer/unknown 0.17.5-0rcnee5~stretch+20180120 armhf [upgradable from: 0.17.5-0rcnee0~stretch+20170816]
N: There is 1 additional version. Please use the '-a' switch to see it

@RobertCNelson
Copy link
Contributor

@rd-tyler that's strange:

try:

sudo apt remove bb-node-red-installer --purge
sudo apt update
sudo apt install bb-node-red-installer

Regards,

@rd-tyler
Copy link

rd-tyler commented Jan 24, 2018

@RobertCNelson The plot thickens:

debian@beaglebone:~$ sudo apt remove bb-node-red-installer --purge
E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem.

@StokesMIDE
Copy link

I was having GPIO trouble as originally described, and I updated the kernel to 4.14 as per the instructions here. Not only did it fail to fix the problem, it made the UART overlays unusable; the system won't boot if they're loaded via /boot/uEnv.txt, and attempting to load them manually produces a similar seg fault. I've updated/upgraded, tried rebuilding the overlays, but it hasn't helped.

I know this is getting beyond the scope of the original issue, but it was this issue that led me here, and I'm utterly stuck.

(BTW, I also had the thing with upgrading bb-node-red-installer, but removing and reinstalling it worked for me.)

@pdp7
Copy link
Collaborator

pdp7 commented Jan 26, 2018

@StokesMIDE Please create a new issue so we can troubleshoot your problem.

In that issue, please post complete the Python source code that you are trying to run. Use the "Insert code" button so that the whitespace is preserved.

Please also paste the output of these commands in that issue:

sudo /opt/scripts/tools/version.sh
cat /boot/uEnv.txt

If you are not already, I would recommend trying this image:
Debian 9.3 "Stretch" iot

@pdp7
Copy link
Collaborator

pdp7 commented Jan 26, 2018

@rd-tyler Please create a new issue so we can troubleshoot your problem with Adafruit_Python_CharLCD.

Please paste the output of these commands in that issue:

sudo /opt/scripts/tools/version.sh
cat /boot/uEnv.txt

If you are not already, I would recommend trying this image:
Debian 9.3 "Stretch" iot (2018-01-21)

@pdp7
Copy link
Collaborator

pdp7 commented Jan 26, 2018

@Grincas Are you still experiencing this issue?

I noticed in your example code at the top of this issue that P9_27 is used as input but never setup:

    if GPIO.input("P9_27"):

There needs to be a call to GPIO.setup() first such as:

GPIO.setup("P9_27")

If you get the error message again, then please try running strace to see what /sys files it is trying to open:

sudo strace -e open python ./SPI_new.py 2>&1 | grep /sys/

If strace is not installed, then run:

sudo apt-get install strace

Also, please paste the output of this command:

cat /boot/uEnv.txt

Finally, if you are able to, then I would recommend trying this image:
Debian 9.3 "Stretch" iot (2018-01-21)

@pdp7
Copy link
Collaborator

pdp7 commented Feb 2, 2018

@Grincas are you still having this problem?

@pdp7 pdp7 closed this as completed Feb 8, 2018
@pdp7 pdp7 reopened this Feb 8, 2018
@pdp7
Copy link
Collaborator

pdp7 commented Feb 8, 2018

@Grincas is it OK to close this issue?

@pdp7 pdp7 closed this as completed Feb 13, 2018
@gert-lauritsen
Copy link

Hi Im having the same problem
Short program
import Adafruit_BBIO.GPIO as GPIO
GPIO.setup("P9_23", GPIO.IN)

giving this
sudo strace -e open python ./testGPIO.py 2>&1 | grep /sys/
open("/sys/class/gpio/gpio49/direction", O_WRONLY) = 4
open("/sys/devices/platform/ocp/ocp:P9_23_pinmux/state", O_WRONLY|O_CREAT|O_TRUN C, 0666) = -1 ENOENT (No such file or directory)

the system is:
Linux beaglebone 4.14.25-ti-r38 #1 SMP Sat Mar 10 07:43:50 UTC 2018 armv7l GNU/Linux

@origtech
Copy link

Hi I'm having the same problem and have tried all the suggestions in this thread without any success.

Here is a sample of my test program:
#!/user/bin/python
import Adafruit_BBIO.GPIO as GPIO

GPIO.setup('P8_11', GPIO.IN)
if(GPIO.input('P8_11')):
print 'high'
else:
print 'low'

When I run the program I get this error message:
File "ioTest.py", line 4, in
GPIO.setup('P8_11', GPIO.IN)
ValueError: Set gpio mode failed, missing file or invalid permissions.

sudo /opt/scripts/tools/version.sh produces the following:

git:/opt/scripts/:[e307a944e0be0610ff5296e0abe4ad31a6e70daa]
eeprom:[A335BNLT000C1826BBBG0624]
model:[TI_AM335x_BeagleBone_Black]
dogtag:[BeagleBoard.org Debian Image 2018-03-05]
bootloader:[eMMC-(default)]:[/dev/mmcblk1]:[U-Boot 2018.01-00002-ge9ff418fb8]:[location: dd MBR]
kernel:[4.9.82-ti-r102]
nodejs:[v6.14.4]
uboot_overlay_options:[enable_uboot_overlays=1]
uboot_overlay_options:[enable_uboot_cape_universal=1]
pkg:[bb-cape-overlays]:[4.4.20180914.0-0rcnee0stretch+20180914]
pkg:[bb-wl18xx-firmware]:[1.20180517-0rcnee0
stretch+20180517]
pkg:[firmware-ti-connectivity]:[20170823-1rcnee1~stretch+20180328]
groups:[debian : debian adm kmem dialout cdrom floppy audio dip video plugdev users systemd-journal i2c bluetooth netdev cloud9ide gpio pwm eqep admin spi tisdk weston-launch xenomai]
cmdline:[console=ttyO0,115200n8 bone_capemgr.uboot_capemgr_enabled=1 root=/dev/mmcblk1p1 ro rootfstype=ext4 rootwait uboot_detected_capes=BB-BONE-4D7R-01, coherent_pool=1M net.ifnames=0 quiet]
dmesg | grep pinctrl-single
[ 1.344481] pinctrl-single 44e10800.pinmux: 142 pins at pa f9e10800 size 568
dmesg | grep gpio-of-helper
[ 1.345071] gpio-of-helper ocp:gpio_helper: ready
[ 1.345687] gpio-of-helper ocp:cape-universal: ready
END

cat /boot/uEnv.txt produces the following:
#Docs: http://elinux.org/Beagleboard:U-boot_partitioning_layout_2.0

uname_r=4.9.82-ti-r102
#uuid=
#dtb=

###U-Boot Overlays###
###Documentation: http://elinux.org/Beagleboard:BeagleBoneBlack_Debian#U-Boot_Overlays
###Master Enable
enable_uboot_overlays=1

###Overide capes with eeprom
#uboot_overlay_addr0=/lib/firmware/.dtbo
#uboot_overlay_addr1=/lib/firmware/.dtbo
#uboot_overlay_addr2=/lib/firmware/.dtbo
#uboot_overlay_addr3=/lib/firmware/.dtbo

###Additional custom capes
#uboot_overlay_addr4=/lib/firmware/.dtbo
#uboot_overlay_addr5=/lib/firmware/.dtbo
#uboot_overlay_addr6=/lib/firmware/.dtbo
#uboot_overlay_addr7=/lib/firmware/.dtbo

###Custom Cape
dtb_overlay=/lib/firmware/BBB-UMC-TESTER-00A0.dtbo

###Disable auto loading of virtual capes (emmc/video/wireless/adc)
#disable_uboot_overlay_emmc=1
#disable_uboot_overlay_video=1
#disable_uboot_overlay_audio=1
#disable_uboot_overlay_wireless=1
#disable_uboot_overlay_adc=1

###PRUSS OPTIONS
###pru_rproc (4.4.x-ti kernel)
#uboot_overlay_pru=/lib/firmware/AM335X-PRU-RPROC-4-4-TI-00A0.dtbo
###pru_uio (4.4.x-ti, 4.14.x-ti & mainline/bone kernel)
#uboot_overlay_pru=/lib/firmware/AM335X-PRU-UIO-00A0.dtbo

###Cape Universal Enable
enable_uboot_cape_universal=1

###Debug: disable uboot autoload of Cape
#disable_uboot_overlay_addr0=1
#disable_uboot_overlay_addr1=1
#disable_uboot_overlay_addr2=1
#disable_uboot_overlay_addr3=1

###U-Boot fdt tweaks... (60000 = 384KB)
#uboot_fdt_buffer=0x60000
###U-Boot Overlays###

cmdline=coherent_pool=1M net.ifnames=0 quiet

#In the event of edid real failures, uncomment this next line:
#cmdline=coherent_pool=1M net.ifnames=0 quiet video=HDMI-A-1:1024x768@60e

##enable Generic eMMC Flasher:
##make sure, these tools are installed: dosfstools rsync
#cmdline=init=/opt/scripts/tools/eMMC/init-eMMC-flasher-v3.sh

To try and correct the problem I have run:
sudo apt-get update
sudo apt-get upgrade

But the problem remains. I am running Debian Version 9.3 IoT Stretch.
Any suggestions on what to try?

@pdp7
Copy link
Collaborator

pdp7 commented Sep 20, 2018

@origtech please open a new issue so it is easier to keep track of the problem you experienced

@RobertCNelson is 2018.01 too old of u-boot version for u-boot device tree overlays to work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants