Hi Seth,
I tried your c code that you posted on the 2nd of November, and it’s basicly working fine. I had to fix some minor issues, my changes are shown below.
Checking the pins, I could see the rising and falling levels on the Direction
, Step
and Enable
pins - pins 35, 33 and 32 on the 40 pin header.
This means that the gpios and libgpiod are working as they should.
Double check the sense of your outputs - in particular the enable
signal is active low.
I’m on Debian Bookworm Xfce Image 2024-06-12
/*
* cc gpio_test.c -lgpiod -o gpio_test
*/
#include <gpiod.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#ifndef CONSUMER
#define CONSUMER "Consumer"
#endif
int main(int argc, char **argv)
{
const char *chipname = "gpiochip2";
unsigned int line_num1 = 18; // Direction
unsigned int line_num2 = 12; // Step
unsigned int line_num3 = 16; // Enable
unsigned int val;
struct gpiod_chip *chip;
struct gpiod_line *line1;
struct gpiod_line *line2;
struct gpiod_line *line3;
int ret1, ret2, ret3;
chip = gpiod_chip_open_by_name(chipname);
if (!chip) {
perror("The opening is failing...\n");
goto end;
}
line1 = gpiod_chip_get_line(chip, line_num1);
if (!line1) {
perror("Get line 1 failed\n");
goto close_chip;
}
line2 = gpiod_chip_get_line(chip, line_num2);
if (!line2) {
perror("Get line 2 failed\n");
goto close_chip;
}
line3 = gpiod_chip_get_line(chip, line_num3);
if (!line3) {
perror("Get line 3 failed\n");
goto close_chip;
}
printf("3 lines got\n");
ret1 = gpiod_line_request_output(line1, CONSUMER, 0);
if (ret1 < 0) {
perror("Request line 1 as output failed\n");
goto release_line;
}
ret2 = gpiod_line_request_output(line2, CONSUMER, 0);
if (ret2 < 0) {
perror("Request line 2 as output failed\n");
goto release_line;
}
ret3 = gpiod_line_request_output(line3, CONSUMER, 0);
if (ret3 < 0) {
perror("Request line 3 as output failed\n");
goto release_line;
}
printf("3 lines as output\n");
gpiod_line_set_value(line1, 1);
gpiod_line_set_value(line2, 1);
gpiod_line_set_value(line3, 1);
sleep(3);
gpiod_line_set_value(line1, 0);
gpiod_line_set_value(line2, 0);
gpiod_line_set_value(line3, 0);
sleep(3);
for (val=0; val<100; val++) {
putchar('.'); fflush(stdout);
gpiod_line_set_value(line1, (val & 0x01) != 0);
gpiod_line_set_value(line2, (val & 0x02) != 0);
gpiod_line_set_value(line3, (val & 0x04) != 0);
sleep(1);
}
printf("done\n");
release_line:
gpiod_line_release(line3);
close_chip:
gpiod_chip_close(chip);
end:
return 0;
}