I’m using raspberry PI 4, and I want to set my line to use the internal PULL_UP (default Raspberry lines above 8 are all pull_down):
Using C++ and libgpiod:
try
{
gpiod::chip chip("gpiochip0");
gpiod::line_bulk lines;
const std::vector<io_gpio_t> offsets = {
{1, 21},
{2, 26},
{3, 16},
{4, 19}};
for (io_gpio_t offset : offsets)
{
auto line = chip.get_line(offset.gpio_line);
line.set_bias(gpiod::line::bias::pull_up); <<---- ERROR HERE!!!!
line.request({"io", gpiod::line_request::EVENT_BOTH_EDGES, 100000});
lines.append(line);
}
while (true)
{
gpiod::line_bulk changed_lines = lines.event_wait(std::chrono::seconds(10));
for (gpiod::line line : changed_lines)
{
auto event = line.event_read();
int offset = line.offset();
process_digital_in(offset, event); // Process event
}
}
}
catch (const std::exception &e)
{
std::cerr << "Error: " << e.what() << std::endl;
}
}
Seens that version 1.6 of libgpiod does not support set_bias:
src/IO.cpp:79:18: error: ‘class gpiod::line’ has no member named ‘set_bias’; did you mean ‘set_flags’?
79 | line.set_bias(gpiod::line::bias::pull_up);
| ^~~~~~~~
| set_flags
src/IO.cpp:79:40: error: ‘gpiod::line::bias’ is not a class, namespace, or enumeration
79 | line.set_bias(gpiod::line::bias::pull_up);
| ^~~~
Compiler suggests set_flags, but I cannot find docs on that.
How to properly set the input to use the internal pull up programatically?