DotStar strip on RaspberryPi leaves an extra LED on...

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
dcp
 
Posts: 4
Joined: Mon Jul 20, 2020 12:27 pm

DotStar strip on RaspberryPi leaves an extra LED on...

Post by dcp »

I am new to the forum, so please bear with me.
  • I searched the Glowy things topic, but could not find the answer to my question (though I didn't browse all 354 pages).
  • I am using a https://www.adafruit.com/product/2239 Adafruit DotStar Digital LED Strip - Black 60 LED - Per Meter - BLACK strip.
  • I am using a Raspberry Pi (4 Model B Rev 1.2) w/ `sudo pip3 install adafruit-circuitpython-dotstar`and all its dependencies.
  • My test.py code is below.

Code: Select all

#!/usr/bin/env python3
import board, adafruit_dotstar as dotstar, time
n = 17
dots = dotstar.DotStar(board.SCK, board.MOSI, n, brightness=0.2)
for i in range(dots.n):
    dots[i] = (0x66, 0x33, 0x99, )  # Rebecca Purple
time.sleep(1)
dots.deinit()
print('done...')
Everything works as expected for `n <= 16` — The `n` LEDs come on Rebecca Purple for 1s and `dots.deinit()` turns everything off. However, when `n > 16`, the (n + 1)th LED comes on BLUE and `dots.deinit()` does not turn it off. I have tested this for n on [1, 30] and the behavior is consistent.
DotStar 18th LED on after dots.deinit() for n = 17
DotStar 18th LED on after dots.deinit() for n = 17
dotstar-18th-LED.jpg (94.3 KiB) Viewed 200 times
My question is: is there a bug in the `adafruit_dotstar` module for `n > 16`, or am I using it incorrectly?

Thank you.

- dcp

User avatar
dastels
 
Posts: 15662
Joined: Tue Oct 20, 2015 3:22 pm

Re: DotStar strip on RaspberryPi leaves an extra LED on...

Post by dastels »

I've seen cases (with NeoPixels I think) where extra stuff gets shifted out that will end up past the end of the strip. That could account for what you are seeing. The usual usecase is for n to equal the length of the strip so that the extra bits gets shifted off the end and have no effect. When n is less that that, the extra stuff ends up in a pixel.

Does it work correctly when n is 60?

Dave

dcp
 
Posts: 4
Joined: Mon Jul 20, 2020 12:27 pm

Re: DotStar strip on RaspberryPi leaves an extra LED on...

Post by dcp »

Thank you for your response.

I attempted to RTFC to try to debug this behavior. I looked in:
`adafruit_dotstar.py` has the following code:

Code: Select all

 
       # Supply one extra clock cycle for each two pixels in the strip.
        trailer_size = n // 16
        if n % 16 != 0:
            trailer_size += 1
If anywhere in the code `trailer_size` (or a `pixelbuf`ed `trailer_size`?) is used instead of `n`, then could things be off by one? (I couldn't find it.)

Further research shows that, when `n = 17, 33, 49, 65, ...` the 'extra' color cycles between four colors I call blue, cyan, whitish1, & whitish2. And starting with `n = 81` more than one DotStar is left on after `dots.deinit()`!

EDIT: After `n = 81`, a 'whitish' DotStar is followed by the cycle color. And starting with `n = 145` three extra DotStars are left on after `dots.deinit()` (two 'whitish' DotStars followed by the cycle color).

I can set `n` to the number of DotStars, but I would also like to debug this behavior.

User avatar
dastels
 
Posts: 15662
Joined: Tue Oct 20, 2015 3:22 pm

Re: DotStar strip on RaspberryPi leaves an extra LED on...

Post by dastels »

Why do you consider this a bug?

Dave

User avatar
argonblue
 
Posts: 93
Joined: Wed Apr 25, 2012 12:18 am

Re: DotStar strip on RaspberryPi leaves an extra LED on...

Post by argonblue »

It looks like the Adafruit library uses FF (all bits 1) for the trailer. I think the current recommendation is to use all bits 0 for the trailer. Look at cpldcpu dot (banned_word) dot com/2016/12/13/sk9822-a-clone-of-the-apa102/ for lots of useful details about the protocol. If you're setting n to fewer than the number of LEDs in the strip, then the all-ones trailer will get shifted into downstream LEDs, lighting them up.

Basically, if you don't set n equal to the number of LEDs, you should not expect it to behave properly. A small change to the library might make this better, but also might not work in all cases you care about.

dcp
 
Posts: 4
Joined: Mon Jul 20, 2020 12:27 pm

Re: DotStar strip on RaspberryPi leaves an extra LED on...

Post by dcp »

dastels wrote:Why do you consider this a bug?
Because `dots.deinit()` deallocates the DotStar and turns off the LEDs on [0, n - 1], but some of the LEDs (with index >= n) potentially stay on. It is important to me to have a method of totally resetting the DotStar strip.

The work-around of declaring the DotStar to have at least as many elements as there are LEDs will work. Thanks.

dcp
 
Posts: 4
Joined: Mon Jul 20, 2020 12:27 pm

Re: DotStar strip on RaspberryPi leaves an extra LED on...

Post by dcp »

argonblue wrote:...lots of useful details about the protocol.
Thank you! This information is great.
argonblue wrote:A small change to the library might make this better, but also might not work in all cases you care about.
Agreed. The work-around of declaring the DotStar to have at least as many elements as there are LEDs will work. Thanks again.

User avatar
argonblue
 
Posts: 93
Joined: Wed Apr 25, 2012 12:18 am

Re: DotStar strip on RaspberryPi leaves an extra LED on...

Post by argonblue »

Agreed. The work-around of declaring the DotStar to have at least as many elements as there are LEDs will work. Thanks again.
If you use n greater than the number of LEDs you have in the chain, that might also cause trouble, as you noticed. My proposed change would probably fix that.

I'd happy to make a pull request at some point, if I had a strip to test with, but I don't.

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”