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
#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
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.
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.
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):
#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:
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)