3

I have an Intel aaeon upboard and I want to use its GPIO pins. To do that I'm trying the below code:

echo 17 > /sys/class/gpio/export

But when I run it, this is what I get:

-bash: echo: write error: Invalid argument

What can be the problem and how can I fix it?


The output of ls /sys/class/gpio/:

export gpiochip225 gpiochip228 gpiochip314 gpiochip341 gpiochip414 unexport
Kamil Maciorowski
  • 69,815
  • 22
  • 136
  • 202
Yunus Temurlenk
  • 133
  • 1
  • 5

1 Answers1

3

The documentation reads:

GPIO controllers have paths like /sys/class/gpio/gpiochip42/ (for the controller implementing GPIOs starting at #42) and have the following read-only attributes:

/sys/class/gpio/gpiochipN/

base ... same as N, the first GPIO managed by this chip

[…]

ngpio ... how many GPIOs this manages (N to N+ngpio-1)

In your case the lowest N is 225. No chip manages GPIO 17. Invoke

cat /sys/class/gpio/gpiochip225/ngpio

If you get (e.g.) 2 then you can use two numbers: 225 and 226:

# as root
echo 225 > /sys/class/gpio/export
echo 226 > /sys/class/gpio/export

(If you want to use sudo, this trick will be useful: echo 225 | sudo tee /sys/class/gpio/export).

Similarly for other controllers (gpiochipN entries).


Note sysfs-gpio is deprecated. See this video on YouTube.

Kamil Maciorowski
  • 69,815
  • 22
  • 136
  • 202
  • thank you echo 225 > /sys/class/gpio/export this is working without an error. But another problem. Im trying to do in this [link](https://software.intel.com/en-us/articles/robotics-development-kit-blink-led-tutorial) But when I run that code this error occurs: Failed to open gpio direction for writing! Could you please control that link – Yunus Temurlenk Jun 18 '19 at 07:01
  • @YunusTemurlenk I think I have solved your original problem. If you have a new one, ask a separate question (separate post). Please take our short [tour] to learn how the site works. Don't let this question be "[chameleon](https://meta.stackexchange.com/q/43478/355310)". – Kamil Maciorowski Jun 18 '19 at 07:05
  • okay. thank you so much I will ask it in a new post. – Yunus Temurlenk Jun 18 '19 at 07:12
  • @YunusTemurlenk Do the research first, especially what the documentation says about "direction". Make sure you understand the code from your link. Super User is not about programming and nobody will analyze the code. – Kamil Maciorowski Jun 18 '19 at 07:22
  • Okey. I will delete the post and I will do research but can you please take a short look at that – Yunus Temurlenk Jun 18 '19 at 07:26
  • @YunusTemurlenk There problem is with opening `/sys/class/gpio/gpioN/direction`. Maybe it doesn't exist. That's why I sent you back to the documentation where it describes `direction`. – Kamil Maciorowski Jun 18 '19 at 07:30
  • @YunusTemurlenk Note `225` may or may not be right for what you're trying to do. It may be input-only or not available (physically) at all. Try to match `ngpio` from available controllers to numbers of physical pins (e.g. if there is a separate block of 20 pins, it's probably managed by a controller for which `ngpio` is `20`). – Kamil Maciorowski Jun 18 '19 at 07:38
  • I have understood my problem now. I dont have an available gpiochip* file for my upboard. My upboard has 40 pins and the gpiochip files in /sys/class/gpio is not for the 40 pins how can I install an available driver for my upboard – Yunus Temurlenk Jun 18 '19 at 13:26