Chat here is you are connecting ESP-xx type modules to existing AVR based Arduino

Moderator: igrr

User avatar
By Stoney
#16611 After attempting and failing to get my LPD1886 led strip functioning directly with the ESP-01 I went old school and left an arduino nano driving the led strip, 35 chips driving 3 RGB leds each. The LPD1886 needs <280nS pulses and these seem tricky to generate.
Anyway, I had this working with my rapsberry pi running hyperion for an ambilight clone behind the tv, but it was a pain to use as the pi needs the USB replugged in at times, besides, a brick wall behind the tv made it too dark. The Pi (running openelec and kodi) cannot drive the leds directly due to latency so the arduino does the pulse generation for the strip.
So the idea was initially to wifi enable the strip and make something artistic ultimately, I was going to have the arduino running effects and be able to change them with my ipad or browser.
Then I considered glediator .. after looking at the network protocols and failing to make much sense of how to use it (I cannot remove the incorrect IP address, says 'universe in use' no matter what I do)
So installed 'Jinx!' instead. much easier to use and set up.
added a tpm2.net interface and pointed it at my esp-01 .. checked out the port data I was receiving, a 112 byte buffer 25 times a second of which 105 bytes is the LED data, a bit of though said 38400baud should just handle that so I left the standard arduino hyperion interface code in place and

used part of the tpm2.net packet routines from here .. https://github.com/sfranzyshen/esp8266_tpm2net_ws2812

the arduino code from here .. http://pastebin.com/zhQCRFhd

and some UDP code from soemwhere..

Since using just a nano for this I had to change that to use altsoftserial to get it reliable at 38400. 19200 nearly worked but flickered.

Code: Select all#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

unsigned int localPort = 65506;      // local port to listen for UDP packets
const int PACKET_SIZE = 1536;
byte packetBuffer[PACKET_SIZE]; //buffer to hold incoming and outgoing packets

const char* ssid = "TP-LINK_2.4GHz_62379F";
const char* password = "abcdefgh";  // <-- i actually have no wifi security, live in the bush, but it needs a dummy password

// A UDP instance to let us send and receive packets over UDP
WiFiUDP udp;


void setup() {
  Serial.begin(38400);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print("x");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  Serial.println("Starting UDP");
  udp.begin(localPort);
  Serial.print("Local port: ");
  Serial.println(udp.localPort());

}

void loop() {

  int cb = udp.parsePacket();
  if (!cb) {
    //    Serial.setDebugOutput(true);
  }
  else {
    //    Serial.print("packet received, length=");
    //    Serial.println(cb);

    // 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
      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 command ...
        if (cb >= framelength + 7 && packetBuffer[6 + framelength] == 0x36) { // header end (packet stop)
          if (numpackages == 0x01) { // no frame split found
//            int packetindex;
//            Serial.println("start:");
//            for (packetindex = 0; packetindex < framelength + 6; packetindex++)
//            {
//              Serial.print (" ");
//              Serial.print (packetBuffer[packetindex],HEX);
//            }

            int packetindex;
            Serial.print("Ada00U");
            for (packetindex = 6; packetindex < framelength + 6; packetindex++)
            {
              Serial.print ((char)packetBuffer[packetindex]);
            }
          }
        }
      }
    }
  }

}



Now issues ..

if I am sending the data stream to the port and cycle the esp-01 power it starts operating every time.
If I start the stream when the esp has been on for a while sometimes it starts straight away, sometimes after 10 seconds or so, sometimes not at all.

it will also stop at times.. printing this every second or so..

LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1

If I stop and restart the data stream, it will often not restart but then it might after a while..

I haven't yet looked into why it might be happening yet, do I have to issue the udp.begin regularly ?
apart from that though its working quite seamlessly, the little blue LED on the esp-01 is on continuously, just a slight brightness flicker to it, the leds are zero flicker at all.

anyway I thought I would post that code and results to date as I had not seen a lot of UDP stuff around unless i am searching badly.