I’m trying to follow the instructions for direct control of the GPIO using the standard Linux library Libgpiod and I'm not suceeding. (https://revolutionpi.com/en/tutorials/e ... ol-compact)
I have disabled piControl by using modprobe blacklist, built the code and run it on a standard build Rpi, but then the code fails on the RevPi. When I run gpioinfo the IO lines are still showing as [used].
I would like to be able to access the three bi-colour LEDs to start with.
What am I missing, please?
Code: Select all
#include <stdio.h>
#include <unistd.h>
#include <gpiod.h>
int main() {
struct gpiod_chip * chip;
struct gpiod_line * line;
int rv, value;
printf("testing GPIO\n");
chip = gpiod_chip_open_by_number(0);
if (!chip)
{
printf("chip failed\n"); // RevPi fails here
return -1;
}
line = gpiod_chip_get_line(chip, 3);
if (!line) {
gpiod_chip_close(chip);
printf("line failed\n");
return -1;
}
rv = gpiod_line_request_output(line, "test", 0);
if (rv)
{
gpiod_chip_close(chip);
printf("input failed\n");
return -1;
}
value = gpiod_line_set_value(line, 1);
sleep(1);
value += gpiod_line_set_value(line, 0);
printf("value - %d\n", value);
gpiod_chip_close(chip);
return 0;
}