The two main issues i'm having is that 1) sometimes my LEDs can get choppy/stutter and they won't resolve until i stop sending led data values and let the ESP rest for a bit and 2) sometimes when i stop sending values, the LEDs will still be animating, seemingly because they still going through old packets. This one doesn't really make sense to me, because it would seem to me that the ESP is saving UDP packets somewhere, but I feel any packets that it receives and the loop doesn't execute exactly when it receives, would just be dropped/lost somewhere.
so i've posted my code, which i feel is fairly minimal, but maybe someone can point out a better method of doing something. I'm not sure i put the yield() in the correct place. I was also having software and hardware watchdog resets, so i added that bit about feeding it, and added a 5.6k resistor between 3.3V and GPIO0 (although that seemed to have no effect). I haven't had any watchdog errors/resets in a while, so i feel the code is correct (maybe a little excessive with how it maintains an active state).
Another thing i've noticed is that the ESP runs a lot better when powered from USB rather than the Vin pin. Is this true, or is it due to when i power it through Vin, my breadboard/wires/power-source (which is shares with the LEDs) is bad? I added some caps to stabilize/clean the power supply.
I've attached a picture as well to show my hardware setup. My ESP is connected to a 5 meter WS2812B strip of 300 LEDs and uses a level shifter to bump the 3.3V signal to 5V. UDP packets of 300 RGB values are getting sent 60 times a seconds (60fps). if anymore information is required, please let me know
Cheers.
#include <ESP8266WiFi.h>
#include <WiFiUDP.h>
#define FASTLED_ESP8266_NODEMCU_PIN_ORDER
//#define FASTLED_ALLOW_INTERRUPTS 0
#include <FastLED.h>
#define PIN 6
#define LED_COUNT 300
#define UDP_TX_PACKET_MAX_SIZE 1500
CRGB leds[LED_COUNT];
// wifi connection variables
const char* ssid = ****;
const char* password = "****";
boolean wifiConnected = false;
// UDP variables
unsigned int localPort = 8888;
IPAddress ip(192, 168, 2, 177);
IPAddress gateway(192, 168, 2, 1);
IPAddress subnet(255, 255, 255, 0);
WiFiUDP UDP;
boolean udpConnected = false;
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
void setup() {
//when watchdog resets the board, GPIO0 needs to be Pulled Up according to here:
//https://github.com/esp8266/Arduino/blob/master/doc/boards.md#minimal-hardware-setup-for-running-only
//https://learn.sparkfun.com/tutorials/esp8266-thing-hookup-guide/using-the-arduino-addon
//also added a resistor between GPIO0 and 3.3V pin
pinMode(0, INPUT_PULLUP);
FastLED.addLeds<WS2812B, PIN, GRB>(leds, LED_COUNT);
Serial.begin(115200);
wifiConnected = connectWifi();
if (wifiConnected) {
udpConnected = connectUDP();
}
}
void loop() {
ESP.wdtEnable(WDTO_8S);
ESP.wdtFeed();
if (wifiConnected) {
if (udpConnected) {
int packetSize = UDP.parsePacket();
if (packetSize) {
UDP.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
for (uint16_t j = 0; j < LED_COUNT; j++) {
leds[j].setRGB (packetBuffer[(j * 3)],
packetBuffer[(j * 3) + 1],
packetBuffer[(j * 3) + 2]);
}
FastLED.show();
}
}
}
yield();
}
// connect to wifi – returns true if successful or false if not
boolean connectWifi() {
boolean state = true;
int i = 0;
WiFi.config(ip, gateway, subnet);
WiFi.begin(ssid, password);
Serial.println("");
Serial.println("Connecting to WiFi");
// Wait for connection
Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
if (i > 10) {
state = false;
break;
}
i++;
}
if (state) {
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
else {
Serial.println("");
Serial.println("Connection failed.");
}
return state;
}
// connect to UDP – returns true if successful or false if not
boolean connectUDP() {
boolean state = false;
Serial.println("");
Serial.println("Connecting to UDP");
if (UDP.begin(localPort) == 1) {
Serial.println("Connection successful");
state = true;
}
else {
Serial.println("Connection failed");
}
return state;
}