vsergeev / python-periphery

A pure Python 2/3 library for peripheral I/O (GPIO, LED, PWM, SPI, I2C, MMIO, Serial) in Linux.
MIT License
519 stars 139 forks source link

GPIO polling issues #61

Closed ericzhao625 closed 1 year ago

ericzhao625 commented 1 year ago

I am trying to use python-periphery to poll a gpio pin on an Arduino Portenta x8 running Ubuntu 22.04.1 LTS.

I am trying out the most basic polling:

from periphery import GPIO

gpio0 = GPIO("/dev/gpiochip5", 0, "in", edge="both")
if gpio0.poll():
  print(gpio0.read_event())

However, the poll function seems to never return regardless of any signals I send to the pin. I'm not sure whether there's some other setup I might be missing, any ideas on what I can try to fix this or debug this would be great! Prior to setting up any polling, the gpio read functions work (reads True when signal is high and False when low).

Another possibly related issue is that upon setting the edge type for a pin (gpio.edge = "both", for example), upon calling the read() function on that pin (gpio.read()), I get this error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/periphery/gpio_cdev1.py", line 323, in read
    fcntl.ioctl(self._line_fd, Cdev1GPIO._GPIOHANDLE_GET_LINE_VALUES_IOCTL, data)
TimeoutError: [Errno 110] Connection timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/dev/wall_panels/bb_ws/src/spc_unit_tester/spc_unit_tester/poll_test.py", line 6, in <module>
    value0 = int(gpio0.read())
  File "/usr/local/lib/python3.10/dist-packages/periphery/gpio_cdev1.py", line 325, in read
    raise GPIOError(e.errno, "Getting line value: " + e.strerror)
periphery.gpio.GPIOError: [Errno 110] Getting line value: Connection timed out

I've also noticed this Errno 110 in other instances, but this is one way I've found to consistently reproduce it. So far the only way I know to regain use of the pin after this is to restart my board, so any help with this would be appreciated, thanks!