libgpiod icon indicating copy to clipboard operation
libgpiod copied to clipboard

Operation not permitted for set_value()

Open ActiveTutorial opened this issue 1 year ago • 2 comments

For this script:

import gpiod

chipname = "gpiochip0" line_offset_16 = 16 line_offset_26 = 26

chip = gpiod.Chip(chipname)

line_16 = chip.get_line(line_offset_16)

line_26 = chip.get_line(line_offset_26)

try: events = line_26.request(consumer="test_continuity", type=gpiod.LINE_REQ_EV_BOTH_EDGES) line_16.set_value(1) time.sleep(0.1) state = line_26.get_value() if state == 1: print("Continuity detected between pin 16 and pin 26.") else: print("No continuity detected between pin 16 and pin 26.")

finally: line_16.release() line_26.release() chip.close()

I get this error: ~ $ sudo python3 contentest.py Traceback (most recent call last): File "/home/active/contentest.py", line 21, in line_16.set_value(1) PermissionError: [Errno 1] Operation not permitted

This is run on Raspberry pi 5 and raspberrypios There is no Explonation for this anywhere on the intenernet and i cant belive a 70$ device can not do its main purpose.

ActiveTutorial avatar Jun 10 '24 09:06 ActiveTutorial

Can you run this script through strace like: strace -f -o/tmp/output.txt <your script> and attached the output here?

brgl avatar Jun 10 '24 12:06 brgl

You never request line_16, only line_26.

Add

line_16.request(consumer="test continuity", type=gpiod.LINE_REQ_DIR_OUT, default_val=0)

before trying to set the value. Note that the line will be set to the default_val (0 in my example) when requested.

Admittedly the error could be better - "PermissionError" when trying to use an unrequested line isn't very helpful.

warthog618 avatar Jun 15 '24 15:06 warthog618

I totally forgot about me posting about this. @brgl sorry for ignoring you and @warthog618 thanks for the solution.

ActiveTutorial avatar Oct 12 '24 23:10 ActiveTutorial