Go Down

Topic: Troubles with WS2811 - Only one pixel lighting up (Read 585 times) previous topic - next topic

CheckmateMe

Good evening.

I'm a bit at loss about what to do with my issue.

For a project, I am creating a 'tree' of sorts. In the tree there's three panels with Neopixels in them, which will light up and indicate the life of the tree.

There's a watersensor which also gives an input when you give water to this artificial tree, and besides that there's also a dial so I can change the tree between demo mode (1 minute in which it dies, which means the pixels will turn orange one by one, and then turn off) and normal mode (same process, but in 24 hours).

I'm mostly including all the above info so the code makes more sense.

Either way,

I've snipped apart and soldered together my neopixel strips so they fit in the panels for my tree. I've tested each panel of connections before putting the entire tree together, so I know that each panel works on its own.

On top of this, I've created all the code before taking apart my neopixel strip and soldering the thing, so I know that my code is in order and can be powered the way it's powered right now, which is through the Arduino itself.

However, now that I've put my entire tree together, and run the code, only the very first pixel lights up, and even blinks for a bit (which is not part of the coding).

What I've tried so far (and some other deets):

- As mentioned, each panel has been tested and works, the code runs fine on it

- I've taken the entire thing apart and I've redone all the major wiring (so what connects the three panels), this has not solved anything

- Both the first and second time putting it together, I've checked my leds on connecting them in the correct order

- The example code for a neopixel strip also doesn't change anything when the tree is completely set up

- The PSU shouldn't make a difference. Yes, it's powered through the Arduino, but when I was coding it at the beginning of the project, it worked with the 60 LEDs, even through the Arduino. Right now, 50 LEDs are connected.

- I've even tried taking out the resistor which is advised on when connecting a neopixel strip, doesn't make a difference.

Lastly, this is the code I'm running:

Code: [Select]
#include <Adafruit_NeoPixel.h>
 
#define PIN      6
#define N_LEDS   50
#define periodeMins 1
#define waterGrens 170
static unsigned long lWaitMillis;
const int waterSensor = A0;
const int analogInPin = A1;
const int digitalOutPin = 8;
 
Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_LEDS, PIN, NEO_GRB + NEO_KHZ800);

enum ledStatus {
  green,
  red,
  off
};

bool DEATH = false;
int sensorValue;
int ledCounter;
int waitTime;
int buttonMin;

ledStatus myleds[N_LEDS];


void setup() {
  strip.setBrightness(100);
  strip.begin();
  strip.clear();
  intialise();
}
 
void loop() {

int val = analogRead(analogInPin);
buttonMin = map(val,0,235,0,300);

waitTime = 30000/N_LEDS*buttonMin;
sensorValue = analogRead(waterSensor);
if (sensorValue<=waterGrens && !DEATH){
          intialise();
}
if( (long)( millis() - lWaitMillis ) >= 0)
  {
    // millis is now later than my 'next' time

      if(!DEATH){
         advance();
      }
      if(ledCounter == N_LEDS){
        ledCounter = 0;
      }

    lWaitMillis += waitTime;  // do it again 1 second later
  }
  else
  {
    // millis is still 'before' my 'next' time
    // so I continue waiting

    delay(1);  // one possible thing you can do
  }
 
}

void intialise() {
   digitalWrite(digitalOutPin,HIGH);
   for(int i=0; i<N_LEDS; i++){
    myleds[i] = green;
    strip.setPixelColor(i, strip.Color(5,255,20));
  }
  strip.show();

  int val = analogRead(analogInPin);
  buttonMin = map(val,0,235,0,10);

  waitTime = 30000/N_LEDS*buttonMin;
  lWaitMillis = millis() + waitTime;  // initial setup
 
  ledCounter = 0;
  sensorValue = 0;
}

void advance() {
  switch (myleds[ledCounter]){
    case off:
    myleds[ledCounter] = green;
    //strip.setPixelColor(ledCounter, strip.Color(0,255,0));
    //strip.show();
    gradient(20,255,255);
    ledCounter = ledCounter+1;
    break;

    case green:
    myleds[ledCounter] = red;
    //strip.setPixelColor(ledCounter, strip.Color(255,0,0));
    //strip.show();
    gradient(255,30,15);
    ledCounter = ledCounter+1;
    break;

    case red:
    myleds[ledCounter] = off;
    //strip.setPixelColor(ledCounter, strip.Color(0,0,0));
    //strip.show();
    gradient(0,0,0);
    ledCounter = ledCounter+1;
    if (ledCounter >= N_LEDS){
      DEATH = true;
    }
    break;
  }
}

void gradient(int R2 , int G2, int B2)
{
  int R=(strip.getPixelColor(ledCounter) >> 16) & 0x7f;
  int G=(strip.getPixelColor(ledCounter) >>  8) & 0x7f;
  int B=(strip.getPixelColor(ledCounter)      ) & 0x7f;
  for (int i = 0; i<255; i++)
  {
    if (R<R2){
      R++;
    } else if (R>R2) {
      R--;
    }
    if (G<G2){
      G++;
    } else if (G>G2) {
      G--;
    }
    if (B<B2){
      B++;
    } else if (B>B2) {
      B--;
    }
    strip.setPixelColor(ledCounter, strip.Color(R, G, B));
    strip.show();
  }
}


so to recap:
I've tried a lot, but somehow none of the neopixels except the very first one is lighting up when it's connected like this.

I hope someone can help.

Kind regards,

CheckmateMe

INTP

Don't power it through the Arduino. There is no reason to. When you did what you did, you exacerbated voltage drop on both power and data lines.

Grumpy_Mike

You sure you have the individual LEDs the right way round. Data in and data out pins have to be connected correctly. Normally you get an arrow on the strip to help you.

Go Up