esp8266 / esp8266/Arduino

NodeMCU as UDP client to control ws2812

Open
#8,313 2 comments 0 reactions 0 assignees View on GitHub
waiting for feedback
Dominant language
C++
Stars
16.7k
Forks
13.1k
PR merge metrics
No merged PRs in 30d

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

```cpp

#include
#include
#include

#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(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();
}

```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.