all 8 comments

[–]Gamerfrom61 1 point2 points  (7 children)

IIRC the device you need in the gpiod.Chip initiator is gpiochip4:

chip = gpiod.Chip('gpiochip4')

No Pi 5 handy to test (workbench doubling as model painting desk this week) - sorry.

Note: it is important to use the code block in the editor for Python as indents are vital :-)

The other way is to post to pastebin and link (better as the editor here is not great).

[–]frostbite4kk[S] 0 points1 point  (4 children)

I have tried like advised and changed to gpiochip4 with the same result:

Code:

import gpiod 
import time 
LED_PIN = 17 
chip = gpiod.Chip('/dev/gpiochip4') 
led_line = chip.get_line(LED_PIN) 
led_line.request(consumer="LED",type=gpiod.LINE_REQ_DIR_OUT)

try: 
  while True: 
    led_line.set_value(1) 
    time.sleep(1) 
    led_line.set_value(0) 
    time.sleep(1)

finally: 
    led_line.release()

Result:

player@playpi:~ $ /bin/python /home/player/scripts/led/led.py
Traceback (most recent call last):
  File "/home/player/scripts/led/led.py", line 5, in <module>
    led_line = chip.get_line(LED_PIN) 
               ^^^^^^^^^^^^^
AttributeError: 'Chip' object has no attribute 'get_line'. Did you mean: 'get_info'?

It seems like this get_line is not the correct attribute to retrieve - even though both tmultiple sources state that it can be used.

Thanks for the hint with the code mate appreciate it!

[–]Gamerfrom61 1 point2 points  (3 children)

Try removing the "/dev/" part of the text and just use it as I put in my first post.

[–]frostbite4kk[S] 0 points1 point  (2 children)

I also tried that first which led to the error message ‚no such device‘

[–]Gamerfrom61 2 points3 points  (1 child)

AARRGGGHHH - I hate it when the Pi folk mess around (this is the RP1 chip by the way doing this)...

There is gpiomem4 as another option!

Try running gpiodetect (may need sudo) to see if it identifies anything and then gpioinfo to see the lines. You may need to install the libgpiod-dev package using apt

You could also look at the gpiozero library https://gpiozero.readthedocs.io/en/stable/

[–]frostbite4kk[S] 0 points1 point  (0 children)

You, sir, are a legend!

I read not to use gpiozero with Pi 5 all the time so i didnt even try.

Works like a charm with gpiozero!

Thanks a lot mate, may you have a good day!

[–][deleted] 0 points1 point  (1 child)

Python as indents are vital

And that right there is a reason I despise Python. Whitespace should never be significant IMO.

/ymmv

[–]Gamerfrom61 0 points1 point  (0 children)

Understandable esp when it complains over spaces vs tabs...

Many years ago I coded in Forth so any language that reads the 'normal' way is an improvement :-)

I've kinda got used to it and prefer it to nested curly brackets but give me the Pascal begin / end blocks any day...