Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't identify passed pins as pins on raspberry pi with blinka #19

Closed
Neradoc opened this issue Jan 30, 2022 · 3 comments · Fixed by #25
Closed

Doesn't identify passed pins as pins on raspberry pi with blinka #19

Neradoc opened this issue Jan 30, 2022 · 3 comments · Fixed by #25
Labels
bug Something isn't working good first issue Good for newcomers Hacktoberfest DigitalOcean's Hacktoberfest

Comments

@Neradoc
Copy link
Contributor

Neradoc commented Jan 30, 2022

Running on a Pi 3 (python 3.7.3).

import board
import adafruit_rgbled
rgb = adafruit_rgbled.RGBLED(board.D1, board.D2, board.D3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/.local/lib/python3.7/site-packages/adafruit_rgbled.py", line 110, in __init__
    raise TypeError("Must provide a pin, PWMOut, or PWMChannel.")
TypeError: Must provide a pin, PWMOut, or PWMChannel.

This line does not identify pins correctly:

if hasattr(self._rgb_led_pins[i], "frequency"):
self._rgb_led_pins[i].duty_cycle = 0
elif str(type(self._rgb_led_pins[i])) == "<class 'Pin'>":
self._rgb_led_pins[i] = PWMOut(self._rgb_led_pins[i])
self._rgb_led_pins[i].duty_cycle = 0
else:
raise TypeError("Must provide a pin, PWMOut, or PWMChannel.")

>>> type(board.D1)
<class 'adafruit_blinka.microcontroller.bcm283x.pin.Pin'>

Is there a compatible way to actually test if it's a pin ? Just try/except it ?
In Circuitpython a pin is an instance of microcontroller.Pin (for isinstance), but not currently in Blinka.
If we are going with strings, there's board.D1.__class__.__name__ == "Pin" ?

@ladyada
Copy link
Member

ladyada commented Jan 30, 2022

we dont have pwmout either necessarily, so there might be another test to see if there's a 'value' property? if so, then we can use it as a non-PWM output

@schnee72
Copy link

schnee72 commented Mar 6, 2022

I had the same issue, I imported re and changed line 106 to elif re.match(r"^<class '.*Pin'>$", str(type(self._rgb_led_pins[i]))):. Not sure if it is ideal or not, but works.

You can see the various use cases for the regex here.

@tekktrik
Copy link
Member

Opening this up for Hacktoberfest!

The current method for checking if an input is a Pin is insufficient. A better method would be to check for a value property in the input:

if hasattr(self._rgb_led_pins[i], "value"):

@tekktrik tekktrik added bug Something isn't working good first issue Good for newcomers labels Sep 15, 2022
@adafruit-adabot adafruit-adabot added the Hacktoberfest DigitalOcean's Hacktoberfest label Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers Hacktoberfest DigitalOcean's Hacktoberfest
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants