-
Notifications
You must be signed in to change notification settings - Fork 8
Add support for multiple chained boards #7
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tested on hardware, but code looks good and it's well-documented.
Yep, will do. Pretty sure I've got two boards here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something's off here, at least on CPython / the Pi. Doesn't seem to control pins 21-23 on the second board.
@@ -50,6 +50,8 @@ | |||
# access is by design for the internal class. | |||
#pylint: disable=protected-access | |||
|
|||
_CHANNELS = 24 | |||
_STOREBYTES = _CHANNELS + _CHANNELS/2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_STOREBYTES = _CHANNELS + _CHANNELS/2 | |
_STOREBYTES = int(_CHANNELS + _CHANNELS/2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...otherwise we wind up with a float here, at least on CPython.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for finding this one! I hoped to avoid this pitfall by rephrasing _STOREBYTES = _CHANNELS * 1.5
but forgot about Python 3 division rules. So here is my fix:
_STOREBYTES = _CHANNELS + _CHANNELS/2 | |
_STOREBYTES = _CHANNELS + _CHANNELS//2 |
which I find less bulky, but also a bit less clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had time to test my own code now. Sincere apologies for being so boastful to think I could do without.
Improvements to the library to allow for Python's negative index feature on the board. Changed example file because the last LED was on after each cycle.
""" | ||
assert 0 <= key <= 23 | ||
assert 0 <= key < _CHANNELS * self._n |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To allow for Python's negative indices (adressing elements from the rear end of an array), the suggested change is needed. Otherwise the negative index adressing near the end of tlc5947_chain.py would fail.
assert 0 <= key < _CHANNELS * self._n | |
if key < 0: # allow reverse adressing with negative index | |
key = key + _CHANNELS * self._n | |
assert 0 <= key < _CHANNELS * self._n |
If auto_write is enabled (the default) then the chip PWM state will | ||
immediately be updated too, otherwise you must call write to update | ||
the chip with the new PWM state. | ||
""" | ||
assert 0 <= key <= 23 | ||
assert 0 <= key < _CHANNELS * self._n |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here - enable Python's negative array index feature:
assert 0 <= key < _CHANNELS * self._n | |
if key < 0: # allow reverse adressing with negative index | |
key = key + _CHANNELS * self._n | |
assert 0 <= key < _CHANNELS * self._n |
# (note this is NOT the 12-bit value supported by the chip natively) and the | ||
# PWM channel will be updated. | ||
|
||
# With one RGB LED hooked up to pins 0, 1, and 2, AND |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplify comment.
# With one RGB LED hooked up to pins 0, 1, and 2, AND | |
# Hook up one RGB LED to pins 0, 1, and 2, AND connect another RGB LED | |
# to pins 21, 22 and 23 of the last chained driver. |
# PWM channel will be updated. | ||
|
||
# With one RGB LED hooked up to pins 0, 1, and 2, AND | ||
# with another RGB LED hooked up to pins 21, 22 and 23 of the last chained driver, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove.
# with another RGB LED hooked up to pins 21, 22 and 23 of the last chained driver, |
|
||
# With one RGB LED hooked up to pins 0, 1, and 2, AND | ||
# with another RGB LED hooked up to pins 21, 22 and 23 of the last chained driver, | ||
# cycle the red, green, and blue pins of LED one up and down, and the other vice versa: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to below, and change to reflect code changes.
# cycle the red, green, and blue pins of LED one up and down, and the other vice versa: |
while True: | ||
for (pinA, pinZ) in ((redA, redZ), (greenA, greenZ), (blueA, blueZ)): | ||
# Brighten: | ||
print("LED A up, LED Z down") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With current code the second LED will stay lit after the cycle. Proposed change will brighten the LEDs one after the other, then dim them again, repeating for each channel:
print("LED A up, LED Z down") | |
print("LED A up") |
print("LED A up, LED Z down") | ||
for pwm in range(start_pwm, end_pwm, step): | ||
pinA.duty_cycle = pwm | ||
pinZ.duty_cycle = end_pwm - pwm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove.
pinZ.duty_cycle = end_pwm - pwm |
pinA.duty_cycle = pwm | ||
pinZ.duty_cycle = end_pwm - pwm | ||
# tlc5947.write() # see NOTE below | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now brighten the LED on the last pins of the last driver board:
print("LED Z up") | |
for pwm in range(start_pwm, end_pwm, step): | |
pinZ.duty_cycle = pwm | |
# tlc5947.write() # see NOTE below | |
# tlc5947.write() # see NOTE below | ||
|
||
# Dim: | ||
print("LED A down, LED Z up") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dimming both LEDs now:
print("LED A down, LED Z up") | |
print("LED A and LED Z down") |
print("LED A down, LED Z up") | ||
for pwm in range(end_pwm, start_pwm, 0 - step): | ||
pinA.duty_cycle = pwm | ||
pinZ.duty_cycle = end_pwm - pwm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just do the same with both LEDs:
pinZ.duty_cycle = end_pwm - pwm | |
pinZ.duty_cycle = pwm |
This is where me in the middle kind of falls apart. @ArthurDent62 Do you feel like you could PR this yourself at this point? |
@caternuson Well, see me convinced. The multiple edit sure was over the top. I have opened a new PR with all the related changes included. I've also extended the chain example to test all the available channels one by one. So you could delete this PR when you find mine. Thanks! |
Closing in favor of #8 |
PRing on behalf of forum poster:
https://forums.adafruit.com/viewtopic.php?f=60&t=140130&p=709433#p709428
Their code simply copy-pasted here.