Using GPIO pins on BeagleBone AI using Adafruit_BBIO library

Hi, I’ve been trying to set up a GPIO pin on the BeagleBone AI as an input but keep getting this error. I’ve confirmed that I am using the correct GPIO pin, it works as an output, but just can’t get it to work for an input.
image

Does anyone have any suggestions about what could help fix this, or a different approach to receiving an input from the GPIO pins?

The code I’m using is as follows:

import Adafruit_BBIO.GPIO as GPIO
switch = “P9_31”
GPIO.setup(switch, GPIO.IN)
exit_loop = 1
while exit_loop:
if GPIO.input(switch):
print(“Switch On”)
exit_loop = 0
GPIO.cleanup()

I tried using Adafruit_Blinka but it just results in an endless list of errors when trying to install/use the library. I know there are differences between the pins for the Black (which adafruit_BBIO is designed for) and the AI, but I’ve found GPIO pins using them as outputs.

Thanks

There are other posts regarding this.

However, unless someone else has a different answer, as far as I know, at this time the Adafruit_BBIO libraries are not supported with the BBAI:
Ref:
https://github.com/adafruit/adafruit-beaglebone-io-python/issues/317

If you need support with that library, I would suggest contacting Adafruit or adding yourself to the GitHub issue regarding this.

For info regarding the mapping on the BBAI, see the following references:
https://github.com/beagleboard/beaglebone-ai/wiki/System-Reference-Manual#p9.30-p9.31

https://docs.google.com/spreadsheets/d/1fE-AsDZvJ-bBwzNBj1_sPDrutvEvsmARqFwvbw_HkrE/edit#gid=1518010293

If you were able to get it the libraries to work on a BBAI pin as an output, that would be interesting. But, one thing you could try is to map a BB Black GPIO Pin value to a BB AI GPIO pin and see if you can fake out the libs. No guarantee that the pin is mapped to a generic GPIO pin or being used for something else though. You would have to see the references provided previously for clarification.

Example:
BB Black - P8.12 - gpio1.12 (76)
BBAI - P9_15 - gpio3_12 (76)

I’m not 100% sure this would work though.

Cheers,

Jon

Actually, the pin ref for BBB in the Adafruit_BBIO lib would be P8_39 for GPIO 76.

Ref:
https://github.com/adafruit/adafruit-beaglebone-io-python/blob/7361d9a997bce4ab79c83c4ef30442e8dd13f363/source/common.c

For the BBAI, P9_15 would have to be enabled in the .dts for the kernel that is running.

On the BBAI, P9_31 is mapped to gpio5_10 (gpio138) and shown as gpio110 “SPI1_SCLK” for the BBB. I did not find a gpio110 for the BBAI in the spreadsheet.

Cheers,

Jon

Yes, the BB pin P8_39 is the BBAI GPIO 76 (P9_15), that works perfectly fine on the AI as an output pin, but I’ve had issues with setting it up as an input pin.

I’m aware that the Adafruit_BBIO library isn’t very compatible with the AI, but I thought once I worked out how the pins match, I could get it to work. But unfortuantely I am only able to output signals using GPIO.setup(“P8_39”, GPIO.OUT)

Thanks for your help but I think I’ll just have to go with my alternative of using an arduinos serial output to send an input to my AI board.

I might give this a go/investigation, thanks

For reference, these are the pins I found work as outputs on the BBAI using the Adafruit_BBIO library. You use the BB pin for the software pin setup, but physically connect at the AI pin location:
image

You have to look at how the pin is defined in the .dts that is running. If it is not set to INPUT, then you would have to set it as such and rebuild the dtb.

I did this for P8.22 and P8.23:
Ex:
DRA7XX_CORE_IOPAD(0x3798, PIN_INPUT | MUX_MODE14) /* AD6: P8.22: mmc3_dat5.off /
DRA7XX_CORE_IOPAD(0x3794, PIN_OUTPUT | MUX_MODE14) /
AC8: P8.23: mmc3_dat4.off */

    cape_pins: cape_pins {
            compatible = "gpio-leds";
            pinctrl-names = "default";
            gpios = <&gpio6 12 GPIO_ACTIVE_HIGH>,
                    <&gpio5 0 GPIO_ACTIVE_HIGH>,
                    <&gpio1 22 GPIO_ACTIVE_HIGH>,
                    <&gpio1 23 GPIO_ACTIVE_HIGH>,
                    <&gpio3 12 GPIO_ACTIVE_HIGH>;
            pinctrl-0 = <&cape_pins_default>;
    };

Then you can can create your own Python script, or use another language to read and write to the pins.

As far as the Adafruit_BBIO libs, it really is a matter of how they are configuring the pins. What works on the BB Black does not necessarily work on the BBAI. I configured P8.22 as an Input and can use it with other tools or just command line, but it still gets an error from the BBIO code. Until someone looks into this, it is just not going to work on the BBAI.

Jon

1 Like

Thank you so much, I’ll try do that. I really appreciate the help!

Hi…I included my question to this topic rather than making a new subject. I moreover need to configure gpio pins within the gadget tree (DT). I examined the over BB-P9_27-LED-00A0.dts illustration. I get it what fragment0, 1 and 2 are doing but I won’t require those parts since my DT does not incorporate P9_27_pinmux helper. If I get it accurately, fragment3 employments gpio-leds. I don’t have a ‘led’ hub in my DT.

Just poking around and saw this. For anyone else reading this, I believe you need elevated privileges to ‘set’ the GPIO pins. Try sudo python app.py.

1 Like