Okay…
I am using a level shifter and the ULN2003A for testing this source:
// Testing...
#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 *chipname0 = "gpiochip0";
const char *chipname1 = "gpiochip1";
unsigned int line_num1 = 7; // Direction GPIO27 PIN 13
unsigned int line_num2 = 33; // Step GPIO23 PIN 16
unsigned int val;
struct gpiod_chip *chip1;
struct gpiod_chip *chip2;
struct gpiod_line *line1;
struct gpiod_line *line2;
int ret1, ret2;
chip1 = gpiod_chip_open_by_name(chipname0);
if (!chip1) {
perror("The opening is failing...\n");
goto end;
}
chip2 = gpiod_chip_open_by_name(chipname1);
if (!chip2) {
perror("No opening now...\n");
goto end;
}
line1 = gpiod_chip_get_line(chip1, line_num1);
if (!line1) {
perror("Get line failed\n");
goto close_chip;
}
line2 = gpiod_chip_get_line(chip2, line_num2);
if (!line2) {
perror("Get line failed\n");
goto close_chip;
}
ret1 = gpiod_line_request_output(line1, CONSUMER, 0);
if (ret1 < 0) {
perror("Request line as output failed\n");
goto release_line;
}
ret2 = gpiod_line_request_output(line2, CONSUMER, 0);
if (ret2 < 0) {
perror("Request line as output failed\n");
goto release_line;
}
printf("All lines are not output...\n");
for (val=0; val < 15; val++) {
sleep(0.41);
putchar('.');
fflush(stdout);
gpiod_line_set_value(line1, (val & 0x02) != 0);
gpiod_line_set_value(line2, (val & 0x04) != 0);
sleep(1);
}
printf("done...\n");
release_line:
gpiod_line_release(line1);
gpiod_line_release(line2);
close_chip:
gpiod_chip_close(chip1);
gpiod_chip_close(chip2);
end:
return 0;
}
The source compiles and runs. This is okay news but I only receive the jolt and then it goes back to where it started before the jolt of movement. Like it is a locking mechanism. Maybe I used this source for a locking solenoid in the past. Hmm?
Anyway, the source is working but the source is a bit off. I understand this is of concern. I will learn more in time but until then, I am at a standstill in source versus motor movement. Off to test…
Seth
P.S. Without using some compilation efforts on my part, the source does not run but errors out with a segmentation fault
. I mean it. Even with gcc MY_FILE.c -lgpiod -o my_file
for compilation, I receive some erroring that I am not accounting for currently. I have no way to tell what exactly is going on without more investigative work.
This link was the start of understanding the movement of a GPIO * 3
while attempting some logic to create a bipolar stepper to move around some…
Thank you @bbbpaul for starting it all with some good ideas…