Open
Description
Platform
- Hardware: NodeMCU 0.9
- Development Env: Arduino IDE
- Operating System: MacOS
Settings in IDE
- Module: Nodemcu
- Flash Size: [4MB/1MB]
- lwip Variant: v2 Lower Memory
- CPU Frequency: 160MHz
- Upload Using: SERIAL
- Upload Speed: 115200
Problem Description
I used nodmcu as udp client to recives ws2812 datas,each pixel take up 3 bytes and I have 500pixels or more,but once it exceeds 492 pixels, the client can no longer receive data
Sketch
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <FastLED.h>
#define DATA_PIN 3
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
#define NUM_LEDS 500
#define BRIGHTNESS 128
#define UDP_PORT 3000
const char* ssid = "Rect";
const char* password = "11111111";
const unsigned int wifi_timeout = 30000;
CRGB leds[NUM_LEDS];
WiFiUDP Udp;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(10);
// 初始化灯带
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
// 连接wifi
setup_wifi();
// 开启udp
Udp.begin(UDP_PORT);
Serial.printf("Now listening at IP %s, UDP port %d\n", WiFi.localIP().toString().c_str(), UDP_PORT);
}
// 设置wifi
void setup_wifi() {
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
unsigned long connect_start = millis();
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.println();
}
void loop() {
// put your main code here, to run repeatedly:
int packetSize = Udp.parsePacket();
while (packetSize > 0) {
Udp.read((char*)leds, NUM_LEDS * 3);
}
FastLED.show();
}