Gpio: Unable to open GPIO direction interface for pin -1: No such file or directory

I get “gpio: Unable to open GPIO direction interface for pin -1: No such file or directory” when registering interrupts through libWiringPi:

wiringPiISR(3, INT_EDGE_BOTH, handler1);
wiringPiISR(2, INT_EDGE_BOTH, handler2);
wiringPiISR(7, INT_EDGE_BOTH, handler3);
wiringPiISR(11, INT_EDGE_BOTH, handler4);

How can I fix this?

Running “gpio readall” freezes the Edge-V… sometimes running the wiringPiSetup() from c program also freezes the Edge-V


@quatro I am checking now .

1 Like

@quatro I find the error form.Some pins lock the CPU . But We haven’t found a solution yet. I temporarily shielded these 4 pins. There is no problem with other pins. You can use them first.

which are the pins that lock the CPU?

@quatro you clone it .Then you can try gpio will see 4 pins wiringPi number is -1.

I have spent hours rewriting my own library to handle interrupts using linux select() and poll()… the issue is in the GPIOs from the kernel… they have too many errors: hangs cpu after first couple of detections, report wrong values, need to unexport first every time I open the program to read the gpio… any information about this? I need to use interrupts, and this is taking away too much time already for simple programming!

I need a solution as soon as possible…

The wiring Pi is only an upper layer package, and it cannot modify the content of the kernel itself. After I shield these pins, the gpioreadall command will not lock the CPU. I didn’t test and use the interrupt function in detail. Besides, not all functions and pins can be used after porting. This involves the reuse of pins in the kernel and other issues. If you need detailed documents, you can check here. I transplanted it from here, too.

Frank, I made my own code not using wiring pi, and the whole system hangs… not my program, the whole operating system is hanging when I poll the gpio device files in /sys/class/gpio. We are not talking about wiring Pi anymore, this is not about the readall function.

I create a separate thread which sleeps until changes are made to the file using linux poll() and linux select(). When it wakes, my other threads sleep, and the poll thread calls the ISR handler. This is the linux way.
The whole system hangs! If my app was the problem I should have my app hang, and the system still be accesible through ssh for example, or the command line. Not happening, everything hangs, and this has to be an issue with the gpio kernel module, there’s no other option here.

Another proof:

  1. After the first 2 interrupts it freezes the value, when running “cat /sys/class/gpio/gpio122/value” it always returns 1 no matter if I manually connect the pin to ground or to 3V3. My code stops detecting new interrupts via linux poll().

  2. If I do “echo 1 > /sys/class/gpio/gpio122/value” my code detects these changes as it should, so my app is running perfectly.

  3. If I do “echo 122 > /sys/class/gpio/unexport” and “echo 122 > /sys/class/gpio/export” it freezes the CPU (no LED flashes, command line and ssh access are down and not recoverable).

There is an issue with the gpio kernel module or is it an issue on the hardware of the EdgeV?

I need these fixed as soon as possible, I’m running out of development time!

@quatro You said gpio readall freezes the Edge-V. It’s the command with WiringPi.So So I naturally think you’re using a wiringPi.About the GPIO error with kernel .Maybe @numbqq can help you.

I got more information that might help:
The issue happens when you do digitalRead(), inside the ISR thread called by poll inside wiringPiISR()

I fixed this writing my own library, WiringPi is not doing much at all, just reading and monitoring the linux devices, not true direct access to the gpio

I can’t reproduce this issue on my side…

$ echo 122 > /sys/class/gpio/unexport
$ echo 122 > /sys/class/gpio/export

It won’t happen just with those steps… the real problem is:

  1. Register interrupt wiringPiISR()
  2. Generate change to pin level
  3. inside the interrupt handler, do digitalRead()
  4. No more interrupts will be received after the first 2.
  5. Once the interrupts stopped working, the value in the device file gets stucked “cat /sys/class/…/value”, no matter the level in the pin. Now, if you unexport & export, the whole system hangs. Sometimes doing “echo” to the device file also hangs the system.

I made my own function to read the file, and it fixed everything.

The problem should be here:

bank = pin / 32;
setClkState(pin, EDGE_CLK_ENABLE);

ret = *(gpio[bank] + (EDGE_GPIO_GET_OFFSET >> 2)) & (1 << gpioToShiftReg(pin)) ? HIGH : LOW;

setClkState(pin, EDGE_CLK_DISABLE);
return ret;

Mark this response as the solution for my case