Go Down

Topic: WS2812B not working (Read 2472 times) previous topic - next topic

Fjallbacka

Mar 12, 2017, 10:11 pm Last Edit: Mar 12, 2017, 10:16 pm by Fjallbacka
Hi, I want to make an ambilight system but I couldn't make it work because I don't understand how does this type of leds work. So now in order to understand a bit more I'm just trying with a single led to make it work with my arduino nano.

I have connected the 5V and GND to the arduino respective pinouts, and the DATA to digital pin 6 (and used a 100ohm) resistor which was suggested. I am using the fastled library and I have this sketch uploaded to the arduino nano

Code: [Select]
#include "FastLED.h"

// How many leds in your strip?
#define NUM_LEDS 1
#define DATA_PIN 6
#define COLOR_ORDER RGB

// Adalight sends a "Magic Word" (defined in /etc/boblight.conf) before sending the pixel data
uint8_t prefix[] = {'A', 'd', 'a'}, hi, lo, chk, i;

// Baudrate, higher rate allows faster refresh rate and more LEDs (defined in /etc/boblight.conf)
#define serialRate 115200

// Define the array of leds
CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
 
  // initial RGB flash
  LEDS.showColor(CRGB(255, 0, 0));
  delay(500);
  LEDS.showColor(CRGB(0, 255, 0));
  delay(500);
  LEDS.showColor(CRGB(0, 0, 255));
  delay(500);
  LEDS.showColor(CRGB(0, 0, 0));

  Serial.begin(serialRate);
  Serial.print("Ada\n"); // Send "Magic Word" string to host

}

void loop() {
  // wait for first byte of Magic Word
  for (i = 0; i < sizeof prefix; ++i) {
waitLoop: while (!Serial.available()) ;;
    // Check next byte in Magic Word
    if (prefix[i] == Serial.read()) continue;
    // otherwise, start over
    i = 0;
    goto waitLoop;
  }

  // Hi, Lo, Checksum

  while (!Serial.available()) ;;
  hi = Serial.read();
  while (!Serial.available()) ;;
  lo = Serial.read();
  while (!Serial.available()) ;;
  chk = Serial.read();

  // if checksum does not match go back to wait
  if (chk != (hi ^ lo ^ 0x55))
  {
    i = 0;
    goto waitLoop;
  }

  memset(leds, 0, NUM_LEDS * sizeof(struct CRGB));
  // read the transmission data and set LED values
  for (uint8_t i = 0; i < NUM_LEDS; i++) {
    byte r, g, b;
    while (!Serial.available());
    r = Serial.read();
    while (!Serial.available());
    g = Serial.read();
    while (!Serial.available());
    b = Serial.read();
    leds[i].r = r;
    leds[i].g = g;
    leds[i].b = b;
  }
  // shows new values
  FastLED.show();
}


But the led is not blinking or doing nothing. What could be possibly wrong? Thanks

Qdeathstar

hi. Can you take a picture of how you have it wired. And a close up of the strip. You have to connect the data cable to the right end. There is an input and output. You need to connect to the input side.
A creaking creeping shadow
stiff against the freezing fog
glares at a tickless watch.

Time has failed him -- all things shall pass.

Fjallbacka

hi. Can you take a picture of how you have it wired. And a close up of the strip. You have to connect the data cable to the right end. There is an input and output. You need to connect to the input side.
I was able to make it turn on but it just stays white, the colors aren't changing or anything. The most weird thing is that when I unplug the arduino from the computer and plug it back again the led won't turn on, I need to move, unplug the 5v, ground and data pins and sometimes after doing this it turns back on. It is driving me mad! How is it possible that I can't achieve such a simple task!

I've used even a simpler sketch, the blinking example of the fastled library which is this (but no blinks at all):
Code: [Select]
#include "FastLED.h"

// How many leds in your strip?
#define NUM_LEDS 1

// For led chips like Neopixels, which have a data line, ground, and power, you just
// need to define DATA_PIN.  For led chipsets that are SPI based (four wires - data, clock,
// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
#define DATA_PIN 5
//#define CLOCK_PIN 13

// Define the array of leds
CRGB leds[NUM_LEDS];

void setup() {
      // Uncomment/edit one of the following lines for your leds arrangement.
      FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
}

void loop() {
  // Turn the LED on, then pause
  leds[0] = CRGB::Red;
  FastLED.show();
  delay(500);
  // Now turn the LED off, then pause
  leds[0] = CRGB::Black;
  FastLED.show();
  delay(500);
}


I've also tried with an arduino uno, here are the wirings and the led picture:

larryd

#3
Mar 13, 2017, 02:38 am Last Edit: Mar 13, 2017, 02:39 am by LarryD
It appears you are connected to the output pin 'not' the input.


.
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

Qdeathstar

Hi.

You have got the green wire (data) hooked up to do (data out) you need to connect it to di (data in) it would be on the other side, typically.
A creaking creeping shadow
stiff against the freezing fog
glares at a tickless watch.

Time has failed him -- all things shall pass.

Fjallbacka

#5
Mar 13, 2017, 12:32 pm Last Edit: Mar 13, 2017, 01:03 pm by Fjallbacka
I never thought I could be that stupid. Thanks, it's working now.

EDIT: Now that I got a single led to work I tried with the strip attached to my TV (I should've done after testing them, I hope there's not any burned LED) but it doesn't work. I'll leave here picture of my connections tell me what am I doing wrong. This time I made sure that I've used the DIN pin not the DO.


The GND is both connected to GND on the PSU and on the arduino, the 5V just to the PSU, and the DIN has a 100ohm resistor too that just goes to the arduino.
I've tested the PSU and it's working properly (5.2V output)

larryd

#6
Mar 13, 2017, 05:09 pm Last Edit: Mar 13, 2017, 05:11 pm by LarryD
That ground is the chassis GND.

What do you measure between V+ and V-  ?



What does the sticker on the power supply read?

.
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

Fjallbacka

I've got it to work by using the V- rail for the GND connections. And yeah the middle one was earth, I though it was ground but it's not the same.

larryd

You are an expert now.


.
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

Go Up