We use cookies to provide our visitors with an optimal site experience. View our privacy notice and cookie notice to learn more about how we use cookies and how to manage your settings. By proceeding on our website you consent to the use of cookies.
Some further testing: I updated debian to 11 (bullseye) now, but still can’t use libgpiod to toggle GPIOs.
I tried using the Perl script to print out pins
debian@beaglebone:/opt/scripts/device/bone$ sudo /opt/scripts/device/bone/show-pins.pl
parse error at /opt/scripts/device/bone/show-pins.pl line 129, <> line 2.
Okay, I now tried toggling the pins in a Rust application using the gpiod crate and that works totally fine.
Maybe it is something with the way the gpiod CLI utilities work…
@robamu , I have found that in C, it works but on the am335x supported BBB…
The pin is left floating.
a. cannot be used in other languages or w/out libgpiod.
b. a reboot is necessary to clear the pin of this issue.
I am not sure why this is the way it is but for now, this is all I can configure.
/*
Simple gpiod example of toggling a LED connected to a gpio line from
the BeagleBone Black Wireless and RelayCape.
Exits with or without CTRL-C.
*/
// This source can be found here: https://github.com/tranter/blogs/blob/master/gpio/part9/example.c
// It has been changed by me, Seth, to handle the RelayCape and BBBW Linux based SiP SBC.
// kernel: 5.10.140-ti-r52
// image : BeagleBoard.org Debian Bullseye Minimal Image 2022-11-01
// type gpioinfo and look for this line: line 20: "P9_41B" "relay1" output active-high [used]
// That line shows us the info. we need to make an educated decision on what fd we will use, i.e. relay1.
// We will also need to locate which chipname is being utilized. For instance: gpiochip0 - 32 lines:
// #include <linux/gpio.h>
#include <gpiod.h>
#include <stdio.h>
#include <unistd.h>
int main(int argc, char **argv)
{
const char *chipname = "gpiochip0";
struct gpiod_chip *chip;
struct gpiod_line *lineLED;
int i, ret;
// Open GPIO chip
chip = gpiod_chip_open_by_name(chipname);
if (!chip) {
perror("Open chip failed\n");
return 1;
}
// Open GPIO lines
lineLED = gpiod_chip_get_line(chip, 20);
if (!lineLED) {
perror("Get line failed\n");
return 1;
}
// Open LED lines for output
ret = gpiod_line_request_output(lineLED, "relay1", 0);
if (ret < 0) {
perror("Request line as output failed\n");
return 1;
}
// Blink a LED
i = 0;
while (true) {
ret = gpiod_line_set_value(lineLED, (i & 1) != 0);
if (ret < 0) {
perror("Set line output failed\n");
return 1;
}
usleep(1000000);
i++;
}
// Release lines and chip
gpiod_line_release(lineLED);
gpiod_chip_close(chip);
return 0;
}
So, in my idea here, I would have thought the gpiod_line_release and gpiod_chip_close remedies would have alleviated this issue. If you see where I am making an issue, please let me know.
Please remember, once you run the above source to handle a LED or whatever, the pin is left in a floating state which disables running other source in other languages outside of libgpiod being able to be used.
Also…that specific source is for the RelayCape on the BBB. So, the RelayCape is autodetected and the pins muxed accordingly.
Seth
P.S. If you need to use config-pin on the BBB, this may provide a valuable way of muxing your pin that you want to have available. In Rust, did you come across this issue?