Hexgen
Posts: 3
Joined: Sun Feb 19, 2017 8:03 pm

GPIO No such file or directory

Sun Feb 19, 2017 8:17 pm

So this is driving me insane.

I have an LED on GPIO 21.
root@RP0:/sys/class/gpio/gpio21# echo "out" > direction
root@RP0:/sys/class/gpio/gpio21# echo "1" > value

LED lights up.

However;
root@RP0:/sys/class/gpio/gpio21# echo "out" > /sys/class/gpio21/direction
-bash: /sys/class/gpio21/direction: No such file or directory

Anyone know what's going on here? I currently cannot access any GPIO with Node.JS, C++ or anything other than going to the directory in a terminal and switching it there.

It does not matter if I set all GPIO as unexport or individually;

root@RP0:/sys/class/gpio/gpio21# echo "21" > /sys/class/gpio/export
-bash: echo: write error: Device or resource busy

root@RP0:/sys/class/gpio/gpio21# echo "21" > /sys/class/gpio/unexport
root@RP0:/sys/class/gpio/gpio21# echo "out" > "/sys/class/gpio21/direction"
-bash: /sys/class/gpio21/direction: No such file or directory

but;

root@RP0:/sys/class/gpio/gpio21# echo "0" > value

LED turns off.

wtf!

Anyone else seen this? I have searched, but alas nothing works.

User avatar
rpdom
Posts: 17275
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: GPIO No such file or directory

Mon Feb 20, 2017 7:24 am

Hexgen wrote:root@RP0:/sys/class/gpio/gpio21# echo "out" > /sys/class/gpio21/direction
-bash: /sys/class/gpio21/direction: No such file or directory
Yes, you will get that error if you don't put the correct full path for the pseudofile /sys/class/gpio/gpio21/direction.

Hexgen
Posts: 3
Joined: Sun Feb 19, 2017 8:03 pm

Re: GPIO No such file or directory

Mon Feb 20, 2017 7:53 am

In my defence I was super tired. Still though, wow.

Thanks rpdom!

Hexgen
Posts: 3
Joined: Sun Feb 19, 2017 8:03 pm

Re: GPIO No such file or directory

Mon Feb 20, 2017 7:15 pm

I would like to add, for clarity, that my initial confusion was around elevated privileges. I was accessing GPIO via C++ and standard out was reporting that the pin I was setting was 0, irrespective of what I set it to.

I had omitted "sudo" and while my C++ program ran happily, writing to GPIO under the default "pi" user is not permitted.

This is what I get writing to the (virtual) file system and not checking for errors.

User avatar
rpdom
Posts: 17275
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: GPIO No such file or directory

Mon Feb 20, 2017 7:31 pm

Hexgen wrote:In my defence I was super tired. Still though, wow.
I get that way sometimes. Stare for hours at a problem and find no solution.

Then I walk away, go do something else for a while, look at another problem. After a reasonable break I come back to the original problem and the lightbulb goes on (or I wake up in the middle of the night grab a notepad)

Just saying, I'm very familiar with that situation :-)

User avatar
jojopi
Posts: 3274
Joined: Tue Oct 11, 2011 8:38 pm

Re: GPIO No such file or directory

Mon Feb 20, 2017 8:18 pm

Hexgen wrote:I had omitted "sudo" and while my C++ program ran happily, writing to GPIO under the default "pi" user is not permitted.
In the recommended images, the pi user is a member of the gpio group, and can access the /sys/class/gpio/ files without sudo.

When exporting the pins inside a program, however, there can be a race condition. The files are initially created by the kernel as root:root, and then it takes a second or so for udev to apply the correct permissions. You may need to insert a delay or a call to "udevadm settle" between export and first use.

Return to “Troubleshooting”