Getting to read and write to gpio's

Hi,
i have just got a beaglebone black.
I’ve flashed it with the newest image I could find

uname -r
6.17.5-bone14

lsb_release -a
Distributor ID: Debian
Description: Debian GNU/Linux 13 (trixie)
Release: 13
Codename: trixie

i connect to it using ssh.
but I’m struggling getting it to read/write to the gpio’s?
I’ve tried to use python to read a button state and use it to toggle a diode i have connected via a breadboard.

I downloaded the beaglebone-cookbook-code but alle the gpio examples seems outdated I can’t get any of them to work.

eg.

toggle1.py from beaglebone-cookbook-code/02sensors/gpiod

import gpiod
import time

LED_CHIP = ‘gpiochip1’
LED_LINE_OFFSET = [18] # P9_14

chip = gpiod.Chip(LED_CHIP)

lines = chip.get_lines(LED_LINE_OFFSET)
lines.request(consumer=‘blink’, type=gpiod.LINE_REQ_DIR_OUT)

while True:
lines.set_values([0])
time.sleep(0.1)
lines.set_values([1])
time.sleep(0.1)

when i run this i get:

sudo python3 toggle1.py
[sudo] password for beaglebone:
Traceback (most recent call last):
File “/home/beaglebone/beaglebone-cookbook-code/02sensors/gpiod/toggle1.py”, line 17, in
chip = gpiod.Chip(LED_CHIP)
File “/usr/lib/python3/dist-packages/gpiod/chip.py”, line 58, in init
self._chip = _ext.Chip(path)
~~~~~~~~~^^^^^^
FileNotFoundError: [Errno 2] No such file or directory

I’ve also tried at chatgpt, claude and so on with no success..
I’ve searched for other libraries like adafruit but they all seems oudated?

So.
How can i read/write from/to the gpios?

trixie has libgpiod v2 so everything is off…

the example should work with Bookworm..

Regards,

When I was getting started, I found that example snippet useful too: Displays and Other Outputs — BeagleBoard Documentation

I use the Bullseye IoT Image 2023-08-05 (it needs a little effort to remove the default password, but it’s got more free space and a nice easy flasher image). I copied the snippet (fixed the asymmetric quotes and indentation) and it works on that in Python 3.9.2 without sudo, with gpiod._version_ 1.6.2.

The error does mention the path. Perhaps try LED_CHIP = ”\dev\gpiochip1” ?,

I can’t say I’ve not installed something different with apt-get or pip though. But gpiod does work great for me in a venv, using the context manager approach instead. Incidentally I found the advice on GPIO’s PyPi page to set LINK_SYSTEM_LIBGPIOD=1 causes a compiler error.

Don’t forget a resistor in series with the LED - I didn’t bother with one at first, and I think I had to reflash after overheating the board (I’m relieved I didn’t cook it).

okay so the os (trixie) doesn’t support the gpiod features yet or?
Instead of using gpiod lib.

can’t type something in some file and then read write from/to some files to do set/get the state?

Thanks,
i guess i should reflash with something older then. This is running python 3.13 i think and didn’t check the gpiod version but seems it’s isn’t working with debian 13..
thanks for the heads up haha i have a resistor in place, I played with arduinos and rasberry pi’s before - but this seems difficult compared to those. I don’t get how it can be that tedious to receive a button input haha.

man gpioinfo gpioget gpioset

They are what I use the most. Eg.

gpioinfo | grep -e chip -e 'P[89]_[0-9]*'
gpioget --by-name P8_7 P8_8
gpioset -c1 2=on 3=on

You can go through /sys/class/gpio also, but it’s more tedious.