Results 1 to 7 of 7

Thread: Arduino Mega 2650 - E1.31 Unicast to Universe 2

  1. #1
    Join Date
    Dec 2018
    Posts
    2
    Post Thanks / Like

    Default Arduino Mega 2650 - E1.31 Unicast to Universe 2

    I'm attempting to setup an Arduino Mega 2650 to receive E1.31 data via unicast for universe 2 to drive an 8 channel solid state relay. While I will eventually send the stream from XLights or Vixen, right now, I'm just testing with sACNView so I can really control what I'm sending. Multicast works, but only for universe 1.

    I seem to be able to set the e131.universe = 2, but universe 2 data is never returned... never. I'm not much of a coder, so I really don't know how to configure my code to do what I want:

    /*
    * E1.31_DMX_Reciever.ino - This is a simple sketch to listen for E1.31
    * data on an ethernet shield and turn on/off
    * relays on boards such as a Sainsmart 8-Channel
    * relay board.

    * Based on the E.131 (sACN) library for Arduino by Shelby Merrick
    * http://www.forkineye.com
    */

    //================================================== ============================
    // Load libraries and initialize variables and objects...
    //================================================== ============================
    #include <SPI.h>
    #include <Ethernet.h>
    #include <E131.h>

    // Set this to true (case sensitive) if you want debugging output sent to the
    // serial port so you can watch it in the serial monitor or the Arduino
    // developement software.
    bool debug = true;

    // MAC address value, Note: MACs are made-up on ethernet shields. Best to create
    // DHCP reservation for this MAC in your DHCP server/router so it always gets
    // the same IP address.
    byte mac[] = { 0xC0, 0xFF, 0xEE, 0xE1, 0x31, 0xC1 };
    // byte ip[] = { 10,0,0,101 };
    // byte nm[] = { 255,255,255,0 };
    // byte gw[] = { 10,0,0,138 };
    // byte dns[] = { 10,0,0,138 };
    uint16_t UNIVERSE = 2;
    uint8_t UNIVERSE_COUNT = 1;

    // Number of relays (channels) you will be controlling. It is also very important
    // to ensure that your software for sending E1.31 data only sends channel data
    // for this many channels.
    int ch = 8;

    // Arduino pin numbers for each relay. There should be pin numbers for each of
    // the [ch] channels above.
    int relay[]={30,31,32,33,34,35,36,37};

    // Just a counter variable
    int i=0;

    // Initiate the ethernet shieild object...
    E131 e131;

    //================================================== ============================
    void setup() {
    //================================================== ============================
    // Initialize the serial output so you can see what IP you are getting or
    // see debug output...
    Serial.begin(115200);
    delay(100);

    // Start the ethernet sheild using the MAC and IP set above...
    // e131.begin(mac,ip,nm,gw,dns);
    e131.universe = UNIVERSE;
    e131.begin(mac);
    Serial.print(F("- Universe: "));
    Serial.println(e131.universe);

    // Configure each of the pins as output and set an initial value...
    // Serial.println("Setting up GPIO channels...");
    for(i=0; i < ch; i++) // Loop through each relay and configure it
    {
    pinMode(relay[i], OUTPUT); // Set i(th) pin as output
    digitalWrite(relay[i], HIGH); // Turn the relay OFF
    }
    }

    //================================================== ============================
    void loop() {
    //================================================== ============================
    /* Parse a packet */
    uint16_t num_channels = e131.parsePacket();

    /* Process channel data if we have it */
    if (num_channels) {
    // This code is used to output status to the serial port for debugging...
    if (debug && Serial) {
    Serial.print(F("Universe "));
    Serial.print(e131.universe);
    Serial.print(F(" / "));
    Serial.print(num_channels);
    Serial.print(F(" Channels | Packet#: "));
    Serial.print(e131.stats.num_packets);
    Serial.print(F(" / Errors: "));
    Serial.print(e131.stats.packet_errors);
    Serial.print(F(" / Channels: "));
    for(i=0; i < ch; i++) {
    Serial.print(e131.data[i]);
    Serial.print(F(" : "));
    }
    Serial.println(F(" "));
    }

    for(i=0; i < ch; i++) // Loop through each relay and set relay
    {
    if (e131.data[i] < 128) {
    digitalWrite(relay[i], HIGH); // Turn the relay OFF
    } else {
    digitalWrite(relay[i], LOW); // Turn the relay ON
    }
    }
    }
    }

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

    Default Re: Arduino Mega 2650 - E1.31 Unicast to Universe 2

    Code:
    /*
    * E1.31_DMX_Reciever.ino - This is a simple sketch to listen for E1.31
    * data on an ethernet shield and turn on/off
    * relays on boards such as a Sainsmart 8-Channel
    * relay board.
    
    * Based on the E.131 (sACN) library for Arduino by Shelby Merrick
    * http://www.forkineye.com
    */
    
    //================================================== ============================
    // Load libraries and initialize variables and objects...
    //================================================== ============================
    #include <SPI.h>
    #include <Ethernet.h>
    #include <E131.h>
    
    int num_channels;  // adding this line for your e131 data may help   ("_")
    
    
    // Set this to true (case sensitive) if you want debugging output sent to the
    // serial port so you can watch it in the serial monitor or the Arduino
    // developement software.
    bool debug = true;
    
    // MAC address value, Note: MACs are made-up on ethernet shields. Best to create
    // DHCP reservation for this MAC in your DHCP server/router so it always gets
    // the same IP address.
    byte mac[] = { 0xC0, 0xFF, 0xEE, 0xE1, 0x31, 0xC1 };
    // byte ip[] = { 10,0,0,101 };<<<< this is lower than your gw - not sure this is right
    // byte nm[] = { 255,255,255,0 };
    // byte gw[] = { 10,0,0,138 };
    // byte dns[] = { 10,0,0,138 };
    #define UNIVERSE 2  // definite
    uint8_t UNIVERSE_COUNT = 1; // should this be 2 ?  
    
    // Number of relays (channels) you will be controlling. It is also very important
    // to ensure that your software for sending E1.31 data only sends channel data
    // for this many channels.
    int ch = 8;
    
    // Arduino pin numbers for each relay. There should be pin numbers for each of
    // the [ch] channels above.
    int relay[]={30,31,32,33,34,35,36,37};
    
    // Just a counter variable
    int i=0;
    
    // Initiate the ethernet shieild object...
    E131 e131;
    
    //================================================== ============================
    void setup() {
    //================================================== ============================
    // Initialize the serial output so you can see what IP you are getting or
    // see debug output...
    Serial.begin(115200);
    delay(100);
    
    // Start the ethernet sheild using the MAC and IP set above...
    // e131.begin(mac,ip,nm,gw,dns);
    e131.universe = UNIVERSE ;
    e131.begin(mac);
    Serial.print(F("- Universe: "));
    Serial.println(e131.universe);
    
    // Configure each of the pins as output and set an initial value...
    // Serial.println("Setting up GPIO channels...");
    for(i=0; i < ch; i++) // Loop through each relay and configure it
    {
    pinMode(relay[i], OUTPUT); // Set i(th) pin as output
    digitalWrite(relay[i], HIGH); // Turn the relay OFF
    }
    }
    
    //================================================== ============================
    void loop() {
    //================================================== ============================
    /* Parse a packet */
    uint16_t num_channels = e131.parsePacket();
    
    /* Process channel data if we have it */
    if (num_channels == 0) 
       return;
     if (e131.universe == 2) {   // great code from a good friend which may help you also  :)
    // This code is used to output status to the serial port for debugging...
    if (debug && Serial) {
    Serial.print(F("Universe "));
    Serial.print(e131.universe);
    Serial.print(F(" / "));
    Serial.print(num_channels);
    Serial.print(F(" Channels | Packet#: "));
    Serial.print(e131.stats.num_packets);
    Serial.print(F(" / Errors: "));
    Serial.print(e131.stats.packet_errors);
    Serial.print(F(" / Channels: "));
    for(i=0; i < ch; i++) {
    Serial.print(e131.data[i]);
    Serial.print(F(" : "));
    }
    Serial.println(F(" "));
    }
    
    for(i=0; i < ch; i++) // Loop through each relay and set relay
    {
    if (e131.data[i] < 128) {
    digitalWrite(relay[i], HIGH); // Turn the relay OFF
    } else {
    digitalWrite(relay[i], LOW); // Turn the relay ON  
    }
    }
    }
    }
    Last edited by angus40; 11-13-2019 at 12:55 AM.

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

    Default Re: Arduino Mega 2650 - E1.31 Unicast to Universe 2

    One of those changes may help . Most likely line 32 , universe count =1 should be 2 .
    Last edited by angus40; 11-13-2019 at 04:51 AM.

  4. #4
    Join Date
    Jan 2019
    Posts
    73
    Post Thanks / Like

    Default Re: Arduino Mega 2650 - E1.31 Unicast to Universe 2

    Are you using mega with built in wifi esp 8266?

  5. #5
    Join Date
    Dec 2018
    Posts
    2
    Post Thanks / Like

    Default Re: Arduino Mega 2650 - E1.31 Unicast to Universe 2

    angus40 and mojuave1... thanks for the replies...

    I'm using a mega with an Ethernet shield on top...

    There are actually a couple things I can't seem to get working

    1) I can never get it to respond to Unicast packets even though it reports it is listening on port 5568 for unicast packets.
    2) I can never get it to listen for data sent to universe 2... it seems to only be able to listen for data on universe 1.

    Here is some output and the associated code (Note: DHCP reservation is being used as well).

    Code:
    Requesting Address via DHCP
    - MAC: C0FFEEE131C1
    - IP Address: 10.0.0.101
    - Unicast port: 5568
    - Universe: 2
    Universe 1 / 8 Channels | Packet#: 1 / Errors: 0 / Channels: 0 : 0 : 0 : 0 : 0 : 0 : 0 : 0 :  
    Universe 1 / 8 Channels | Packet#: 2 / Errors: 0 / Channels: 0 : 0 : 0 : 0 : 0 : 0 : 0 : 0 :  
    Universe 1 / 8 Channels | Packet#: 3 / Errors: 0 / Channels: 0 : 0 : 0 : 0 : 0 : 0 : 0 : 0 :  
    Universe 1 / 8 Channels | Packet#: 4 / Errors: 0 / Channels: 0 : 0 : 0 : 0 : 0 : 0 : 0 : 0 :  
    Universe 1 / 8 Channels | Packet#: 5 / Errors: 0 / Channels: 0 : 0 : 0 : 0 : 0 : 0 : 0 : 0 :  
    Universe 1 / 8 Channels | Packet#: 6 / Errors: 0 / Channels: 3 : 0 : 0 : 0 : 0 : 0 : 0 : 0 :  
    Universe 1 / 8 Channels | Packet#: 7 / Errors: 0 / Channels: 19 : 0 : 0 : 0 : 0 : 0 : 0 : 0 :  
    Universe 1 / 8 Channels | Packet#: 8 / Errors: 0 / Channels: 41 : 0 : 0 : 0 : 0 : 0 : 0 : 0 :  
    Universe 1 / 8 Channels | Packet#: 9 / Errors: 0 / Channels: 63 : 0 : 0 : 0 : 0 : 0 : 0 : 0 :  
    Universe 1 / 8 Channels | Packet#: 10 / Errors: 0 / Channels: 113 : 0 : 0 : 0 : 0 : 0 : 0 : 0 :  
    Universe 1 / 8 Channels | Packet#: 11 / Errors: 0 / Channels: 144 : 0 : 0 : 0 : 0 : 0 : 0 : 0 :  
    Universe 1 / 8 Channels | Packet#: 12 / Errors: 0 / Channels: 187 : 0 : 0 : 0 : 0 : 0 : 0 : 0 :  
    Universe 1 / 8 Channels | Packet#: 13 / Errors: 0 / Channels: 217 : 0 : 0 : 0 : 0 : 0 : 0 : 0 :  
    Universe 1 / 8 Channels | Packet#: 14 / Errors: 0 / Channels: 242 : 0 : 0 : 0 : 0 : 0 : 0 : 0 :  
    Universe 1 / 8 Channels | Packet#: 15 / Errors: 0 / Channels: 255 : 0 : 0 : 0 : 0 : 0 : 0 : 0 :  
    Universe 1 / 8 Channels | Packet#: 16 / Errors: 0 / Channels: 252 : 0 : 0 : 0 : 0 : 0 : 0 : 0 :  
    Universe 1 / 8 Channels | Packet#: 17 / Errors: 0 / Channels: 212 : 0 : 0 : 0 : 0 : 0 : 0 : 0 :  
    Universe 1 / 8 Channels | Packet#: 18 / Errors: 0 / Channels: 179 : 0 : 0 : 0 : 0 : 0 : 0 : 0 :  
    Universe 1 / 8 Channels | Packet#: 19 / Errors: 0 / Channels: 132 : 0 : 0 : 0 : 0 : 0 : 0 : 0 :  
    Universe 1 / 8 Channels | Packet#: 20 / Errors: 0 / Channels: 78 : 0 : 0 : 0 : 0 : 0 : 0 : 0 :  
    Universe 1 / 8 Channels | Packet#: 21 / Errors: 0 / Channels: 50 : 0 : 0 : 0 : 0 : 0 : 0 : 0 :  
    Universe 1 / 8 Channels | Packet#: 22 / Errors: 0 / Channels: 26 : 0 : 0 : 0 : 0 : 0 : 0 : 0 :  
    Universe 1 / 8 Channels | Packet#: 23 / Errors: 0 / Channels: 0 : 0 : 0 : 0 : 0 : 0 : 0 : 0 :  
    Universe 1 / 8 Channels | Packet#: 24 / Errors: 0 / Channels: 0 : 0 : 0 : 0 : 0 : 0 : 0 : 0 :  
    Universe 1 / 8 Channels | Packet#: 25 / Errors: 0 / Channels: 0 : 0 : 0 : 0 : 0 : 0 : 0 : 0 :  
    Universe 1 / 8 Channels | Packet#: 26 / Errors: 0 / Channels: 0 : 0 : 0 : 0 : 0 : 0 : 0 : 0 :  
    Universe 1 / 8 Channels | Packet#: 27 / Errors: 0 / Channels: 0 : 0 : 0 : 0 : 0 : 0 : 0 : 0 :  
    Universe 1 / 8 Channels | Packet#: 28 / Errors: 0 / Channels: 0 : 0 : 0 : 0 : 0 : 0 : 0 : 0 :  
    Universe 1 / 8 Channels | Packet#: 29 / Errors: 0 / Channels: 0 : 0 : 0 : 0 : 0 : 0 : 0 : 0 :
    ... and the source code.

    Code:
    /*
    * E1.31_DMX_Reciever.ino
    * 
    * This is a simple sketch to listen for E1.31
    * DMX data on an ethernet shield and turn on/off relays on boards such 
    * as a Sainsmart 8-Channel relay boards. 
    
    * Based on the E.131 (sACN) library for Arduino by Shelby Merrick
    * http://www.forkineye.com
    * 
    * A great tool for sending DMX data over E1.31 for testing sACNView... last 
    * found at https://sacnview.org/
    */
    
    //==============================================================================
    // Load libraries and initialize variables and objects...
    //==============================================================================
    #include <SPI.h>
    #include <Ethernet.h>
    #include <E131.h>
    
    // Set this to true (case sensitive) if you want debugging output sent to the
    // serial port so you can watch it in the serial monitor or the Arduino
    // developement software.
    bool debug = true;
    
    // MAC address value, Note: MACs are made-up on ethernet shields. Best to create
    // DHCP reservation for this MAC in your DHCP server/router so it always gets 
    // the same IP address.
    byte mac[] = { 0xC0, 0xFF, 0xEE, 0xE1, 0x31, 0xC1 };
    // byte ip[]  = { 10,0,0,101 };
    // byte nm[]  = { 255,255,255,0 };
    // byte gw[]  = { 10,0,0,138 };
    // byte dns[] = { 10,0,0,138 };
    uint16_t UNIVERSE = 2;
    uint8_t  UNIVERSE_COUNT = 2;
    
    // Number of relays (channels) you will be controlling. It is also very important
    // to ensure that your software for sending E1.31 data only sends channel data
    // for this many channels.                         
    int ch = 8;
    
    // Arduino pin numbers for each relay. There should be pin numbers for each of
    // the [ch] channels above.
    int relay[]={30,31,32,33,34,35,36,37};
    
    // Just a counter variable
    int i=0;
                    
    // Initiate the ethernet shieild object...
    E131 e131;
    
    //==============================================================================
    void setup() {
    //==============================================================================
        // Initialize the serial output so you can see what IP you are getting or
        // see debug output...
        Serial.begin(115200);
        delay(100);
    
        // Start the ethernet sheild using the MAC and IP set above...
        // e131.begin(mac,ip,nm,gw,dns);
        e131.universe = UNIVERSE;
        e131.begin(mac);
        Serial.print(F("- Universe: "));
        Serial.println(e131.universe);
    
        // Configure each of the pins as output and set an initial value...
        // Serial.println("Setting up GPIO channels...");
        for(i=0; i < ch; i++)           // Loop through each relay and configure it
        {
          // Note set this initially to HIGH for a mechanical relay like a Sainsmart 8
          // channel mechanica relay and LOW for a Solid State Relay such as a 
          // Sainsmart 8 channel high level trigger relay board.    
          pinMode(relay[i], OUTPUT);    // Set i(th) pin as output
          digitalWrite(relay[i], LOW);  // Turn the relay OFF  
        }      
    }
    
    //==============================================================================
    void loop() {
    //==============================================================================
        /* Parse a packet */
        uint16_t num_channels = e131.parsePacket();
        
        /* Process channel data if we have it */
        if (num_channels) {
            // This code is used to output status to the serial port for debugging...
            if (debug && Serial) {
              Serial.print(F("Universe "));
              Serial.print(e131.universe);
              Serial.print(F(" / "));
              Serial.print(num_channels);
              Serial.print(F(" Channels | Packet#: "));
              Serial.print(e131.stats.num_packets);
              Serial.print(F(" / Errors: "));
              Serial.print(e131.stats.packet_errors);
              Serial.print(F(" / Channels: "));
              for(i=0; i < ch; i++) {
                Serial.print(e131.data[i]);
                Serial.print(F(" : "));
              }
              Serial.println(F(" "));
            }
    
            for(i=0; i < ch; i++) // Loop through each relay and set relay
            {    
              if (e131.data[i] < 128) {
                // Sainsmart 8 channel mechanical relay - HIGH = OFF 
                // Sainsmart 8 channel solid state relay - LOW = OFF
                digitalWrite(relay[i], LOW); // Turn the relay OFF
              } else {
                digitalWrite(relay[i], HIGH);  // Turn the relay ON
              }
            }
        }
    }

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

    Default Re: Arduino Mega 2650 - E1.31 Unicast to Universe 2

    The solution can be found on this page .

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

    Default Re: Arduino Mega 2650 - E1.31 Unicast to Universe 2

    Here is a Step by Step tutorial that looks real helpful for Arduino users .

    https://www.instructables.com/id/Com...-With-Arduino/

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
  •