Go Down

Topic: Feeling blue with WS2182b LEDs! (Read 655 times) previous topic - next topic

KieranW

Good day.
Hope this is the right place for this.

I'm having an issue with my addressable LED.

I'm using a DFRobot Beetle, a board that is programmed like an Arduino Leonardo, and I want to use it to give the data for just a single addressable LED and later an LED ring.

I initially tried wiring the single LED directly to the data output on the Beetle, and the same with power and ground. For some reason I could only get the LED to display blue.

After a quick google, I found lots of posts telling me I was an idiot (and rightly so),  so have now put in a resistor (270 ohms) in series on the data line and a capacitor (100 uF, 10V) in parallel across the +ve and gnd.

Despite all this, I can only get the LED to display blue! Any other RGB values where b=0 results in the LED remaining off.
Any suggestions why this could be?

I've attached images of the setup (pretty simple) and a closer view of the LED wiring. Below is the code I am using to test the LED.

 All criticisms welcome, I never learnt electronics and I've been learning this as I go along!


Code: [Select]
#include <Adafruit_NeoPixel.h>

#ifdef __AVR__
  #include <avr/power.h>
#endif

#define stripPIN           11
#define stripPIXELS     1

Adafruit_NeoPixel strip = Adafruit_NeoPixel(stripPIXELS, stripPIN, NEO_RGB + NEO_KHZ800);

int led = 13;

void setup() {
  pinMode(led, OUTPUT);
  digitalWrite(led, HIGH);
 
  strip.begin();
  strip.setBrightness(255);
  strip.show();

  strip.fill((0,0,0));
  strip.show();
  delay(1000);

}

void loop() {
  strip.fill((0,0,0));
  strip.show();
  digitalWrite(led, HIGH);
  delay(1000);
  strip.fill((255,0,0));
  strip.show();
  digitalWrite(led,LOW);
  delay(1000);
 
}



KieranW

Forgot to attach these!

boolrules

I initially tried wiring the single LED directly to the data output on the Beetle, and the same with power and ground. For some reason I could only get the LED to display blue.
This could be no + connection from your PS.

Paul__B

Forgot to attach these!



So you did!

I can't see the solder on your "beetle".  But for that distance between the two parts, the 270 Ohm resistor and capacitor are actually irrelevant.  Are you sure that data pin is in fact, pin 11?

alesam

Try to replace loop with this code:

Code: [Select]

void loop() {

  strip.fill((255,0,0));
  strip.show();
  delay(200);
  strip.fill((0,255,0));
  strip.show();
  delay(200);
  strip.fill((0,0,255));
  strip.show();
  delay(200);
}

Grumpy_Mike

#5
Mar 03, 2019, 08:54 am Last Edit: Mar 03, 2019, 08:57 am by Grumpy_Mike
I can't see the solder on your "beetle".  But for that distance between the two parts, the 270 Ohm resistor and capacitor are actually irrelevant.  Are you sure that data pin is in fact, pin 11?
Yes Paul has it right you need a soldered connection pushing the wires in a hole like that will not cut it. Also you have connected pin 9 not 11.

The 270R is for protection for cases where you power up the Arduino before you power the LED, and the capacitor is for when you have a large number of LEDs, just driving one LED you can do straight off. Each LED needs a maximum of 60mA, so this can quickly add up to be too much for your power supply.

Paul__B

The 270R is for protection for cases where you power up the Arduino before you power the LED,
Yes, I actually noted that but did not mention it as it does not apply in this particular case.

(Except it might apply if the connections are not soldered.  :smiley-lol:  )

PaulRB

#7
Mar 03, 2019, 01:44 pm Last Edit: Mar 03, 2019, 01:44 pm by PaulRB
This is wrong:
Code: [Select]
  strip.fill((255,0,0));
should be:
Code: [Select]
  strip.fill(strip.color(255,0,0));

KieranW

#8
Mar 03, 2019, 02:21 pm Last Edit: Mar 03, 2019, 02:56 pm by KieranW
Yes Paul has it right you need a soldered connection pushing the wires in a hole like that will not cut it. Also you have connected pin 9 not 11.

The 270R is for protection for cases where you power up the Arduino before you power the LED, and the capacitor is for when you have a large number of LEDs, just driving one LED you can do straight off. Each LED needs a maximum of 60mA, so this can quickly add up to be too much for your power supply.
Ok thanks I'll try soldering it. Is that why I only get Blue?
Truth be told the code originallysaid pin 11 but I did some further testing after taking the photo - trust me that when I was encountering this problem it was connected to the right pin!
So is the capacitor and resistor redundant in this case?

Try to replace loop with this code:

Code: [Select]

void loop() {

  strip.fill((255,0,0));
  strip.show();
  delay(200);
  strip.fill((0,255,0));
  strip.show();
  delay(200);
  strip.fill((0,0,255));
  strip.show();
  delay(200);
}

I've tried this before. No matter that values I work in, if the b value is 0 there is no light!

KieranW

#9
Mar 03, 2019, 02:59 pm Last Edit: Mar 03, 2019, 03:03 pm by KieranW Reason: Update
This is wrong:
Code: [Select]
 strip.fill((255,0,0));
should be:
Code: [Select]
 strip.fill(strip.color(255,0,0));
Attempting this gives the compile error "class Adafruit_NeoPixel has no member named 'color'"

Edit: Found the issue, it's strip.Color not color.

PaulRB

Edit: Found the issue, it's strip.Color not color.
Oh yes, you are correct! A small slip on Adafruit's part. Class methods conventionally start with a lower case letter.

But... does your strip still have "the blues"?

KieranW

Oh yes, you are correct! A small slip on Adafruit's part. Class methods conventionally start with a lower case letter.

But... does your strip still have "the blues"?
Nope! That's fixed it! Thanks everyone :)

Why does this work?

PaulRB

The strip.Colour(red, green, blue) method returns an unsigned long integer with the r, g, b components packed inside it. This is the data format that other methods like strip.fill() expect.

When you put "(r, g, b)", without the method name in front, because of a rather peculiar feature of C language, it is actually valid syntax, so no error messages from the compiler. What it means is: evaluate 'r'; discard the result; evaluate 'g'; discard that aswell; then evaluate 'b' and that's the resulting value. So all the strip.fill() gets is the blue part. Far be it from me to question the wisdom of Mr Ritchie, but there you go!

Paul__B

So is the capacitor and resistor redundant in this case?
The capacitor is - sort of - redundant in this case because you are using only one LED which will draw no more than 60 mA - in repetitive pulses and the bypass capacitor on the "Beetle" - wherever it is - can probably handle that.

But bypass capacitors are critical to the operation of digital logic devices and every one of those "addressable" LEDs is a digital logic device generating PWM pulses which is why the board has a bypass capacitor for each LED - just one in this case.  With a whole lot in service, a "bulk" bypass capacitor is desirable.

The resistor has two functions.  One is to suppress transients when there is a long data line between the microcontroller and the LEDs, not the case here when it is merely a couple of inches.  The other is to protect the LED against not being powered when the microcontroller is trying to drive it.  As long as your connections are soldered, the LED here will always be powered when the "Beetle" is, but since longer LED strips require their own power supply, you may not be using the same power supply for the microcontroller - though you usually should.

KieranW

The strip.Colour(red, green, blue) method returns an unsigned long integer with the r, g, b components packed inside it. This is the data format that other methods like strip.fill() expect.

When you put "(r, g, b)", without the method name in front, because of a rather peculiar feature of C language, it is actually valid syntax, so no error messages from the compiler. What it means is: evaluate 'r'; discard the result; evaluate 'g'; discard that aswell; then evaluate 'b' and that's the resulting value. So all the strip.fill() gets is the blue part. Far be it from me to question the wisdom of Mr Ritchie, but there you go!
Aha thanks! That makes a lot of sense.

The capacitor is - sort of - redundant in this case because you are using only one LED which will draw no more than 60 mA - in repetitive pulses and the bypass capacitor on the "Beetle" - wherever it is - can probably handle that.

But bypass capacitors are critical to the operation of digital logic devices and every one of those "addressable" LEDs is a digital logic device generating PWM pulses which is why the board has a bypass capacitor for each LED - just one in this case.  With a whole lot in service, a "bulk" bypass capacitor is desirable.

The resistor has two functions.  One is to suppress transients when there is a long data line between the microcontroller and the LEDs, not the case here when it is merely a couple of inches.  The other is to protect the LED against not being powered when the microcontroller is trying to drive it.  As long as your connections are soldered, the LED here will always be powered when the "Beetle" is, but since longer LED strips require their own power supply, you may not be using the same power supply for the microcontroller - though you usually should.
That's really helpful - thank you. If you don't mind, while you're answering question; would you recommend a capacitor and/or resistor for an LED ring of 24 addressable LEDS at a similarly short distance from the controller? They will be from the same power source and commonly grounded.

Go Up