Page 1 of 3 123 LastLast
Results 1 to 10 of 25

Thread: Esp Code for various modules

  1. #1
    Join Date
    Dec 2011
    Posts
    6,319
    Post Thanks / Like

    Default Esp Code for various modules

    Thought I would start a thread for sharing working sketches .

    This is for esp8266 wemos . Uses FastLed & older E131
    May also work on Esp-01, not tested

    Code:
    /*
      E131_Test.ino - Simple sketch to listen for E1.31
    
      Project: E131 ESP8266 and FastLed
      Copyright (c)  Shelby Merrick
      http://www.forkineye.com
    
       This program is provided free for you to use in any way that you wish,
       subject to the laws and regulations where you are using it.  Due diligence
       is strongly suggested before using this code.  Please give credit where due.
    
       The Author makes no warranty of any kind, express or implied, with regard
       to this program or the documentation contained in this document.  The
       Author shall not be liable in any event for incidental or consequential
       damages in connection with, or arising out of, the furnishing, performance
       or use of these programs.
    
    */
    #include <ESP8266WiFi.h>
    #include <E131.h>
    #include <FastLED.h>
    
    #define UNIVERSE 1                      // First DMX Universe to listen for
    #define CHANNEL_START 1
    #define DATA_PIN 2
    #define NUM_LEDS 170
    
    CRGB newLeds[NUM_LEDS];
    
    const char ssid[] = "SSID";         // Replace with your SSID
    const char passphrase[] = "PASSWORD";   // Replace with your WPA2 passphrase
    
    // ESPAsyncE131 instance with UNIVERSE_COUNT buffer slots
    E131 e131;
    
    void setup() {
      Serial.begin(115200);
      delay(10);
    
      FastLED.addLeds<WS2812B, DATA_PIN, GRB>(newLeds, NUM_LEDS);
    
      // Make sure you're in station mode
      WiFi.mode(WIFI_STA);
    
      Serial.println("");
      Serial.print(F("Connecting to "));
      Serial.print(ssid);
    
      if (passphrase != NULL)
        WiFi.begin(ssid, passphrase);
      else
        WiFi.begin(ssid);
    
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }
    
      Serial.println("");
      Serial.print(F("Connected with IP: "));
      Serial.println(WiFi.localIP());
    
      // Choose one to begin listening for E1.31 data
      //if (e131.begin(E131_UNICAST))                               // Listen via Unicast
      //if (e131.begin(E131_MULTICAST, UNIVERSE, UNIVERSE_COUNT))   // Listen via Multicast
      e131.beginMulticast(ssid, passphrase, UNIVERSE);
    
      Serial.println(F("Listening for data..."));
    
    }
    void loop() {
      if (e131.parsePacket()) {
        if (e131.universe == 1) {
          for (int i = 0; i < NUM_LEDS; i++) {
            int j = i * 3 + (CHANNEL_START - 1);
            newLeds[i] = (i, (CRGB(e131.data[j], e131.data[j + 1], e131.data[j + 2])));
          }
          FastLED.show();
        }
      }
    }
    Last edited by angus40; 02-25-2020 at 06:27 PM.

  2. #2
    Join Date
    Dec 2011
    Posts
    6,319
    Post Thanks / Like

    Default Re: Esp Code for various modules

    Esp8266 Wemos, EspAsyncE131 , FastLed

    May also work on esp-01 , not tested .

    Code:
    /*
      E131_Test.ino - Simple sketch to listen for E1.31
    
      Project: ESPAsyncE131  ESP8266 and FastLed
      Copyright (c) 2019 Shelby Merrick
      http://www.forkineye.com
    
       This program is provided free for you to use in any way that you wish,
       subject to the laws and regulations where you are using it.  Due diligence
       is strongly suggested before using this code.  Please give credit where due.
    
       The Author makes no warranty of any kind, express or implied, with regard
       to this program or the documentation contained in this document.  The
       Author shall not be liable in any event for incidental or consequential
       damages in connection with, or arising out of, the furnishing, performance
       or use of these programs.
    
    */
    #include <ESP8266WiFi.h>
    #include <ESPAsyncE131.h>
    #include <FastLED.h>
    
    
    #define UNIVERSE 1                      // First DMX Universe to listen for
    #define UNIVERSE_COUNT 2
    #define CHANNEL_START 1
    #define DATA_PIN 2
    #define NUM_LEDS 170
    
    
    CRGB newLeds[NUM_LEDS];
    
    const char ssid[] = "SSID";         // Replace with your SSID
    const char passphrase[] = "PASSWORD";   // Replace with your WPA2 passphrase
    
    // ESPAsyncE131 instance with UNIVERSE_COUNT buffer slots
    ESPAsyncE131 e131(UNIVERSE_COUNT);
    
    void setup() {
      Serial.begin(115200);
      delay(10);
    
      FastLED.addLeds<WS2812B, DATA_PIN, GRB>(newLeds, NUM_LEDS);
    
      // Make sure you're in station mode
      WiFi.mode(WIFI_STA);
    
      Serial.println("");
      Serial.print(F("Connecting to "));
      Serial.print(ssid);
    
      if (passphrase != NULL)
        WiFi.begin(ssid, passphrase);
      else
        WiFi.begin(ssid);
    
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }
    
      Serial.println("");
      Serial.print(F("Connected with IP: "));
      Serial.println(WiFi.localIP());
    
      // Choose one to begin listening for E1.31 data
      //if (e131.begin(E131_UNICAST))                               // Listen via Unicast
      if (e131.begin(E131_MULTICAST, UNIVERSE, UNIVERSE_COUNT))   // Listen via Multicast
        Serial.println(F("Listening for data..."));
      else
        Serial.println(F("*** e131.begin failed ***"));
    
    }
    void loop() {
      if (!e131.isEmpty()) {
        e131_packet_t packet;
        e131.pull(&packet);     // Pull packet from ring buffer
        uint16_t universe = htons(packet.universe);
        if (universe == 1) {
          if (packet.property_values[(CHANNEL_START - 1)] < NUM_LEDS) {
            for (int n = 0; n < NUM_LEDS; n++) {
              int j = n * 3 + (CHANNEL_START);
              newLeds[n] = (n, (CRGB(packet.property_values[j] , packet.property_values[j + 1], packet.property_values[j + 2])));
              //Serial.println(packet.property_values[j]);
            }
            FastLED.show();
          }
        }
      }
    }
            /*   Serial.printf("Universe %u / %u Channels | Packet#: %u / Errors: %u / CH1: %u\n",
                       htons(packet.universe),                 // The Universe for this packet
                       htons(packet.property_value_count) - 1, // Start code is ignored, we're interested in dimmer data
                       e131.stats.num_packets,                 // Packet counter
                       e131.stats.packet_errors,               // Packet error counter
                       packet.property_values[1]);             // Dimmer data for Channel 1     */

  3. #3
    Join Date
    Dec 2011
    Posts
    6,319
    Post Thanks / Like

    Default Re: Esp Code for various modules

    Esp8266 Wemos, EspAsyncE131, NeoPixelBus

    May work on Esp-01 , not tested

    Code:
    /*
      E131_Test.ino - Simple sketch to listen for E1.31 data on an ESP32
                       and print some statistics.
    
      Project: ESPAsyncE131 - Asynchronous E.131 (sACN) library for Arduino ESP8266
      Copyright (c) 2019 Shelby Merrick
      http://www.forkineye.com
    
       This program is provided free for you to use in any way that you wish,
       subject to the laws and regulations where you are using it.  Due diligence
       is strongly suggested before using this code.  Please give credit where due.
    
       The Author makes no warranty of any kind, express or implied, with regard
       to this program or the documentation contained in this document.  The
       Author shall not be liable in any event for incidental or consequential
       damages in connection with, or arising out of, the furnishing, performance
       or use of these programs.
    
    */
    #include <ESP8266WiFi.h>
    #include <ESPAsyncE131.h>
    #include <NeoPixelBus.h>
    
    #define UNIVERSE 1                // First DMX Universe to listen for
    #define UNIVERSE_COUNT 2          // Total number of Universes to listen for, starting at UNIVERSE
    #define CHANNEL_START 1
    
    const uint16_t PixelCount = 170; // this example assumes 4 pixels, making it smaller will cause a failure
    const uint8_t PixelPin = 2;  // make sure to set this to the correct pin, ignored for Esp8266
    
    const char ssid[] = "SSID";         // Replace with your SSID
    const char passphrase[] = "PASSWORD";   // Replace with your WPA2 passphrase
    
    // ESPAsyncE131 instance with UNIVERSE_COUNT buffer slots
    ESPAsyncE131 e131(UNIVERSE_COUNT);
    
    
    NeoPixelBus<NeoGrbFeature, NeoEsp8266BitBangWs2812xMethod> strip(PixelCount, PixelPin);
    
    void setup() {
      Serial.begin(115200);
      delay(10);
       
      // Make sure you're in station mode
      WiFi.mode(WIFI_STA);
    
      Serial.println("");
      Serial.print(F("Connecting to "));
      Serial.print(ssid);
    
      if (passphrase != NULL)
        WiFi.begin(ssid, passphrase);
      else
        WiFi.begin(ssid);
    
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }
       
      Serial.println("");
      Serial.print(F("Connected with IP: "));
      Serial.println(WiFi.localIP());
    
     /* Initialize output */
        pinMode(PixelPin, OUTPUT);
        digitalWrite(PixelPin, LOW);
     
     // this resets all the neopixels to an off state
        strip.Begin();
        strip.Show();
    
      // Choose one to begin listening for E1.31 data
      //if (e131.begin(E131_UNICAST))                               // Listen via Unicast
      if (e131.begin(E131_MULTICAST, UNIVERSE, UNIVERSE_COUNT));   // Listen via Multicast
    }
    
    void loop() {
      if (!e131.isEmpty()) {
        e131_packet_t packet;
        e131.pull(&packet);     // Pull packet from ring buffer
      uint16_t universe = htons(packet.universe);  
      if (universe == 1) { 
         if (packet.property_values[(CHANNEL_START - 1)] < PixelCount) {
          for (int i = 0; i < PixelCount; i++) {
                int j = i * 3 + (CHANNEL_START );
                  strip.SetPixelColor(i, (RgbColor(packet.property_values[j], packet.property_values[j+1], packet.property_values[j+2])));        
                Serial.println(packet.property_values[j] );;
                }
                strip.Show();
         }
      }
      }
    }

  4. #4
    Join Date
    Dec 2011
    Posts
    6,319
    Post Thanks / Like

    Default Re: Esp Code for various modules

    ESP32 ,EspAsyncE131 & NeoPixelBus (This provides 2 functional GPIO * 2 Universes as configured , with the possibly of more through experimentation )

    Code:
    /*
      All credits to :
      Shelby Merrick for his E131
             &
      Michael Miller for the NeoPixel_Bus
    
      E131_Test.ino - Simple sketch to listen for E1.31 data on an ESP32
                       and print some statistics.
    
      Project: ESPAsyncE131 - Asynchronous E.131 (sACN) library for Arduino ESP8266 and ESP32
      Copyright (c) 2019 Shelby Merrick
      http://www.forkineye.com
    
      NeoPixelBus Test
      https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
    */
    #include <ESPAsyncE131.h>
    #include <NeoPixelBus.h>
    #include <WiFi.h>
    
    #define UNIVERSE 1               // First DMX Universe to listen for
    #define CHANNEL_START_A 1
    #define UNIVERSE_COUNT 3
    #define CHANNEL_START_B 1
    
    
    const uint16_t PixelCount1 = 81; // this example assumes 4 pixels, making it smaller will cause a failure
    const uint8_t PixelPin1 = 12;  // make sure to set this to the correct pin, ignored for Esp8266
    
    const uint16_t PixelCount2 = 81; // this example assumes 4 pixels, making it smaller will cause a failure
    const uint8_t PixelPin2 = 15;  // make sure to set this to the correct pin, ignored for Esp8266
    
    
    const char ssid[] = "SSID";         // Replace with your SSID
    const char passphrase[] = "PASSWORD";   // Replace with your WPA2 passphrase
    
    // ESPAsyncE131 instance with UNIVERSE_COUNT buffer slots
    ESPAsyncE131 e131(3);
    
    NeoPixelBus<NeoGrbFeature, NeoEsp32I2s0Ws2812xMethod> strip1(PixelCount1, PixelPin1);
    NeoPixelBus<NeoGrbFeature, NeoEsp32Rmt0800KbpsMethod> strip2(PixelCount2, PixelPin2);
    
    void setup() {
      Serial.begin(115200);
      delay(10);
    
      // Make sure you're in station mode
      WiFi.mode(WIFI_STA);
    
      Serial.println("");
      Serial.print(F("Connecting to "));
      Serial.print(ssid);
    
      if (passphrase != NULL)
        WiFi.begin(ssid, passphrase);
      else
        WiFi.begin(ssid);
    
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }
    
      Serial.println("");
      Serial.print(F("Connected with IP: "));
      Serial.println(WiFi.localIP());
    
      // this resets all the neopixels to an off state
      strip1.Begin();
      strip1.Show();
      strip2.Begin();
      strip2.Show();
    
      
      // Choose one to begin listening for E1.31 data
      //if (e131.begin(E131_UNICAST))                               // Listen via Unicast
      if (e131.begin(E131_MULTICAST, UNIVERSE, UNIVERSE_COUNT));   // Listen via Multicast
    }
    
    void loop() {
    
      while (!e131.isEmpty()) {
        e131_packet_t packet;
        e131.pull(&packet);     // Pull packet from ring buffer
        uint16_t universe = htons(packet.universe);
        if (universe == 1) {
          //if (packet.property_values[(CHANNEL_START_A - 1)] < PixelCount1) {
            for (int i = 0; i < PixelCount1; i++) {
              int j = i * 3 + (CHANNEL_START_A );
              strip1.SetPixelColor(i, (RgbColor(packet.property_values[j], packet.property_values[j + 1], packet.property_values[j + 2])));
              Serial.println(packet.property_values[j] );
            }
            strip1.Show();
        }
    
        if ((universe == 2) && (packet.property_values[(CHANNEL_START_B - 1)] == (packet.property_values[0]))) {   << Change the (packet.property_values "0 ") to suit your pixel count >>
            for (int i = 0; i < PixelCount2; i++) {
              int j = i * 3 + (CHANNEL_START_B );
              strip2.SetPixelColor(i, (RgbColor(packet.property_values[j], packet.property_values[j + 1], packet.property_values[j + 2])));
              Serial.println(packet.property_values[j + 1] );
            }
            strip2.Show();
        }
      }
    }

  5. #5
    Join Date
    Dec 2011
    Posts
    6,319
    Post Thanks / Like

    Default Re: Esp Code for various modules

    Enjoy ( ͡ ͜ʖ ͡)

  6. #6
    Join Date
    Dec 2011
    Location
    UK S80 postcode
    Posts
    1,464
    Post Thanks / Like

    Default Re: Esp Code for various modules

    Hi, I haven’t had try these yet but great to see working code posted.

  7. #7
    Join Date
    Dec 2011
    Posts
    6,319
    Post Thanks / Like

    Default Re: Esp Code for various modules

    i could not find any code online for the Esp32

    Thanks to Michael Miller and his NeoPixelBus I was able to see some blinky .
    It would be awesome to see the TLS made to work with these modules :

  8. #8
    Join Date
    Dec 2011
    Posts
    6,319
    Post Thanks / Like

    Default Re: Esp Code for various modules

    Esp32, NeoPixelBus, I2s, & 2 GPIO

    This is the one of the best configurations that has worked so far !

    One hurdle I have overcome with figuring out the coding is that there is a huge difference between universe & UNIVERSE .


    Code:
    /*
      All credits to :
      Shelby Merrick for his E131
             &
      Michael Miller for the NeoPixel_Bus
    
      E131_Test.ino - Simple sketch to listen for E1.31 data on an ESP32
                       and print some statistics.
    
      Project: ESPAsyncE131 - Asynchronous E.131 (sACN) library for Arduino ESP8266 and ESP32
      Copyright (c) 2019 Shelby Merrick
      http://www.forkineye.com
    
      NeoPixelTest
      https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
    */
    #include <ESPAsyncE131.h>
    #include <NeoPixelBus.h>
    #include <WiFi.h>
    
    #define UNIVERSE 1               // First DMX Universe to listen for
    #define CHANNEL_START_A 1
    #define UNIVERSE_COUNT 2
    #define CHANNEL_START_B 1
    
    const uint16_t PixelCount1 = 170; // this example assumes 4 pixels, making it smaller will cause a failure
    const uint8_t PixelPin1 = 12;  // make sure to set this to the correct pin, ignored for Esp8266
    
    const uint16_t PixelCount2 = 170; // this example assumes 4 pixels, making it smaller will cause a failure
    const uint8_t PixelPin2 = 15;  // make sure to set this to the correct pin, ignored for Esp8266
    
    const char ssid[] = "SSID";         // Replace with your SSID
    const char passphrase[] = "PASSWORD";   // Replace with your WPA2 passphrase
    
    // ESPAsyncE131 instance with UNIVERSE_COUNT buffer slots
    ESPAsyncE131 e131(UNIVERSE_COUNT);
    
    //NeoPixelBus<NeoGrbFeature, NeoEsp32Rmt0800KbpsMethod> strip1(PixelCount1, PixelPin1);
    //NeoPixelBus<NeoGrbFeature, NeoEsp32Rmt1800KbpsMethod> strip2(PixelCount2, PixelPin2);
    //NeoPixelBus<NeoGrbFeature, NeoEsp32Rmt2800KbpsMethod> strip3(PixelCount3, PixelPin3);
    //NeoPixelBus<NeoGrbFeature, NeoEsp32BitBangWs2813Method> strip3(PixelCount3, PixelPin3);
    NeoPixelBus<NeoGrbFeature, NeoEsp32I2s1800KbpsMethod> strip1(PixelCount1, PixelPin1);
    NeoPixelBus<NeoGrbFeature, NeoEsp32I2s0800KbpsMethod> strip2(PixelCount2, PixelPin2);
    
    void setup() {
      Serial.begin(115200);
      delay(10);
    
      // Make sure you're in station mode
      WiFi.mode(WIFI_STA);
    
      Serial.println("");
      Serial.print(F("Connecting to "));
      Serial.print(ssid);
    
      if (passphrase != NULL)
        WiFi.begin(ssid, passphrase);
      else
        WiFi.begin(ssid);
    
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }
    
      Serial.println("");
      Serial.print(F("Connected with IP: "));
      Serial.println(WiFi.localIP());
    
      // this resets all the neopixels to an off state
      strip1.Begin();
      strip1.Show();
      strip2.Begin();
      strip2.Show();
    
      // Choose one to begin listening for E1.31 data
      //if (e131.begin(E131_UNICAST));                              // Listen via Unicast
      if (e131.begin(E131_MULTICAST, UNIVERSE, UNIVERSE_COUNT));   // Listen via Multicast
    }
    
    void loop() {
    
      if (!e131.isEmpty()) {
        e131_packet_t packet;
        e131.pull(&packet);     // Pull packet from ring buffer
        uint16_t universe = htons(packet.universe);
        if (universe == 1) {
          //if (packet.property_values[(CHANNEL_START_A - 1)] < PixelCount1) {
          for (int i = 0; i < PixelCount1; i++) {
            int j = i * 3 + (CHANNEL_START_A );
            strip1.SetPixelColor(i, (RgbColor(packet.property_values[j], packet.property_values[j + 1], packet.property_values[j + 2])));
            //Serial.println(packet.property_values[j] );
          }
          //strip1.Dirty();
          strip1.Show();
        }
    
        if ((universe == 2) && (packet.property_values[(CHANNEL_START_B - 1)] == (packet.property_values[0]))) {
          //if (packet.property_values[(CHANNEL_START_B - 1)] < PixelCount2) {
          for (int i = 0; i < PixelCount2; i++) {
            int j = i * 3 + (CHANNEL_START_B );
            strip2.SetPixelColor(i, (RgbColor(packet.property_values[j], packet.property_values[j + 1], packet.property_values[j + 2])));
            //Serial.println(packet.property_values[j + 1] );
          }
          //strip2.Dirty();
          strip2.Show();
        }
      }
    }

  9. #9
    Join Date
    Dec 2011
    Posts
    6,319
    Post Thanks / Like

    Default Re: Esp Code for various modules

    Esp32, Esp8266 , EspAsyncE131 , FastLed 2* GPIO Unicast

    Also works with the old E131 version for esp8266
    Code:
    //#include <ESP8266WiFi.h> // Uncomment for esp8666 & comment out WiFi.h
    #include <ESPAsyncE131.h>
    #include <FastLED.h>
    #include <WiFi.h>           // Uncomment for esp32 & comment out ESP8266WiFi.h
    
    #define NUM_LEDS_PER_STRIP_B 81
    #define NUM_LEDS_PER_STRIP_A 81
    
    #define CHANNEL_START_A 1
    #define UNIVERSE  1
    #define CHANNEL_START_B 1
    #define DATA_PIN 15
    
    CRGB newLeds[NUM_LEDS_PER_STRIP_B];
    CRGB oldLeds[NUM_LEDS_PER_STRIP_A];
    
    const char ssid[] = "SSID";         // Replace with your SSID
    const char passphrase[] = "PASSWORD";   // Replace with your WPA2 passphrase
    
    // ESPAsyncE131 instance with UNIVERSE_COUNT buffer slots
    ESPAsyncE131 e131(10);
    
    
    void setup() {
      Serial.begin(115200);
      delay(10);
      
      FastLED.addLeds<WS2812B, DATA_PIN, GRB>(newLeds, NUM_LEDS_PER_STRIP_B);
      FastLED.addLeds<NEOPIXEL, 5>(oldLeds, NUM_LEDS_PER_STRIP_A);
     
      // Make sure you're in station mode
      WiFi.mode(WIFI_STA);
    
      Serial.println("");
      Serial.print(F("Connecting to "));
      Serial.print(ssid);
    
      if (passphrase != NULL)
        WiFi.begin(ssid, passphrase);
      else
        WiFi.begin(ssid);
        
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }
    
      Serial.println("");
      Serial.print(F("Connected with IP: "));
      Serial.println(WiFi.localIP());
    
      // Choose one to begin listening for E1.31 data
      if (e131.begin(E131_UNICAST));  
      //e131.beginMulticast(ssid, passphrase,  );
    
      Serial.println(F("Listening for data..."));
    
    }
    void loop() {
      while (!e131.isEmpty()) {
        e131_packet_t packet;
        e131.pull(&packet);     // Pull packet from ring buffer
        uint16_t universe = htons(packet.universe);
        if (universe == 1) {
            for (int i = 0; i < NUM_LEDS_PER_STRIP_B; i++) {
              int j = i * 3 + (CHANNEL_START_A );
               newLeds[i] = (i, (CRGB(packet.property_values[j], packet.property_values[j + 1], packet.property_values[j + 2])));
              Serial.println(packet.property_values[j] );
            }
            FastLED.show();       
        }
        if ((universe == 2) && (packet.property_values[(CHANNEL_START_B - 1)] == (packet.property_values[245]))) {
               for (int i = 0; i < NUM_LEDS_PER_STRIP_A; i++) {
              int j = i * 3 + (CHANNEL_START_B );
              oldLeds[i] = (i, (CRGB(packet.property_values[j], packet.property_values[j + 1], packet.property_values[j + 2])));
              Serial.println(packet.property_values[j + 1] );
            }
            FastLED.show();
        }
      }
    }
    Last edited by angus40; 02-26-2020 at 03:35 PM.

  10. #10
    Join Date
    Dec 2011
    Posts
    6,319
    Post Thanks / Like

    Default Re: Esp Code for various modules

    *************SOLVED ***********

    6 GPIO on the Esp32 dev board is all I can do for pixel output .
    more learning to do
    Last edited by angus40; 02-27-2020 at 08:27 AM.

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •