0

I am trying to communicate via GPIO using C. Based on this I tried to download the source for libgpiod and build but I got...

configure: error: "libgpiod needs linux headers version >= v5.5.0"

I tried to install via aptitude like sudo apt-get install libgpiod but when I run sudo gpioget gpiochip1 20(GPIO 20 works on my python app) I get...

gpioget: error reading GPIO values: Invalid argument

How do I get libgpiod to work? Is there a more "native" way to do GPIO programming?

Jackie
  • 181
  • 1
  • 8

1 Answers1

5

See my more complete answer at the link below

Control GPIO pins from C

But to summarize the setup that worked for me:

Raspberry Pi 3B (but I suspect this will work for RPi 4 as well).

Clean install of buster. Installing gpiod on jessie failed for me.

sudo apt-get install gpiod libgpiod-dev libgpiod-doc

The standalone applications

gpiodetect, gpioinfo, gpioget, gpioset, gpiofind and gpiomon

are installed along with two different C APIs.

API 1) Found in /usr/include/linux/gpio.h and included via:

#include <linux/gpio.h>

Note that you also need to include several system call libraries.

API 2) Found in /usr/include/gpiod.h (and gpiod.hpp for C++), and included via:

#include <gpiod.h>

I believe that installing this API is the one that also brings in the standalone apps. Programs using this API need to be compiled with something like:

gcc -o myprogram -lgpiod myprogram.c

My other contribution gives an example of API 1, as well as some links to other examples.

gorlux
  • 266
  • 1
  • 6