Skip to content

fix clock pin when not using SPI #4

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

Merged
merged 1 commit into from
Nov 2, 2019
Merged

Conversation

schelmo
Copy link
Contributor

@schelmo schelmo commented May 10, 2019

.. else i get weird colors for two different strips

@ladyada
Copy link
Member

ladyada commented May 10, 2019

@kevinjwalters heya i think you wrote the original code, want to test this adjustment?

@kevinjwalters
Copy link

Sure, I'm away from LEDs at the moment but can test this in the latter part of next week.

@kevinjwalters
Copy link

kevinjwalters commented May 14, 2019

The code change makes sense wrt setting data before the clock pulse rises. I've just tested and PR code runs and produces expected colours whereas existing code is buggy wrt colours when non-hardware assisted pins are used.

In detail, on a CPX (M0 based) running 4.0.0 rc1 with library from a recent bundle using a string of 50 "generic" WS2801 on SCL (A4) & SDA (A5):

>>> import adafruit_ws2801
>>> import board
>>> p = adafruit_ws2801.WS2801(board.SCL, board.SDA, 50, brightness=1.0)
>>> p[0:3] = [(5,0,0)] *3
>>> p[99] = (5,0,0)
>>> p[59] = (5,0,0)
>>> p[49] = (5,0,0)
>>> p[50] = (5,0,0)
>>> p[49] = (0,0,5)
>>> type(p._spi)
<class 'SPI'>

Output is as expected and hardware is being used.

Changing pins to A2 for clock and A3 for data to force a bitbang approach from library:

>>> import adafruit_ws2801
>>> import board
>>> p = adafruit_ws2801.WS2801(board.A2, board.A3, 50, brightness=1.0)
>>> type(p._spi)
<class 'NoneType'>
>>> print("this is with library without #4")
this is with library without #4
>>> p[0:3] = [(5,0,0)] *3  ### first three green, not red!

>>> p[0:5] = [(0,5,0)] *5  ### first five blue, not green!

>>> p[0:5] = [(0,0,5)] *5  ### 1st blue, 2nd-5th pink (magenta?), 6th red

>>> p[0:5] = [(0,0,5)] *5
>>> p[0:5] = [(0,0,5)] *5
>>> p[0:5] = [(0,0,5)] *5  ### no change

And now with the new library from this PR (note file is temporary name of adafruit_ws2801_pr4.py):

>>> import adafruit_ws2801_pr4
>>> import board
>>> p = adafruit_ws2801_pr4.WS2801(board.A2, board.A3, 50, brightness=1.0)
>>> type(p._spi)
<class 'NoneType'>
>>> p[0:5] = [(5,0,0)] *5
>>> p[0:5] = [(0,5,0)] *5
>>> p[0:5] = [(0,0,5)] *5
>>> p[0:5] = [(0,0,2)] *5
>>> p[0:5] = [(0,0,1)] *5

>>> p[0:50] = [(0,0,1)] *50
>>> p[0:50] = [(1,0,0)] *50
>>> p[0:50] = [(0,0,0)] *50

All RGB LEDs as expected, i.e. correct colours.

(Note: for anyone unfamiliar with WS2801, first LED often changes colour rather randomly if clock/data are not connected to anything or are being connected manually to a circuit.)

Copy link
Collaborator

@makermelissa makermelissa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was experiencing the weird colors issue as well. Testing with this change fixed it.

@makermelissa makermelissa merged commit 8ce2d2d into adafruit:master Nov 2, 2019
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Nov 2, 2019
Updating https://github.com/adafruit/Adafruit_CircuitPython_WS2801 to 0.9.4 from 0.9.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_WS2801#4 from schelmo/master
  > Merge pull request adafruit/Adafruit_CircuitPython_WS2801#7 from makermelissa/master
  > Merge pull request adafruit/Adafruit_CircuitPython_WS2801#5 from adafruit/dherrada-patch-1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants