Programowalne LEDy z Aliexpress

Posted on Fri 09 June 2023 in Hack • [7 min read]

Adnotacja z 2026: artykuł nigdy nie dokończony

Kolejny raz przekonałem się, że jeśli chcę czegoś nauczyć swoje dzieci, nie powinienem zbytnio oszczędzać.

Mój młodszy syn chce zbudować sobie programowalne podświetlenie z LED-ów. Zamiast kupić sprawdzone, np. z Adafruit, przyjanuszyłem i kupiłem na Aliexpress.

Dostawa zajęła ok. trzech tygodni więc prawie o nich zapomnieliśmy. Według opisu miały to być światełka typu WD-2813. O! My naiwni!

Arduino Nano klon z CH340, potrzebny sterownik.

Parametry:

Mikrokontroler: Atmega328 / 16MHz

Pamięć:Flash 32kB, EEPROM 1kB, SRAM 2kB

Konwerter:USB RS232  (CH340)

Złącze: Mini USB

Interfejs: SPI,UART,I2C

Wejścia: Analogowe 8 szt.

Porty: 14 I/O  6x PWM

Zasilanie: 5V

Wymiary: 44mm x 18mm

Moduł niezlutowany - do samodzielnego montażu.

Biblioteki: Adafruit i Fastled

https://github.com/dmadison/Adalight-FastLED

Biblioteka Fastled jest najlepsza.

https://www.instructables.com/Cheap-Ambilight-Tutorial-for-PC-Using-Arduino/

/*
 *  Project     Adalight FastLED
 *  @author     David Madison
 *  @link       github.com/dmadison/Adalight-FastLED
 *  @license    LGPL - Copyright (c) 2017 David Madison
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include <Arduino.h>

// --- General Settings
const uint16_t
    Num_Leds   =  58;         // strip length
const uint8_t
    Brightness =  255;        // maximum brightness

// --- FastLED Setings
#define LED_TYPE     WS2813  // led strip type for FastLED
#define COLOR_ORDER  GRB      // color order for bitbang
#define PIN_DATA     3        // led data output pin
// #define PIN_CLOCK  7       // led data clock pin (uncomment if you're using a 4-wire LED type)

// --- Serial Settings
const unsigned long
    SerialSpeed    = 115200;  // serial port speed
const uint16_t
    SerialTimeout  = 60;      // time before LEDs are shut off if no data (in seconds), 0 to disable

// --- Optional Settings (uncomment to add)
#define SERIAL_FLUSH          // Serial buffer cleared on LED latch
// #define CLEAR_ON_START     // LEDs are cleared on reset

// --- Debug Settings (uncomment to add)
// #define DEBUG_LED 13       // toggles the Arduino's built-in LED on header match
// #define DEBUG_FPS 8        // enables a pulse on LED latch

// --------------------------------------------------------------------

#include <FastLED.h>

CRGB leds[Num_Leds];
uint8_t * ledsRaw = (uint8_t *)leds;

// A 'magic word' (along with LED count & checksum) precedes each block
// of LED data; this assists the microcontroller in syncing up with the
// host-side software and properly issuing the latch (host I/O is
// likely buffered, making usleep() unreliable for latch). You may see
// an initial glitchy frame or two until the two come into alignment.
// The magic word can be whatever sequence you like, but each character
// should be unique, and frequent pixel values like 0 and 255 are
// avoided -- fewer false positives. The host software will need to
// generate a compatible header: immediately following the magic word
// are three bytes: a 16-bit count of the number of LEDs (high byte
// first) followed by a simple checksum value (high byte XOR low byte
// XOR 0x55). LED data follows, 3 bytes per LED, in order R, G, B,
// where 0 = off and 255 = max brightness.

const uint8_t magic[] = {
    'A','d','a'};
#define MAGICSIZE  sizeof(magic)

// Check values are header byte # - 1, as they are indexed from 0
#define HICHECK    (MAGICSIZE)
#define LOCHECK    (MAGICSIZE + 1)
#define CHECKSUM   (MAGICSIZE + 2)

enum processModes_t {Header, Data} mode = Header;

int16_t c;  // current byte, must support -1 if no data available
uint16_t outPos;  // current byte index in the LED array
uint32_t bytesRemaining;  // count of bytes yet received, set by checksum
unsigned long t, lastByteTime, lastAckTime;  // millisecond timestamps

void headerMode();
void dataMode();
void timeouts();

// Macros initialized
#ifdef SERIAL_FLUSH
    #undef SERIAL_FLUSH
    #define SERIAL_FLUSH while(Serial.available() > 0) { Serial.read(); }
#else
    #define SERIAL_FLUSH
#endif

#ifdef DEBUG_LED
    #define ON  1
    #define OFF 0

    #define D_LED(x) do {digitalWrite(DEBUG_LED, x);} while(0)
#else
    #define D_LED(x)
#endif

#ifdef DEBUG_FPS
    #define D_FPS do {digitalWrite(DEBUG_FPS, HIGH); digitalWrite(DEBUG_FPS, LOW);} while (0)
#else
    #define D_FPS
#endif

void setup(){
    #ifdef DEBUG_LED
        pinMode(DEBUG_LED, OUTPUT);
        digitalWrite(DEBUG_LED, LOW);
    #endif

    #ifdef DEBUG_FPS
        pinMode(DEBUG_FPS, OUTPUT);
    #endif

    #if defined(PIN_CLOCK) && defined(PIN_DATA)
        FastLED.addLeds<LED_TYPE, PIN_DATA, PIN_CLOCK, COLOR_ORDER>(leds, Num_Leds);
    #elif defined(PIN_DATA)
        FastLED.addLeds<LED_TYPE, PIN_DATA, COLOR_ORDER>(leds, Num_Leds);
    #else
        #error "No LED output pins defined. Check your settings at the top."
    #endif

    FastLED.setBrightness(Brightness);

    #ifdef CLEAR_ON_START
        FastLED.show();
    #endif

    Serial.begin(SerialSpeed);
    Serial.print("Ada\n"); // Send ACK string to host

    lastByteTime = lastAckTime = millis(); // Set initial counters
}

void loop(){
    t = millis(); // Save current time

    // If there is new serial data
    if((c = Serial.read()) >= 0){
        lastByteTime = lastAckTime = t; // Reset timeout counters

        switch(mode) {
            case Header:
                headerMode();
                break;
            case Data:
                dataMode();
                break;
        }
    }
    else {
        // No new data
        timeouts();
    }
}

void headerMode(){
    static uint8_t
        headPos,
        hi, lo, chk;

    if(headPos < MAGICSIZE){
        // Check if magic word matches
        if(c == magic[headPos]) {headPos++;}
        else {headPos = 0;}
    }
    else{
        // Magic word matches! Now verify checksum
        switch(headPos){
            case HICHECK:
                hi = c;
                headPos++;
                break;
            case LOCHECK:
                lo = c;
                headPos++;
                break;
            case CHECKSUM:
                chk = c;
                if(chk == (hi ^ lo ^ 0x55)) {
                    // Checksum looks valid. Get 16-bit LED count, add 1
                    // (# LEDs is always > 0) and multiply by 3 for R,G,B.
                    D_LED(ON);
                    bytesRemaining = 3L * (256L * (long)hi + (long)lo + 1L);
                    outPos = 0;
                    memset(leds, 0, Num_Leds * sizeof(struct CRGB));
                    mode = Data; // Proceed to latch wait mode
                }
                headPos = 0; // Reset header position regardless of checksum result
                break;
        }
    }
}

void dataMode(){
    // If LED data is not full
    if (outPos < sizeof(leds)){
        ledsRaw[outPos++] = c; // Issue next byte
    }
    bytesRemaining--;

    if(bytesRemaining == 0) {
        // End of data -- issue latch:
        mode = Header; // Begin next header search
        FastLED.show();
        D_FPS;
        D_LED(OFF);
        SERIAL_FLUSH;
    }
}

void timeouts(){
    // No data received. If this persists, send an ACK packet
    // to host once every second to alert it to our presence.
    if((t - lastAckTime) >= 1000) {
        Serial.print("Ada\n"); // Send ACK string to host
        lastAckTime = t; // Reset counter

        // If no data received for an extended time, turn off all LEDs.
        if(SerialTimeout != 0 && (t - lastByteTime) >= (uint32_t) SerialTimeout * 1000) {
            memset(leds, 0, Num_Leds * sizeof(struct CRGB)); //filling Led array by zeroes
            FastLED.show();
            mode = Header;
            lastByteTime = t; // Reset counter
        }
    }
}
 Note:
The price is only Led Strip, Not Included Power Supply or Led Controller!
WS2813 Must Use DC5V Power Supply AND Led Controller to Control!
Every 0.5meter with solder joints, please note!
Pay Attention:
1, 30,60,144 means: 30 Leds/m, 60 Leds/m, 144 Leds/m
2, IP30 Non-Waterproof / IP65 Waterproof in Silicon Coating / IP67 Waterproof in Silicon Tube
3, IP30 IP65 with 3M adhensive tape on the back (IP67 without 3M adhensive)
4, Each strip with one free male connector for, The length of the strip as you choose
Main feature:
One pixel damaged will not affect the other LEDs'working, Dual signal wires version, Signal can jump to transfer
FEATURES:
LED Light Source: WS2813 LEDs ( Same Protocol as WS2811S But With Dual-Signal Wires,So Can Be Controlled by the Same WS2811/ws2812 Controllers)
Input Voltage: DC 5V
Power: 30 Leds/M --- 9 Watt/Meter / 60 Leds/M --- 18 Watt/Meter / 144 Leds/M --- 43.2 Watt/Meter
LED Resource: WS2813 led (5050 SMD RGB LED with built-in improved version of ws2811 ic)
LED: Each LED is separately controlled
IC Type: Improved version ws2813 IC(built inside the 5050 smd rgb led)
Of IC: (1 IC drives 1 led chip)
Pixels: 30Leds/60Leds/144Leds/meter
Pitch: 16.6mm(1000/64)
Grey Scale: 256
Colors: Full color RGB, dream color changing
Bits/Color: 8-Bits/Color
FPC Color: BLACK / White
FPC Width: 30 Leds/M --- 10 MM / 60 Leds/M --- 10 MM / 144 Leds/M --- 12 MM
Protection Rate: IP30 Non-Waterproof / IP65 Waterproof in Silicon Coating / IP67 Waterproof in Silicon Tube
Cuttable: Every LED is cuttable
Package: In anti-static bag, IP30 IP65 with 3M adhensive tape on the back (IP67 without 3M adhensive), each strip with one free male connector for connector
Working Temperature: -40 - 70 °C
Storage Temperature: -50 - 80 °C
Source Life: 50,000 hours
Connector: 4PIN connector terminal pair (Red: 5V power, Green: Date line, Blue: standby date line, Black: GND)
Recommand controllers: T-1000s,T-8000A;T-100K;T-200K;T-300K
MORE FEATURES:
(1)One pixel damaged will not affect the other LEDs working.
(2)The power protection,if +5V and GND reverse polarity,the LED will not be burned.
(3) Dual signal wires version, signal can jump to transfer.
(4)The original electronic devices integrated,it does not cause virtual welding in the installation process.
1, all the electronic components are integrated in a 5050 lamp beads, it does not require any other peripheral auxiliary electronic components to form a complete external control pixels. While reducing the product at the time of installation inverted Weld, caused by poor.
2, serial cascade interface, dual-line signal transmission, to achieve the functions of HTTP, which under a single pixel without causing damage to its lower pixel normal lighting, silk ho does not affect the overall results.
3, intelligent reverse polarity protection, product installation access 5V power supply in case of reverse, will not cause damage to the lamp beads.
4, built-in signal shaping circuit, any one pixel after receiving the signal through the waveform shaping and then output to ensure line waveform distortion will not accumulate.
5, the transmission distance between any two points in less than 5 meters without any additional signal amplification circuit.
6, when a refresh rate of 30 frames / sec, the number of cascades of not less than 1024 points.
7, the data transmission speed of up to 800Kbps. Light color consistency, cost-effective.
LED WS2813 Symphony light strip Function Description:
Happy control a single lamp, water, windows, rear meteor, chasing, pattern change animation, video, text, and so on. Use of the lamp, in which a pixel bad, does not affect the normal operation of other lights so as not to affect the overall results. Any color can show, random combinations into any pattern, in particular made light of the screen to use. No separate address to write to the lamp can be achieved HTTP, installation easier. Meanwhile lamp beads which also integrates a capacitive resistance, so that electronic components do not need to be on board the auxiliary light bar, thus increasing the stability of the product.
LED WS2813 strip use for:
The product rich colors and bright light, high visibility, more visually appealing. Is widely used in the corridor wall, indoor decoration, product model decorative lighting, decorative lighting consoles, speakers decorative lighting, entertainment, wine cooler bar backlight, smallpox backlight, LED light boxes, LED luminous signs, aquarium supplies, car decoration etc., it is to replace the traditional neon signs, fluorescent lamps and a new