0

DotStar LED Strip Issue
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

DotStar LED Strip Issue

by Shadow6290 on Sat Feb 27, 2021 10:33 pm

Hey Everyone,

First post here so if it's in the wrong place please let me know. I bought some DotStar LED strips, half meter strips with 72 LED's. It looks gorgeous with some of the animations I've written for it however I'm seeing an issue with the first(last?) LED in the strip. While all other LED's work as programmed the first(last?) LED randomly flashes orange/red (even with two strips daisy chained it is only the very first(last?) LED in the entire chain). I've tested this with two different strips with the same result. Any ideas as to why this is happening? I understand it could be due to how complex my code is at the moment. I'm running this on a Teensy 4.1 with the prop shield, an OLED display, the UDA1334 DAC, and of course the LED strip. I've attached my code, take a look at the animations specifically (yes it's a bit convoluted atm but I plan to clean it up a little more later as this is just a test, I got a little carried away with the animations).

A note on hardware setup, the LED strip and flash chip are on the SPI bus (thanks to the prop shield) and the OLED is on the SPI1 bus. DAC is on I2S2 (I removed the IRQ pin to allow this to work.)

Any help with this would be greatly appreciated!!!
Attachments
Debounce_Button.h
(1002 Bytes) Not downloaded yet
LED_Animations.h
Animation Classes
(5.06 KiB) Not downloaded yet
LED_TEST.ino
Main Sketch
(5.41 KiB) Not downloaded yet

Shadow6290
 
Posts: 12
Joined: Mon Sep 07, 2015 7:41 pm

Re: DotStar LED Strip Issue

by Shadow6290 on Sun Feb 28, 2021 7:07 pm

So I had an odd idea to make the code I'm using think there's one additional LED to write to and the issue goes away....

Here's an example of my Rainbow Stream animation. Why is it the now confirmed last LED in the strip randomly flashes red with this code? buffer size is the number of LED's in the strip. There are 72 in the strip I'm using, when I set the buffer size to 73 the anomaly disappears....

The setup function is called in the sketch setup.
The begin function is called to prepare the buffer for this animation.
The loop function creates the next "frame" for the animation and displays it on the strip.

Code: Select all | TOGGLE FULL SIZE
class Rainbow_Stream{
  private:
  uint16_t hue_factor;
  float stream_factor;
  uint8_t sat;
  uint8_t val;
  int buffer_size;
  int* pixel_buffer;
 
  public:
  void setup(uint16_t hue_factor,uint8_t val,int pixel_buffer[],int buffer_size,float stream_factor=1){
    this->buffer_size=buffer_size;
    this->pixel_buffer=pixel_buffer;
    this->hue_factor=hue_factor;
    this->stream_factor=stream_factor;
    this->val=val;
    this->sat=255;
    for(uint16_t i=0;i<buffer_size;i++){
      pixel_buffer[i]=i*this->hue_factor;
    }
  }
  void begin(){
    for(uint16_t i=0;i<buffer_size;i++){
      pixel_buffer[i]=i*this->hue_factor;
    }
  }
  void loop(Adafruit_DotStar* strip){
    for(uint16_t i=0;i<buffer_size;i++){
      this->pixel_buffer[i]+=(this->hue_factor*stream_factor);
      strip->setPixelColor(i,Adafruit_DotStar::ColorHSV(pixel_buffer[i],sat,val));
    }
    strip->show();
  }
};

Shadow6290
 
Posts: 12
Joined: Mon Sep 07, 2015 7:41 pm

Re: DotStar LED Strip Issue

by Shadow6290 on Mon Mar 01, 2021 2:26 am

I ran one more test with the following code. In this example I have the number of LED's set to 31.

With LED_CS enabled in setup, no SPI transactions, and animation code: LED's 1-31 act as programmed, LED 32 is on and blue.
With LED_CS enabled in setup, no SPI transactions, and fill strip code: LED's 1-31 act as programmed, LED 32 is on and blue.

With LED_CS enabled only when data is sent, no SPI transactions, and animation code: LED's 1-30 act as programmed, LED 31 is pulsing blue.
With LED_CS enabled only when data is sent, no SPI transactions, and fill strip code: LED's 1-30 act as programmed, LED 31 is on and blue.

With LED_CS enabled only when data is sent, SPI transactions enabled, and animation code: LED's 1-30 act as programmed, LED 31 is not outputting the correct color.
With LED_CS enabled only when data is sent, SPI transactions enabled, and strip fill code: LED's 1-30 act as programmed, LED 31 is blinking blue.

What is going on here? Code below.

Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_DotStar.h>
#include <SPI.h>


#define LED_CS 7

uint16_t hue_factor=700;
  float stream_factor=1;
  uint8_t sat=255;
  uint8_t val=255*0.5;
#define buffer_size 31
  int pixel_buffer[buffer_size];
  Adafruit_DotStar strip(buffer_size, DOTSTAR_BRG);

void setup() {
  Serial.begin(9600);
  pinMode(LED_CS, OUTPUT);
  digitalWrite(LED_CS, HIGH);
  strip.begin();
  strip.fill(0x000000);
  strip.show();
  //digitalWrite(LED_CS, LOW);
  for(uint16_t i=0;i<buffer_size;i++){
      pixel_buffer[i]=i*hue_factor;
  }
}

void loop() {

  //SPI.beginTransaction(SPISettings(32000000, MSBFIRST, SPI_MODE0));
  //digitalWrite(LED_CS, HIGH);
  for(int i=0;i<buffer_size;i++){
      pixel_buffer[i]+=(hue_factor*stream_factor);
      strip.setPixelColor(i,strip.gamma32(strip.ColorHSV(pixel_buffer[i],sat,val)));
   }
   //strip.fill(strip.gamma32(strip.ColorHSV(0,0,val)));
   //strip.fill(0xFFFFFF);
   strip.show();
   //digitalWrite(LED_CS, LOW);
   //SPI.endTransaction();
   delay(16);
}

Shadow6290
 
Posts: 12
Joined: Mon Sep 07, 2015 7:41 pm

Re: DotStar LED Strip Issue

by Shadow6290 on Mon Mar 01, 2021 5:40 pm

Finally decided to dig through the source code and:

@note This library is written in pre-SPI-transactions style and needs
some rewriting to correctly share the SPI bus with other devices.


sigh...well hopefully it's as simple as the way I have SPI transactions set up in my sketch. Will update with more.

Shadow6290
 
Posts: 12
Joined: Mon Sep 07, 2015 7:41 pm

Re: DotStar LED Strip Issue

by Shadow6290 on Tue Mar 02, 2021 1:29 am

I switched over to the FastLED library, everything is happy now. If you need to use multiple things on the SPI bus the Adafruit Dotstar library is not set up to handle this, use FastLED if possible.

Shadow6290
 
Posts: 12
Joined: Mon Sep 07, 2015 7:41 pm

Please be positive and constructive with your questions and comments.