0

I'm running a Pi4 with Debian Buster (not Raspbian / RaspberryPi OS) and need to interact with the GPIO pins but am having problems doing so.

I've created a gpio group and added the pi user to it along with setting the file permissions and group accordingly (re:GPIO Permission Denied). However accessing GPIO18 and other gives me the following error:

> sudo sh -c 'echo 18 >/sys/class/gpio/export'
> sh: 1: echo: echo: I/O error

or

> echo 18 >/sys/class/gpio/export
> -bash: echo: write error: Invalid argument

If I run ls /sys/class/gpio I get:

> export gpiochip446  gpiochip454  unexport

I can see (cant recall the command used) the gpiochip454 handles 58 pins and is the Broadcom BCM2711 which handles the GPIO. As a test I tried to export various GPIO pin numbers but none of them worked if below the gpiochip number. However, all (58) numbers from the gpiochip number upwards, do export.

So, I took a guess and assumed that if I counted up 18 pings from the gpiochip number (gpio472), I should be able to interact with gpio18, but this did not shutdown the power management board that reacts to gpio18. I also tried using the physical pin number(12) and adding this to the chip number giving me gpio466. Again, this did nothing, although in both cases I do see these pins being exported and visible via ls /sys/class/gpio.

> ls -l /dev/gpiochip*
 crw------- 1 root root 254, 0 Jan  4 16:06 /dev/gpiochip0
 crw------- 1 root root 254, 1 Jan  4 16:06 /dev/gpiochip1

Is there a way that I can use the gpio number like I would on Raspbian / Raspberrypi OS ?

I'm now at a loss as to what I need to do to get this working and would appreciate some help in working this out.

Thanks.

2
  • Could you add the result of ls -l /dev/gpiochip* to your question. – joan Jan 6 at 16:36
  • @joan I've added it that info in now, thanks. – Phill Healey Jan 6 at 18:53
1

I don't know why the sysfs exports aren't working. I tried a few variants of your commands but they did not work.

Given that the /dev/gpiochip devices exist you could use that interface instead.

I have a new /dev/gpiochip library suite called lg.

http://abyz.me.uk/lg/

You could use that to manipulate the GPIO.

I have added some details at https://elinux.org/C

1
  • I'll take a look at that thanks. Unfortunately, my need for this to work is that my power management board (x735) relies on bash scripts and services to work. It'll mean having to convert everything. But converting is better than it not working at all. Thanks. – Phill Healey Jan 6 at 19:31
1

I'm using a fresh aarch64 with Arch Linux on a RPi 4B, and had the same issue with echoing low numbers to /sys/class/gpio/export. Reading more, I see that the sysfs approach is legacy and probably being dropped from newer kernels. The character device ABI, using /dev/gpiochip[0-9]+ (as discussed by @joan), is the new way to access GPIOs.

On Arch, the gpio-utils package offers lsgpio, gpio-watch, gpio-hammer, gpio-event-mon as easy CLI tools for interacting with GPIO character devices. On Debian Buster, package gpiod provides gpioget, gpioinfo, gpiomon, gpioset, which may do the same.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.