ValueError: Set gpio mode failed, missing file or invalid permissions.

Hi,

We have custom kernel for Beaglebone black we’re trying to configure P8_10 as input pin and we are configuring TIMER6/PIN 68/P8_10 as gpio input in the kernel. But when we boot and try to write these two lines

import Adafruit_BBIO.GPIO as GPIO
GPIO.setup(“P8_10”, GPIO.IN)

we’re getting this error “ValueError: Set gpio mode failed, missing file or invalid permissions.”

Can you please let us know how to use input configured pin in the application to check the interrupt/events on that pin.

Thanks,
Anusha

Hello,

I used to use this library. Are you making it work still? You can probably learn some type of FD language for C/C++ or Python3. I think the lib, Adafruit_BBIO, has been replaced w/ FD or maybe not.

Who knows?

All I know is that Adafruit_BBIO used to be around in '18 but not so much these days, e.g. unless people are still managing to coerce it to work. There were some other libs. I found a long time ago too.

Did you use config-pin?

Seth

P.S. So, gpioinfo will tell you some ideas about what is input or output and what is available. config-pin on the other hand will allow you to mux those specific pins on the BBB for say, “GPIO, PWM, etc…”

Also…I saw gpiod in C works too. If you go to the BeagleBoard.org BeagleBone Relay Cape — BeagleBoard Documentation page online, people have many ideas circulating. I saw some w/ Python3 that only need time and os imported.

Hi,

Thanks for for your reply @silver2row,

I’m new to beaglebone so i just started using Adafruit_BBIO library on the example beaglebone black image and it is working fine. But if i try to use that on customized kernel image and configure it as input using Adafruit_BBIO library i’m getting that error.

is there any other specific library that we can use in python application to read the inputs and configure other peripherals like spi, i2c, pwm, etc.

In this BeagleBoard.org BeagleBone Relay Cape — BeagleBoard Documentation page we can see the outputs but i want to check input.

when i try to configure pins using “config-pin” it is giving “command not found”, how to install config-pin in linux. But even if we use “config-pin” we can configure it as GPIO, how to configure it as gpio input.

Thanks,
Anusha

For Python you can use SMBUS2 for I2C.

For SPI look for any Python library that supports spidev and it should work.

Not used Python for pwms but a quick Google finds https://github.com/scottellis/pwmpy

But if that doesn’t work, it is just a matter of writing to the various sys files to set pwm frequency and duty. Basically just file i/o. You just need to locate the correct paths. Try searching for PWM, BASH and Linux.

Again GPIO depending on kernel is just a matter of exporting the GPIO pin in /sys/class/gpio/export and then writing to the relevant file.

In Linux pretty much everything is a file, so any file i/o can be used to interact with the system.

The above assumes to have the correct pin muxing configure in your devicetree.

https://docs.beagleboard.org/latest/books/beaglebone-cookbook/02sensors/sensors.html#id28

That exact link will help you in Python3 for inputs via GPIO peripherals on the am335x (I think).

Seth

Update

I have not tried the file descriptors way w/ the above method from the docs. pages. The idea is to write to an input. First off, I do not know your system. If you use one of the beagleboard.org images they have made available, using config-pin to set the mode works, the GPIOs are listed in /sys/class/gpio/*, and gpiod works too.

Outside of working w/ their specific images (BSPs), I do not have a ton of experience using libraries but the language, w/ like what @benedict.hewson describes, while using file descriptors works w/ the BBB to my knowledge.

I have used various ways/languages to create useful ideas and presented them (either online or in person). Either way, I think the Adafruit_BBIO lib. stopped being publicly Open Source unless there are a few or a ton of people using it. If you track them down to see how they got it to work, it may be useful…

From the Docs…

# Make it an input pin
f = open(GPIOPATH+"/gpio"+pin+"/direction", "w")
f.write("in")
f.close()

So,

import WHATEVER_IS_NEEDED
import MORE_LIBS_WITHIN_PYTHON3

pin = '7' #  P9_42 is gpio 7 and I do not know how gpio 7 is P9_42 yet?
GPIOPATH = "/sys/class/gpio" # or use /sys/class/gpio/THE_EXACT_GPIO(n)

# Make sure pin is EXPORTED IF NEEDED which it might not be needed?
if (not os.path.exists(GPIOPATH + "/gpio" + pin)):
    f = open(GPIOPATH + "/export", "w")
    f.write(pin)
    f.close()

# Make it an input pin
f = open(GPIOPATH + "/gpio" + pin + "/direction", "w")
f.write("in")
f.close()

...

fancy source...

I think this could in theory work depending on your ideas and build. Did you allow access to GPIO in sysfs in your kernel? I know there must be more to add to the kernel than just sysfs access (if they still allow it)…

Another Update

I will test it. I know there must be a push button around here somewhere…

I will get back to you!

The last update

Okay. So, it works (sort of)… My source is lousy for now. I am still working on it. I am three hours in and edge and active_low seem to work as expected but I am not sure if they are the reasoning behind my source working just yet. I need to research more:

https://www.kernel.org/doc/Documentation/gpio/sysfs.txt will help you understand more.

Hi,

Thanks for your reply, We followed what you suggested with the same pin and added code to read file.

import WHATEVER_IS_NEEDED
import MORE_LIBS_WITHIN_PYTHON3

pin = '7' #  P9_42 is gpio 7 and I do not know how gpio 7 is P9_42 yet?
GPIOPATH = "/sys/class/gpio" # or use /sys/class/gpio/THE_EXACT_GPIO(n)

# Make sure pin is EXPORTED IF NEEDED which it might not be needed?
if (not os.path.exists(GPIOPATH + "/gpio" + pin)):
    f = open(GPIOPATH + "/export", "w")
    f.write(pin)
    f.close()

# Make it an input pin
f = open(GPIOPATH + "/gpio" + pin + "/direction", "w")
f.write("in")
f.close()

# read input pin
f = open(GPIOPATH + "/gpio" + pin + "/value", "r")
f.read()
f.close()

But when i try to read it is always giving value as 0, even though interrupt is generated(verified by checking voltage of that pin).

Can you please let us know the exact steps to configure kernel for gpio input while bootup.

Thanks,
Anusha

1 Like

Hello @Anusha ,

I think learning what exactly gets put into the kernel during compilation may prove useful.

Did you mention you used Yocto or are you using Buildroot or Armbian or ?

I tried w/ Buildroot a while back. I never got the correct .dts file put together for GPIO usage. I tried w/ Yocto recently also. I am still new to Yocto, i.e. what gets built and what is available in userspace is new to me.

So, this may seem a bit odd for me to ask but nevertheless…

  1. Will you provide the steps you took to build your distro (BSP)?
  2. If you would supply the build steps, I may be able to research a bit more on how your specific BSP will work w/ GPIO.
  3. Furthermore, that code from the docs. pages was for the /sys/class/gpio Subsystem (sysfs).

So, in the build steps of the kernel compilation, make sure you compile the sysfs config (which by the way is deprecated) which is still available last I checked.

Also: Assorted Miscellaneous Devices Documentation — The Linux Kernel documentation

That will give you some background on various drivers to build for or around GPIO.

Seth

PS. That source I threw out at you was from the docs. and I only listed portions (I think). There is still a lot for me to learn… I will try to relay info. back to you in time.

@Anusha ,

Did you ever figure out what steps were taken to build the current distro, i.e. Yocto or Buildroot?

Anyway, I am here learning and I may have time this weekend to look over your build steps. This way I can see if you have sysfs built into your kernel or not.

Seth

P.S. I found some more ideas:

  1. Driver porting: Device model overview [LWN.net]
  2. sysfs - _The_ filesystem for exporting kernel objects — The Linux Kernel documentation

The reason I bring up all these ideas is this fact. I would need to build upon your built kernel. Since I do not know how to do what you have already done, I am guessing. For instance, in Buildroot, I will pick the sysfs interface as an option when menuconfig is built. Yocto is different and I am sort of new to Yocto builds w/ the sysfs interface. So, one may need an older build around Yocto and not the bleeding edge 6.1.x kernel. Maybe something stable from an older model will work.

Anyway, if you get around to build steps, let me know.