AI-64 - GPIO sysfs

Hi Guys,

I have been bumbling around trying to get this to work and have managed it, so though I would add this here to help any other poor bumblers. I’m sure this is basic stuff but I found it hard to find a worked example on the internet.

This example is for pin P8_07:

First find the gpiochips:

root@AI64:/sys/class/gpio# gpiodetect
gpiochip0 [42110000.gpio] (84 lines)
gpiochip1 [600000.gpio] (128 lines)
gpiochip2 [601000.gpio] (36 lines)

Then find the gpio details for the pin:

root@AI64:/sys/class/gpio# gpiofind P8_07
gpiochip1 15

Now have a look for the gpiochips:

root@AI64:/sys/class/gpio# ls -ltr /sys/class/gpio/gpiochip*
lrwxrwxrwx 1 root root 0 Jan  1  1970 /sys/class/gpio/gpiochip428 -> ../../devices/platform/bus@100000/bus@100000:bus@28380000/42110000.gpio/gpio/gpiochip428
lrwxrwxrwx 1 root root 0 Jan  1  1970 /sys/class/gpio/gpiochip264 -> ../../devices/platform/bus@100000/601000.gpio/gpio/gpiochip264
lrwxrwxrwx 1 root root 0 Jan  1  1970 /sys/class/gpio/gpiochip300 -> ../../devices/platform/bus@100000/600000.gpio/gpio/gpiochip300

Match via the address, 600000 for gpiochip1->gpiochip300

Calculate the gpio number the 300 in gpiochip is the base and we need to add 15 (from gpiofind command) so we have 315.

So export 315:

root@AI64:/sys/class/gpio# echo 315 > /sys/class/gpio/export
root@AI64:/sys/class/gpio# ls /sys/class/gpio/      
export	gpio315  gpiochip264  gpiochip300  gpiochip428	unexport

Now you have the gpio mapped, for example we can set it to an output and set the value to 1:

root@AI64:/sys/class/gpio# echo out > /sys/class/gpio/gpio315/direction 
root@AI64:/sys/class/gpio# echo 1 > /sys/class/gpio/gpio315/value
1 Like

and a quick update, we (@jkridner ) has a patchset to label all these gpio’s, it just didn’t get merged beforew we both went to Embedded World. So early next week i’ll merge those in… (after recovering from the flight/time/zone/travel/etc…)…



Hello all,

As a total beagle newbie, I have started bumbling…

I am trying to get pushbutton.js Ex 2.1 in the BeagleBone Cookbook to work. On the BBAI64, I don’t see P9_42 but, I do see a P9_42A and a P9_42B. The schematics only show a P9_42 on the P9 header. Any tips on how should I map this out?

cat /etc/dogtag/ Debian Bullseye Xfce Image 2022-08-26
debian@BeagleBone:~$ uname -a
Linux BeagleBone 5.10.120-ti-arm64-r61 #1bullseye SMP Fri Aug 19 16:48:12 UTC 2022 aarch64 GNU/Linux
debian@BeagleBone:~$ gpioinfo | grep -e chip -e 9.42
gpiochip0 - 84 lines:
gpiochip1 - 128 lines:
line 18: “P9_42B” unused input active-high
line 123: “P9_42A” unused input active-high
gpiochip2 - 36 lines:

THanks for any tips,

It’s been really great learning from the forum posts. Looking forward to eventually running some i/o off an R5F core to see how isolated it is from Linux.

1 Like

Hi Fred,

Some of the header pins on the BB-AI64 are connected to two different pins on the MPU. These are then labelled A & B.

If you are looking at the schematic (page 25) you can see the P9.42 is connected to signal AC2_AJ21. If you look further down the same page you can see that signal is then connected to pad AC2 and pad AJ21 on the MPU.

If using function A, then function B pin muxing needs to be set as a GPIO input or vice versa if using function B to prevent the possibility or driving 2 outputs together.

I posted a spreadsheet with the various possible pinmux combintation for the headers here Pinmux spreadsheet

If you are following an example for the BBB it will probably need some work as the two boards are very different. P9.42 on the BBB is GPIO0.7 Depending on how the pin muxing is setup, P9.42 on the AI64 could be either GPIO0.123 or GPIO0.18

I have never used JS, I am a C/Python/Bash scripting person myself.
You can try exporting either GPIO0.123 or GPIO0.18 from a terminal and seeing if you can read the input value.


Hi Benedict,

Thanks for the tips. I have working versions of the program in JS, Python, and Bash Shell script.

For anyone else bumbling along, the BeagleBone Cookbook github example code is greatly updated from the print book. There are both JS and Python versions of the programs.

I’m with you Benedict, I’m going to stay away from JS. One less thing I have to learn :wink:


I am off to learn about Pinmuxing and device tree overlays.

EDIT: After I disconnect the positive lead of my voltmeter from P9_42, the input always reads 1. With the meter connected, it reads 0 until the button is pressed, then it reads 1. So it seems I still have something electrical to figure out…

1 Like

The pin is probably floating when your meter is not connected causing the input to read high. I haven’t checked but the GPIO pins should be configurable with an internal pull up, pull down or neither. Think you would need to do that in a devicetree overlay, I don’t think it can be done by the /sys interface which is a shame, or gpioset.
It would be easier to fit a high value pull down resistor from pin 9.42 to ground if you are switching it high with the button.

Fitting a 1K pull down resistor did the trick. I am going to try setting some outputs. I see in the CookBook 1st Ed that “The GPIO pins on the Bone can source 4 or 6 mA at 3.3V, depending on the pin.” All GPIO pins can sink 8 mA. The CookBook 2nd Ed states “The Bone can drive only 4 to 6 mA”. Perhaps it is best practice to use 4 mA as the sourcing limit?

Is there a resource that lists out the details on what the BBAI64 GPIOs can source and sink?

looks like it is about 5-6ma page 169 TDA4VM.pdf

It works! A big thanks to you and Andrew Capon for the help getting this BBAI64 hardware “hello, world” up and running. Based upon the TDA4VM data sheet, we are treating the IO as max sink -5mA and max source +6mA.