pimoroni / pms5003-python

Python library for the PMS5003 particulate sensor
MIT License
51 stars 19 forks source link

Error : "suitable gpiochip not found" and a workaround. #23

Open g7uvw opened 11 months ago

g7uvw commented 11 months ago

I had an Enviro+ running for a year on a Pi ZeroW before I decided to upgrade the OS to latest, and completely broke the operation of the Enviro+.

I did a fresh install of the previous OS version and have almost everything running again except the PMS5003. Pulling down the latest driver from here an running examples/all.py give the following error

Woah there, suitable gpiochip not found!
PIN15: not found - /dev/gpiochip0 (pinctrl-bcm2835)

Re-running install.sh did some magic, got rid of the gpiochip error but then lead to the following error:

  File "/usr/local/lib/python3.9/dist-packages/gpiodevice/__init__.py", line 138, in get_pin
    chip = find_chip_by_pins(pin)
  File "/usr/local/lib/python3.9/dist-packages/gpiodevice/errors.py", line 45, in wrapper
    errors.append(next(i))
  File "/usr/local/lib/python3.9/dist-packages/gpiodevice/__init__.py", line 108, in find_chip_by_pins
    for pin_id in pins:
TypeError: 'int' object is not iterable

The solution seems to be

pip install RPi.GPIO

replace /usr/local/lib/python3.9/dist-packages/pms5003/__init__.py with the one from this commit https://raw.githubusercontent.com/pimoroni/pms5003-python/406801133aaa7489dd4b967890c1cab7a656a4aa/library/pms5003/__init__.py

After that the examples work perfectly.

Gadgetoid commented 11 months ago

You can install a specific version of the library with:

pip install pms5003==0.0.5

Which will retrieve the version before the migration to gpiod/gpiodevice.

An error like PIN15 not found means your Pi probably names it GPIO22 since PIN15 is the name of GPIO22 on a Pi 5-

https://github.com/pimoroni/pms5003-python/blob/c6bdeca3247de6a3c24677d882983101bac724cc/pms5003/__init__.py#L18-L19

Yup. Pin names as provided by gpiod/gpiochip devices are not consistent across Raspberry Pi devices. 😭