Adafruit BBIO: GPIO input error : Set gpio mode failed, missing file or invalid permissions

Hello,
I have problems with reading GPIO stat with Adafruit BBIO, here is the error:
root@beaglebone:/home/debian# python3 comRev4.py
Connecting… /dev/ttyUSB0
main thread started
Traceback (most recent call last):
File “comRev4.py”, line 44, in
GPIO.setup(di0, GPIO.IN)
ValueError: Set gpio mode failed, missing file or invalid permissions.

Output of sudo /opt/scripts/tools/version.sh
git:/opt/scripts/:[b39ec679648a6be8f25f48bd1c9784c1fc5a0c46]
eeprom:[A335BNLTEIA02103SBI12788]
model:[TI_AM335x_BeagleBone_Black]
dogtag:[BeagleBoard.org Debian Buster IoT Image 2020-04-06]
bootloader:[eMMC-(default)]:[/dev/mmcblk1]:[U-Boot 2019.04-00002-g31a8ae0206]:[location: dd MBR]
UBOOT: Booted Device-Tree:[am335x-boneblack-uboot-univ.dts]
UBOOT: Loaded Overlay:[AM335X-PRU-RPROC-4-19-TI-00A0]
UBOOT: Loaded Overlay:[BB-ADC-00A0]
UBOOT: Loaded Overlay:[BB-BONE-eMMC1-01-00A0]
UBOOT: Loaded Overlay:[BB-HDMI-TDA998x-00A0]
kernel:[4.19.94-ti-r42]
nodejs:[v10.15.2]
/boot/uEnv.txt Settings:
uboot_overlay_options:[enable_uboot_overlays=1]
uboot_overlay_options:[uboot_overlay_pru=/lib/firmware/AM335X-PRU-RPROC-4-19-TI-00A0.dtbo]
uboot_overlay_options:[enable_uboot_cape_universal=1]
pkg check: to individually upgrade run: [sudo apt install --only-upgrade ]
pkg:[bb-cape-overlays]:[4.14.20200403.0-0rcnee0~buster+20200403]
pkg:[bb-wl18xx-firmware]:[1.20200322.0-0rcnee0~buster+20200322]
pkg:[kmod]:[26-1]
pkg:[librobotcontrol]:[1.0.4-git20190227.1-0rcnee0~buster+20190327]
pkg:[firmware-ti-connectivity]:[20190717-2rcnee1~buster+20200305]
groups:[debian : debian adm kmem dialout cdrom floppy audio dip video plugdev users systemd-journal bluetooth netdev i2c gpio pwm eqep remoteproc admin spi iio docker tisdk weston-launch xenomai cloud9ide]
cmdline:[console=ttyO0,115200n8 bone_capemgr.uboot_capemgr_enabled=1 root=/dev/mmcblk1p1 ro rootfstype=ext4 rootwait coherent_pool=1M net.ifnames=0 lpj=1990656 rng_core.default_quality=100 quiet]
dmesg | grep remote
[ 55.938370] remoteproc remoteproc0: wkup_m3 is available
[ 56.036447] remoteproc remoteproc0: powering up wkup_m3
[ 56.036480] remoteproc remoteproc0: Booting fw image am335x-pm-firmware.elf, size 217168
[ 56.036771] remoteproc remoteproc0: remote processor wkup_m3 is now up
[ 58.419640] remoteproc remoteproc1: 4a334000.pru is available
[ 58.437995] remoteproc remoteproc2: 4a338000.pru is available
dmesg | grep pru
[ 58.419640] remoteproc remoteproc1: 4a334000.pru is available
[ 58.419776] pru-rproc 4a334000.pru: PRU rproc node pru@4a334000 probed successfully
[ 58.437995] remoteproc remoteproc2: 4a338000.pru is available
[ 58.438168] pru-rproc 4a338000.pru: PRU rproc node pru@4a338000 probed successfully
dmesg | grep pinctrl-single
[ 0.921873] pinctrl-single 44e10800.pinmux: 142 pins, size 568
dmesg | grep gpio-of-helper
[ 0.935074] gpio-of-helper ocp:cape-universal: ready
lsusb
Bus 001 Device 002: ID 0403:6001 Future Technology Devices International, Ltd FT232 Serial (UART) IC
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
END

Can you please advise what I’m doing wrong and how to fix it?

I am using the Adafruit library on a BBB, although with a slightly older kernel.

I would check permissions first, given the error message.

from console do

ls -l /sys/class/gpio

make a note of the file group owner for export (4th column)

On my board /sys/class/gpio/export is owned by root/gpio

then as the debian user type

groups

make sure the group from the first command is included in the output of the second.

If it isn’t you can add the group by doing (as root or using sudo)

usermod -a -G ‘missing group name’ debian

If debian is already a member of the group, after booting but before running your code, it would also be worth checking /sys/class/gpio/ to see if something else has grabbed the I/O pin already. That will also cause your program to fail.

Hi Benedict

I’m trying to install the Adafruit_BBIO library on the am335x-debian-11.5-minimal-armhf-2022-11-01-2gb.img.xz image on my BeagleBone Green. I had already quite a hard time getting the image to the emmc but now I get errors installing the library following the instructions on:

It states Adafruit_BBIO supports Linux kernels 3.8 through 4.19 … I’m on 5.10.140-ti-r52 :confused:

Which version do you use?

Can I simply downgrade the kernel or do I have to install an older image?

Did you try the Adafruit_Blinka library on the BBB/BBG?

Regards,
techanic

Just downgrade to 4.19.x-ti [ARMHF] Debian 10.x/11.x/12.x Kernel Updates

that project needs a maintainer…

Regards,

Thanks for the quick reply @RobertCNelson

Unfortunately the downgrade did not solve the problem. A few hours of trial & error later I figured out that the root cause for the error during the installation is due to python version api deprications.

Adafruit BBIO is built/tested with python 3.7 but uses the function PyEval_ThreadsInitialized which was deprecated in version 3.9:

When I interprete the docs correctly, this call is not really required since it should have been dealt with already…
So I modified the source code of the Adafruit BBIO (py_gpio.c) and installed manually, which still raised some warnings, but no errors!

Search for PyEval_ThreadsInitialized() and add the following directives on the line before:

#if PY_VERSION_HEX >= 0x03070000 && !defined(PyEval_ThreadsInitialized)
#define PyEval_ThreadsInitialized() 1
#endif

Found this solution via

It might not be the best solution, but it seems to work. I’ll open an issue for this, maybe someone with more experience can do it properly and create a pull-request.

Hope this helps somebody else faceing this issue.

Regards,
techanic

Update

  • Added link to adafruit-beaglebone-io-python issues
1 Like