# GPIO available pins

**URL:** <https://forum.legato.io/t/gpio-available-pins/2608>\
**Category:** Legato Linux distribution (Yocto project)\
**Created:** [August 17, 2017, 8:14am UTC](https://forum.legato.io/t/gpio-available-pins/2608 "2017-08-17T08:14:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kalaivani](https://avatars.discourse-cdn.com/v4/letter/k/4da419/32.png) [@Kalaivani](https://forum.legato.io/u/Kalaivani)\
**Post date:** [August 17, 2017, 8:14am UTC](https://forum.legato.io/t/gpio-available-pins/2608/1 "2017-08-17T08:14:24Z")

</div>

I want to know what all are the available GPIO pins are available to use. I need to send the intermediate response of available GPIO pins for the test and read mode AT commands of AT+KGPIOCFG for WP85 series from my legato application. I tried to read the /sys/class/gpio/export but there is no content inside this file.

```
char result[1000];
FILE *fp = NULL;
int i;
char c;
fp = fopen("/sys/class/gpio/export", "r");
if (!fp)
{
    LE_INFO("Error opening file %s for reading.\n", "/sys/class/gpio/export");
    return;
}
else
{
    LE_INFO("Opening file %s for reading is successful.\n", "/sys/class/gpio/export");
    return;
}
i = 0;
while (((c = fgetc(fp)) != EOF) && (i < (sizeof(result) - 1)))
{
    result[i] = c;
    i++;
}
result[i] = '\0';
fclose (fp);

LE_INFO("Read result: %s from %s", result, "/sys/class/gpio/export");

```

Is this correct way of fetching available pins? Any legato GPIO services or method is available to get these values?

---

<div class="post-metadata">

**Author:** ![mahtab](https://avatars.discourse-cdn.com/v4/letter/m/898d66/32.png) [@mahtab](https://forum.legato.io/u/mahtab)\
**Post date:** [August 17, 2017, 10:56am UTC](https://forum.legato.io/t/gpio-available-pins/2608/2 "2017-08-17T10:56:58Z")

</div>

You may want to remove that second return…

> LE\_INFO(“Opening file %s for reading is successful.\n”, “/sys/class/gpio/export”);  
> **return;**

---

<div class="post-metadata">

**Author:** ![dfrey](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/dfrey/32/563_2.png) [@dfrey](https://forum.legato.io/u/dfrey)\
**Post date:** [August 17, 2017, 5:09pm UTC](https://forum.legato.io/t/gpio-available-pins/2608/3 "2017-08-17T17:09:31Z")

</div>

The file `/sys/class/gpio/export` is a write-only file. It’s purpose is to make GPIOs available to user space applications. For example, if you do `echo 25 > /sys/class/gpio/export`, then the symlink `/sys/class/gpio/gpio25` will be created. The symlink points to a folder and inside that you will find files for interacting with that GPIO. If you want to know all of the GPIOs that are currently exported to userspace, you could look at all of the symlinks matching `/sys/class/gpio/gpioN`.

---

<div class="post-metadata">

**Author:** ![JewelHanda](https://avatars.discourse-cdn.com/v4/letter/j/8c91f0/32.png) [@JewelHanda](https://forum.legato.io/u/JewelHanda)\
**Post date:** [December 11, 2019, 4:52pm UTC](https://forum.legato.io/t/gpio-available-pins/2608/4 "2019-12-11T16:52:18Z")

</div>

Hi…I reckon the gpios failing low probably triggered the boot into safe mode (I think you have to ground a particular gpio to enter safe mode). So safe mode entry was probably a symptom, not a cause.  
One of the electronic type guys would probably know what caused the problem.
