Hey Ben,
I have tried multiple times via source to handle a stepper with libgpiod-dev and python3-gpiod.
I am failing without resolve. I really cannot find out why…
I changed udev, I changed source repeatedly (almost to the point I am running in circles), and then tested the connections:
- I noticed with
python3-gpiod
via an apt install, one would need to use something along these lines:
import gpiod
import time
gpio14 = gpiod.find_line('GPIO14')
gpio14.request(consumer='beagle', type=gpiod.LINE_REQ_DIR_OUT, default_val=0)
while True:
gpio14.set_value(1)
time.sleep(1)
gpio14.set_value(0)
time.sleep(1)
I got that from the docs. pages for GPIO under the header BeagleY-AI.
Anyway, I read the rationale and I am thinking that using 'GPIO14'
as the object instead of the variable is a “lose-lose.”
I say that with the most kindest regards. Still, is it 100% necessary that I attempt programming the BeagleY-AI in that format? For instance, I have other source that now is garbage and can be transferred easily but I do not know the steps to take.
- The other source goes like this:
#!/usr/bin/python3
import time
import gpiod
# Replace with the actual GPIO chip and line numbers
chip = gpiod.Chip("/dev/gpiochip2")
LINE1 = chip.get_line(18)
LINE2 = chip.get_line(12)
LINE3 = chip.get_line(16)
LINE1.request(consumer="STEP", type=gpiod.LINE_REQ_DIR_OUT)
LINE2.request(consumer="STEP", type=gpiod.LINE_REQ_DIR_OUT)
LINE3.request(consumer="STEP", type=gpiod.LINE_REQ_DIR_OUT)
LINE3.set_value(1)
try:
while True:
LINE1.set_value(1)
time.sleep(1)
LINE1.set_value(0)
time.sleep(1)
except KeyboardInterrupt:
LINE3.set_value(0)
I am trying to promote a simple motor to move but because of “something,” I am failing.
I have not tracked down how hard it is mentally/physically to deal with steppers and drivers but am currently trying with no luck.
Seth
P.S. Also, I am receiving an error like /dev/gpiochip2
is not existing with C/C++ source:
The opening is failing...
: No such file or directory
And…that is with 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)
{
char *chipname = "/dev/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 i, 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 failed\n");
goto close_chip;
}
line2 = gpiod_chip_get_line(chip, line_num2);
if (!line2) {
perror("Get line failed\n");
goto close_chip;
}
line3 = gpiod_chip_get_line(chip, line_num3);
if (!line3) {
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;
}
ret3 = gpiod_line_request_output(line3, CONSUMER, 0);
if (ret3 < 0) {
perror("Request line as output failed\n");
goto release_line;
}
/* Blink 20 times */
val = 0;
ret3 = gpiod_line_set_value(line3, val=1);
if (ret3 | val == 1) {
line_num1 = 1;
line_num2 = (1 / 8);
sleep(2);
line_num1 = 0;
line_num2 = (1 / 8);
} else {
line_num1 = 0;
line_num2 = 0;
}
release_line:
gpiod_line_release(line3);
close_chip:
gpiod_chip_close(chip);
end:
return 0;
}
Okay there…I have tried and after compilation, I can run the file binary but that error resides.
update
I think the error is due to not having an allowance in the GPIO chardev udev
rules.
I am not sure now, i.e. as I need to alter udev
some more and find out myself but for now, it is not plug-in, create source, and then watch the motor(s) spin freely.
That is what I expect that source to do. I expect that source to spin the motor via software and then upon canceling the file running, I expect the software controlled motor to stop.
The chip will not even open for usage. Is this a udev
result or my poor source?