Добрый день. Нужна помощь. Есть вывеска, собрана на ленте ws2812 +nodemcu +SD модуль, выгорел диод, вывеска то показывает то нет. Друг говорит сможешь переделать? Давай. Купил ленту ws2815, тестировал через плату arduino nano, питание от usb - все работало, дальше плата nodemcu, питание от бп на 12вт - работает но не корректно, т.е цвета вроде совпадают, а вот при полной мощности есть сильное мерцание и цвета в перемешку. Программа для тестов JINX. Библиотеки и платы обновлял - если на понижение версии только хуже. Скрипт собирался не мной - пытался что-то поменять, не получается - но очень хочется помочь.
WS2812_Glediator для проверки на arduino nano
//##############################################################################
//##############################################################################
// #
// Glediator to WS2812 pixel converter #
// by R. Heller #
// V 1.0 - 07.01.2014 #
// wwww.SolderLab.de #
// #
// Receives serial data in Glediator protocol format @ 1 MBit/s #
// and distributes it to a connectect chain of WS2812 pixels #
// #
// Adjust the correct DATA PIN and the correct NUMBER OF PIXELS you are using #
// in the definitions section below before uploading this sketch to your #
// Arduino device. #
// #
// Maxiumim number of supported pixeles is 512 !!! #
// #
// In the Glediator software set output mode to "Glediator_Protocol", #
// color order to "GRB" and baud rate to "1000000" #
// #
//##############################################################################
//##############################################################################
//##############################################################################
// #
// Definitions --> Make changes ONLY HERE #
// #
// To find out the correct port, ddr and pin name when you just know the #
// Arduino's digital pin number just google for "Arduino pin mapping". #
// In the present example digital Pin 6 is used which corresponds to "PORTD", #
// "DDRD" and "6", respectively. #
// #
//##############################################################################
#define DATA_PORT PORTD
#define DATA_DDR DDRD
#define DATA_PIN 4
#define NUMBER_OF_PIXELS 300
//##############################################################################
// #
// Variables #
// #
//##############################################################################
unsigned char display_buffer[NUMBER_OF_PIXELS * 3];
static unsigned char *ptr;
static unsigned int pos = 0;
volatile unsigned char go = 0;
//##############################################################################
// #
// Setup #
// #
//##############################################################################
void setup()
{
// Set data pin as output
DATA_DDR |= (1 << DATA_PIN);
// Initialize UART
UCSR0A |= (1<<U2X0);
UCSR0B |= (1<<RXEN0) | (1<<TXEN0) | (1<<RXCIE0);
UCSR0C |= (1<<UCSZ01) | (1<<UCSZ00) ;
UBRR0H = 0;
UBRR0L = 1; //Baud Rate 1 MBit (at F_CPU = 16MHz)
ptr=display_buffer;
//Enable global interrupts
sei();
}
//##############################################################################
// #
// Main loop #
// #
//##############################################################################
void loop()
{
if (go==1)
{
cli();
ws2815_sendarray(display_buffer, NUMBER_OF_PIXELS * 3);
sei();
go=0;
}
}
//##############################################################################
// #
// UART-Interrupt-Prozedur (called every time one byte is compeltely received) #
// #
//##############################################################################
ISR(USART_RX_vect)
{
unsigned char b;
b=UDR0;
if (b == 1) {pos=0; ptr=display_buffer; return;}
if (pos == (NUMBER_OF_PIXELS*3)) {} else {*ptr=b; ptr++; pos++;}
if (pos == ((NUMBER_OF_PIXELS*3)-1)) {go=1;}
}
//##############################################################################
// #
// WS2812 output routine #
// Extracted from a ligh weight WS2812 lib by Tim (cpldcpu@gmail.com) #
// Found on wwww.microcontroller.net #
// Requires F_CPU = 16MHz #
// #
//##############################################################################
void ws2815_sendarray(uint8_t *data,uint16_t datlen)
{
uint8_t curbyte,ctr,masklo;
uint8_t maskhi = _BV(DATA_PIN);
masklo =~ maskhi & DATA_PORT;
maskhi |= DATA_PORT;
while (datlen--)
{
curbyte = *data++;
asm volatile
(
" ldi %0,8 \n\t" // 0
"loop%=:out %2, %3 \n\t" // 1
"lsl %1 \n\t" // 2
"dec %0 \n\t" // 3
" rjmp .+0 \n\t" // 5
" brcs .+2 \n\t" // 6l / 7h
" out %2,%4 \n\t" // 7l / -
" rjmp .+0 \n\t" // 9
" nop \n\t" // 10
" out %2,%4 \n\t" // 11
" breq end%= \n\t" // 12 nt. 13 taken
" rjmp .+0 \n\t" // 14
" rjmp .+0 \n\t" // 16
" rjmp .+0 \n\t" // 18
" rjmp loop%= \n\t" // 20
"end%=: \n\t"
: "=&d" (ctr)
: "r" (curbyte), "I" (_SFR_IO_ADDR(DATA_PORT)), "r" (maskhi), "r" (masklo)
);
}
}
//##############################################################################
// #
// End of program #
// #
//##############################################################################
это рабочий скипт на которой работала вывеска + не большие переделки для WS2815
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <Adafruit_NeoPixel.h>
//+SD
#include <FastLED.h>
#include <SPI.h>
#include <SD.h>
//-SD
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN D1 //вывод на матрицу
#define NUMPIXELS 300 //Количество светодиодов
//+SD
#define LED_PIN 1 // вывод на матрицу для SD
#define WS2815 WS2812B
#define CHIPSET WS2815 // your LED chip type
//#define CHIPSET WS2815B
#define CMD_NEW_DATA 1
#define BRIGHTNESS 10 // Яркость
unsigned char x = 60; // количество светодиодов по X
unsigned char y = 5; // количество светодиодов по Y
bool SdCard=true;
File fxdata;
CRGB leds[NUMPIXELS];
//-SD
Adafruit_NeoPixel pixels= Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_RGB + NEO_KHZ800);
const char* ssid = "KOD+M"; //Имя вашей сети Wi-Fi
const char* password = "000001700000"; //пароль вашей сети Wi-Fi
IPAddress ip(192, 168, 43, 200); //IP адрес гирлянды
IPAddress gateway(192, 168, 43, 1); //IP адрес Wi-Fi роутера
IPAddress subnet(255, 255, 255, 0);
unsigned int localPort = 65506; // local port to listen for UDP packets
const int PACKET_SIZE = NUMPIXELS*3+7;
byte packetBuffer[PACKET_SIZE]; //buffer to hold incoming and outgoing packets
// A UDP instance to let us send and receive packets over UDP
WiFiUDP udp;
typedef struct
{
byte r;
byte g;
byte b;
} colorpin;
colorpin led;
int led_index = 0;
void WiFiEvent(WiFiEvent_t event)
{
switch (event)
{
case WIFI_EVENT_STAMODE_GOT_IP:
pixels.begin();
break;
case WIFI_EVENT_STAMODE_DISCONNECTED:
break;
}
}
void setup()
{
//Если есть SD карта
FastLED.addLeds<CHIPSET, LED_PIN, RGB>(leds, NUMPIXELS); //see doc for different LED strips
// Serial.begin(BAUD_RATE); // when using Glediator via usb
FastLED.setBrightness(BRIGHTNESS);
Serial.begin(2000000);
for(int y = 0 ; y < NUMPIXELS ; y++)
{
leds[y] = CRGB::Grey; // set all leds to black during setup
Serial.println(y + "Black");
}
FastLED.show();
if (!SD.begin(10))
{
Serial.println("sdcard initialization failed!");
//return;
}else Serial.println("sdcard initialization done.");
// test file open
fxdata = SD.open("01.out"); // read only
if (fxdata){
Serial.println("file open ok test");
fxdata.close();
}
else // SD карты нет
{
SdCard=false;
pinMode(LED_BUILTIN, OUTPUT);
//Serial.begin(1000000);
WiFi.disconnect(true);
delay(1000);
WiFi.onEvent(WiFiEvent);
WiFi.config(ip, gateway, subnet);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(300);
// Serial.print("x");
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(100);
}
//Serial.println("");
//Serial.println("WiFi connected");
//Serial.println("IP address: ");
//Serial.println(WiFi.localIP());
digitalWrite(LED_BUILTIN, LOW);
//Serial.println("Starting UDP");
udp.begin(localPort);
//Serial.print("Local port: ");
//Serial.println(udp.localPort());
}
}
void loop()
{
// если есть SD карта
if(SdCard)
{
fxdata = SD.open("01.out"); // read only
if (fxdata){
Serial.println("file open ok - loop");
}
while (fxdata.available()){
Sortled();
FastLED.show();
delay(100); // Скорость
}
// close the file in order to prevent hanging IO or similar throughout time
fxdata.close();
for(int y = 0 ; y < NUMPIXELS ; y++){
leds[y] = CRGB::Black; // set all leds to black during setup
}
// 01.out конец
{
fxdata = SD.open("02.out"); // read only
if (fxdata){
Serial.println("file open ok - loop");
}
while (fxdata.available()){
Sortled();
FastLED.show();
delay(50); // Скорость
}
// close the file in order to prevent hanging IO or similar throughout time
fxdata.close();
for(int y = 0 ; y < NUMPIXELS ; y++){
leds[y] = CRGB::Black; // set all leds to black during setup
}
} // 02.out конец
{
fxdata = SD.open("03.out"); // read only
if (fxdata){
Serial.println("file open ok - loop");
}
while (fxdata.available()){
Sortled();
FastLED.show();
delay(50); // Скорость
}
// close the file in order to prevent hanging IO or similar throughout time
fxdata.close();
for(int y = 0 ; y < NUMPIXELS ; y++){
leds[y] = CRGB::Black; // set all leds to black during setup
}
}// 03.out конец
{
fxdata = SD.open("04.out"); // read only
if (fxdata){
Serial.println("file open ok - loop");
}
while (fxdata.available()){
Sortled();
FastLED.show();
delay(50); // Скорость
}
// close the file in order to prevent hanging IO or similar throughout time
fxdata.close();
for(int y = 0 ; y < NUMPIXELS ; y++){
leds[y] = CRGB::Black; // set all leds to black during setup
}
}// 04.out конец
{
fxdata = SD.open("05.out"); // read only
if (fxdata){
Serial.println("file open ok - loop");
}
while (fxdata.available()){
Sortled();
FastLED.show();
delay(50); // Скорость
}
// close the file in order to prevent hanging IO or similar throughout time
fxdata.close();
for(int y = 0 ; y < NUMPIXELS ; y++){
leds[y] = CRGB::Black; // set all leds to black during setup
}
}// 05.out конец
{
fxdata = SD.open("06.out"); // read only
if (fxdata){
Serial.println("file open ok - loop");
}
while (fxdata.available()){
Sortled();
FastLED.show();
delay(50); // Скорость
}
// close the file in order to prevent hanging IO or similar throughout time
fxdata.close();
for(int y = 0 ; y < NUMPIXELS ; y++){
leds[y] = CRGB::Black; // set all leds to black during setup
}
}// 06.out конец
{
fxdata = SD.open("07.out"); // read only
if (fxdata){
Serial.println("file open ok - loop");
}
while (fxdata.available()){
Sortled();
FastLED.show();
delay(50); // Скорость
}
// close the file in order to prevent hanging IO or similar throughout time
fxdata.close();
for(int y = 0 ; y < NUMPIXELS ; y++){
leds[y] = CRGB::Black; // set all leds to black during setup
}
}// 07.out конец
{
fxdata = SD.open("08.out"); // read only
if (fxdata){
Serial.println("file open ok - loop");
}
while (fxdata.available()){
Sortled();
FastLED.show();
delay(50); // Скорость
}
// close the file in order to prevent hanging IO or similar throughout time
fxdata.close();
for(int y = 0 ; y < NUMPIXELS ; y++){
leds[y] = CRGB::Black; // set all leds to black during setup
}
}// 08.out конец
{
fxdata = SD.open("09.out"); // read only
if (fxdata){
Serial.println("file open ok - loop");
}
while (fxdata.available()){
Sortled();
FastLED.show();
delay(50); // Скорость
}
// close the file in order to prevent hanging IO or similar throughout time
fxdata.close();
for(int y = 0 ; y < NUMPIXELS ; y++){
leds[y] = CRGB::Black; // set all leds to black during setup
}
}// 09.out конец
{
fxdata = SD.open("010.out"); // read only
if (fxdata){
Serial.println("file open ok - loop");
}
while (fxdata.available()){
Sortled();
FastLED.show();
delay(50); // Скорость
}
// close the file in order to prevent hanging IO or similar throughout time
fxdata.close();
for(int y = 0 ; y < NUMPIXELS ; y++){
leds[y] = CRGB::Black; // set all leds to black during setup
}
}// 010.out конец
FastLED.show();
}
else{
int cb = udp.parsePacket();
if (!cb){
// Serial.setDebugOutput(true);
}
else{
// We've received a packet, read the data from it
udp.read(packetBuffer, PACKET_SIZE); // read the packet into the buffer
if (cb >= 6 && packetBuffer[0] == 0x9C){
// header identifier (packet start)
byte blocktype = packetBuffer[1]; // block type (0xDA)
unsigned int framelength = ((unsigned int)packetBuffer[2] << 8) | (unsigned int)packetBuffer[3]; // frame length (0x0069) = 105 leds
//Serial.print("Frame.");
//Serial.println(framelength); // chan/block
byte packagenum = packetBuffer[4]; // packet number 0-255 0x00 = no frame split (0x01)
byte numpackages = packetBuffer[5]; // total packets 1-255 (0x01)
if (blocktype == 0xDA){
// data frame ...
////Serial.println("command");
int packetindex;
if (cb >= framelength + 7 && packetBuffer[6 + framelength] == 0x36){
// header end (packet stop)
//Serial.println("s:");
int i = 0;
packetindex = 6;
if (packagenum == 1){
led_index = 0;
}
while (packetindex < (framelength + 6)){
led.r = ((int)packetBuffer[packetindex]);
led.g = ((int)packetBuffer[packetindex + 1]);
led.b = ((int)packetBuffer[packetindex + 2]);
pixels.setPixelColor(led_index, led.r, led.g, led.b);
led_index++;
//Serial.println(led_index);
packetindex += 3;
}
}
//Serial.print(packagenum);
//Serial.print("/");
//Serial.println(numpackages);
}
if ((packagenum == numpackages) && (led_index == NUMPIXELS)){
pixels.show();
led_index == 0;
}
}
}
}
}
int Sortled () {
CRGB templeds[NUMPIXELS];
const uint16_t XYTable[] = {
240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299,
180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59
};
fxdata.readBytes((char*)templeds, NUMPIXELS*3);
for (int k=0; k < NUMPIXELS; k++){
leds[XYTable[k]] = templeds[k];
}
}
int serialGlediator (){
while (!Serial.available()) {}
return Serial.read();
}