I wrote a little test program in Python to manipulate GPIO pins on an an Intel Up Xtreme i11. First running under NixOS, I brought in the package as "libgpiod" and things are working. (MacOS package managers also know "libgpiod".) Then I tried to port this to an Ubuntu world on the same hardware. But apt and apt-get know nothing of libgpiod, they only know gpiod. pip3, too. So I installed gpiod, but the discrepancies mount up…
- gpiod has a member "chip" rather than "Chip"
- chip.get_line gets Error 22 for any small integer I can find.
What I lack is documentation. Is there something, somewhere, that clearly explains the distinction between these two packages that appear to be similar but are not? And what is actually the correct way of using the Ubuntu gpiod package in Python?
BTW I am running as root in both cases. Here's the code (gpiod version):
import gpiod, time
# pins
POWER = 9
chip=gpiod.chip('gpiochip0')
power=chip.get_line(POWER)
power.request(consumer="motor_movement", type=gpiod.LINE_REQ_DIR_OUT)
def run():
delay = 1.0
try:
#power.set_value(0)
while True:
power.set_value(1)
time.sleep(delay)
power.set_value(0)
time.sleep(delay)
finally:
cleanup()
def cleanup():
power.release()
if __name__ == "__main__":
run()