0

I am attempting to rewrite a bit of code that used gpiozero for a Raspberry Pi that no longer works on the Raspberry Pi 5 due to the GPIO changes in the Raspi 5. I need it to be backwards compatible to possibly run on our Raspi 2's that we were using, so the gpiod lib seems like the best choice. However, example code here (specifically using the get line value example) and here but the ACTIVE value doesn't appear to change when I push the button. These are the same buttons that worked using gpiozero, so I'm assuming I'm doing something wrong in the api implementation. However, I have no baseline to check from because I cannot find any working example code that uses a modern implementation of this library. Maybe it doesn't exist? That is my question:

Does anyone know of any or could anyone write working example code for a button that works with the modern gpiod library that I could reference? If not, could anyone suggest where else I might look besides the "active" value of a pin? Maybe I'm looking at the wrong value and just don't know it?

Would really appreciate any direction that anyone would be willing to offer in this case.

Thank you in advance!

EDIT: I did get my LED's switched over, so I know at least what I'm doing with LED's is working. Thanks to the example LED code here for pointing the way. Buttons don't seem to work this way, however.

utdream
  • 113
  • 1
  • Include simple code examples, not links in your question. – CoderMike Mar 29 '24 at 18:19
  • A code example is exactly what I'm asking for. – utdream Mar 29 '24 at 18:36
  • Include examples of what is not working, I can't find what your referring to in the links. – CoderMike Mar 29 '24 at 18:52
  • I am not sure how else to explain this brother. My code "works", in that I can successfully check the state of a GPIO line, but it's ALWAYS returns "INACTIVE". This is not a matter of non-functional code, it's a matter of what works and what doesn't. I'm asking if anyone knows what actually WORKS. Does that explain the situation better? – utdream Mar 29 '24 at 19:03
  • Looks like there was an interesting discussion about this same thing a few days ago over at Libre Computer: https://hub.libre.computer/t/how-to-control-gpio-via-c-or-python-3/601/43?page=2 – utdream Mar 29 '24 at 19:06
  • 1
    If you have the latest gpiozero (v2.0.1) and use the default library lgpio it should work. If you have code you claim doesn't work post with diagnostics. – Milliways Mar 29 '24 at 20:58
  • 1
    This question could be vastly simplified by simply editing the question to add a copy of the code that does not work. After all the comments and discussion it seems that's not going to happen. Consequently, I’m voting to close this question. – Seamus Mar 29 '24 at 23:35

1 Answers1

1

I have some code using gpiod.

See https://raspberrypi.stackexchange.com/a/145544/8697

gpiod is poorly documented so it is not easy to use but my test worked but not fully tested on Pi5

Milliways
  • 59,890
  • 31
  • 101
  • 209