GPIO PULL-UP with BBIO not Working

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
stumpja
 
Posts: 12
Joined: Mon Jun 22, 2015 12:27 pm

GPIO PULL-UP with BBIO not Working

Post by stumpja »

I am admittedly new to the BBB and python scripting, but I've made some progress today. However, I have come to my first hard stop.

I'm trying to set up a couple inputs to have pull-ups enabled, but this seems to spit out the following error:

Code: Select all

debian@beaglebone:/home/Python_Files$ sudo python fanTest.py
Traceback (most recent call last):
  File "fanTest.py", line 11, in <module>
    GPIO.setup(DISP_DOWN,GPIO.IN,pull_up_down=GPIO.PUD_UP)
ValueError: Set gpio mode failed, missing file or invalid permissions.
I have googled the error, and there are lots of suggestions, like old bootloader, and update library, all of which I think I have done. Many ask for the user to check the following.

Code: Select all

sudo /opt/scripts/tools/version.sh
and

Code: Select all

dmesg | grep bone
For completeness, I have done this as well. The results are as follows:

Code: Select all

debian@beaglebone:/$ sudo /opt/scripts/tools/version.sh
git:/opt/scripts/:[bcfc0750f1851ba2d2809b3fdaa13ccea688f25e]
eeprom:[A335BNLT00C02818BBBK0B50]
model:[TI_AM335x_BeagleBone_Black]
dogtag:[BeagleBoard.org Debian Image 2018-10-07]
bootloader:[eMMC-(default)]:[/dev/mmcblk1]:[U-Boot 2018.09-00002-g0b54a51eee]:[location: dd MBR]
kernel:[4.14.71-ti-r80]
nodejs:[v6.14.4]
uboot_overlay_options:[enable_uboot_overlays=1]
uboot_overlay_options:[uboot_overlay_pru=/lib/firmware/AM335X-PRU-RPROC-4-14-TI-00A0.dtbo]
uboot_overlay_options:[enable_uboot_cape_universal=1]
pkg check: to individually upgrade run: [sudo apt install --only-upgrade <pkg>]
pkg:[bb-cape-overlays]:[4.4.20180928.0-0rcnee0~stretch+20180928]
pkg:[bb-wl18xx-firmware]:[1.20180517-0rcnee0~stretch+20180517]
pkg:[kmod]:[23-2rcnee1~stretch+20171005]
pkg:[librobotcontrol]:[1.0.3-git20181005.0-0rcnee0~stretch+20181005]
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 coherent_pool=1M net.ifnames=0 quiet]
dmesg | grep pinctrl-single
[    1.102871] pinctrl-single 44e10800.pinmux: 142 pins at pa f9e10800 size 568
dmesg | grep gpio-of-helper
[    1.114701] gpio-of-helper ocp:cape-universal: ready
END

Code: Select all

debian@beaglebone:/home/Python_Files$ dmesg | grep bone
[    0.000000] Kernel command line: console=ttyO0,115200n8 bone_capemgr.uboot_capemgr_enabled=1 root=/dev/mmcblk1p1 ro rootfstype=ext4 rootwait coherent_pool=1M net.ifnames=0 quiet
[   26.896995] systemd[1]: Set hostname to <beaglebone>.
debian@beaglebone:/home/Python_Files$
The code I am executing is as follows. I know I am likely doing something wrong with the wait_for_edge stuff, but I haven't made it far enough along to really debug.

Code: Select all

import Adafruit_BBIO.GPIO as GPIO
import Adafruit_BBIO.PWM as PWM
from time import sleep
DISP_UP="P9_42"
DISP_DOWN="P9_25"
DISP_LEFT="P8_26"
DISP_RIGHT="P9_41"
DISP_ENTER="P9_27"
FAN_DRV="P8_19"
GPIO.setup(DISP_UP,GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.setup(DISP_DOWN,GPIO.IN,pull_up_down=GPIO.PUD_UP)
PWM.start(FAN_DRV,0,25000)
while(1):
	if GPIO.wait_for_edge(DISP_UP,GPIO.FALLING):
		PWM.set_duty_cycle(FAN_DRV,35)
	if GPIO.wait_for_edge(DISP_DOWN,GPIO.FALLING):
		PWM.set_duty_cycle(FAN_DRV,0)
	if GPIO.wait_for_edge(DISP_UP,GPIO.FALLING) and GPIO.wait_for_edge(DISP_DOWN,GPIO.FALLING):
		break
	sleep(0.2)
GPIO.cleanup()
PWM.stop(FAN_DRV)
PWM.cleanup()
Clearly I'm doing something stupid. Any ideas?

Thanks!

User avatar
stumpja
 
Posts: 12
Joined: Mon Jun 22, 2015 12:27 pm

Re: GPIO PULL-UP with BBIO not Working

Post by stumpja »

UPDATE:

So made it farther. I can use all my buttons, just now my down button which is connected to "P9_25". Is there something about this pin that doesn't like the GPIO calls and can it be fixed?

I found the config-pin command line call, and tried to configure this pin as gpio but error message occurred. I think I found the issue, I just don't know how to fix it.

Code: Select all

debian@beaglebone:/home/Python_Files$ config-pin P9.25 gpio
P9_25 pinmux file not found!
bash: /sys/devices/platform/ocp/ocp*P9_25_pinmux/state: No such file or directory
Cannot write pinmux file: /sys/devices/platform/ocp/ocp*P9_25_pinmux/state
debian@beaglebone:/home/Python_Files$
Latest code:

Code: Select all

import Adafruit_BBIO.GPIO as GPIO
import Adafruit_BBIO.PWM as PWM
from time import sleep
from threading import Timer

DISP_UP="P9_42"
DISP_DOWN="P9_25"
DISP_LEFT="P8_26"
DISP_RIGHT="P9_41"
DISP_ENTER="P9_27"
FAN_DRV="P8_19"

GPIO.setup(DISP_UP,GPIO.IN,GPIO.PUD_UP)
GPIO.setup(DISP_ENTER,GPIO.IN,GPIO.PUD_UP)
GPIO.setup(DISP_LEFT,GPIO.IN,GPIO.PUD_UP)
GPIO.setup(DISP_RIGHT,GPIO.IN,GPIO.PUD_UP)
PWM.start(FAN_DRV,0,25000)

def debounce(wait):
    """ Decorator that will postpone a functions
        execution until after wait seconds
        have elapsed since the last time it was invoked. """
    def decorator(fn):
        def debounced(*args, **kwargs):
            def call_it():
                fn(*args, **kwargs)
            try:
                debounced.t.cancel()
            except(AttributeError):
                pass
            debounced.t = Timer(wait, call_it)
            #TODO: does this spawn too many threads on repeated calls and t.can$
            debounced.t.start()
        return debounced
    return decorator

@debounce(0.1) #debounce to call event only after stable for 0.1s
def gpioEventDebounce(gpio):
    """gpioEventDebounce is a wrapper around gpioEvent which fires after a rese$
    the debounce decorator sets the delay time in seconds"""
    print('event on',gpio)

GPIO.add_event_detect(DISP_UP,GPIO.FALLING,gpioEventDebounce)
GPIO.add_event_detect(DISP_ENTER,GPIO.FALLING,gpioEventDebounce)
GPIO.add_event_detect(DISP_LEFT,GPIO.FALLING,gpioEventDebounce)
GPIO.add_event_detect(DISP_RIGHT,GPIO.FALLING,gpioEventDebounce)

while(1):
        if GPIO.event_detected(DISP_UP):
                PWM.set_duty_cycle(FAN_DRV,35)
        if GPIO.event_detected(DISP_ENTER):
                PWM.set_duty_cycle(FAN_DRV,0)
        if GPIO.event_detected(DISP_LEFT):
                break
        if GPIO.event_detected(DISP_RIGHT):
                break
        sleep(0.2)
sleep(0.25)
GPIO.cleanup()
PWM.stop(FAN_DRV)
PWM.cleanup()

User avatar
drewfustini
 
Posts: 944
Joined: Sat Dec 26, 2015 1:19 pm

Re: GPIO PULL-UP with BBIO not Working

Post by drewfustini »

I can reproduce this as well:

Code: Select all

debian@beaglebone:~$ sudo strace -o /tmp/strace python ./test.py
Traceback (most recent call last):
  File "./test.py", line 5, in <module>
    GPIO.setup(DISP_DOWN,GPIO.IN,pull_up_down=GPIO.PUD_UP)
ValueError: Set gpio mode failed, missing file or invalid permissions.
With strace, I can see that:

Code: Select all

3062  open("/sys/devices/platform/ocp/ocp:P9_25_pinmux/state", O_WRONLY|O_CREAT|O_TRUNC, 0666) = -1 ENOENT (No such file or directory)
This pin should be available as GPIO. I will followup with Robert Nelson who creates the BeagleBoard.org Debian images and kernel builds, and I will see what insights he may have. I suspect something will need to be changed in /boot/uEnv.txt so that this pin can be controlled by config-pin.

User avatar
stumpja
 
Posts: 12
Joined: Mon Jun 22, 2015 12:27 pm

Re: GPIO PULL-UP with BBIO not Working

Post by stumpja »

drewfustini wrote:
This pin should be available as GPIO. I will followup with Robert Nelson who creates the BeagleBoard.org Debian images and kernel builds, and I will see what insights he may have. I suspect something will need to be changed in /boot/uEnv.txt so that this pin can be controlled by config-pin.
drewfustini Looks like you are the adafruit beaglebone expert, and an extremely helpful one at that.

The answer to the latest issue in this thread can be found in another thread, which links another thread. :) That was fun.

Basically, in order for myself to set P9_25 as an input, I had to edit /boot/uEnv.txt, as you surmised. Uncommenting the following line did the trick.

Code: Select all

disable_uboot_overlay_audio=1
So that worked, but it worked for several pins. In the original thread this solution was to fix P9_28. If Robert can shed more light on this, or point to a place that can, I would be very interested.

Thanks again for all your help!

User avatar
drewfustini
 
Posts: 944
Joined: Sat Dec 26, 2015 1:19 pm

Re: GPIO PULL-UP with BBIO not Working

Post by drewfustini »

Robert informs me that P9_25 is mcasp0_ahclkx which is used by HDMI Audio. Thus, disabling audio should be enough to allow it to be used as GPIO.

Locked
Please be positive and constructive with your questions and comments.

Return to “Beagle Bone & Adafruit Beagle Bone products”