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

Thread: Arduino with Ethernet shield

  1. #1
    Join Date
    Mar 2017
    Location
    Clinton Twp. Michigan
    Posts
    107
    Post Thanks / Like

    Default Arduino with Ethernet shield

    A few years ago I ran a light show with a Arduino and 8 SSR, worked great. Now the passed year I got in to E1.31 and I was wondering I if could put a Ethernet shield on my Arduino so I could connect the E1.31 to my show? If so how would I go about it. I have a DIY E1.31 bridge so I can run DMX ( I have a DMX shield also) or Renard. I still want to use my 8 SSR just on/off. That is what my Arduino sketch did, or do I need a new sketch? I wanted to add more lights to my show this year trying to use what I have laying around . Any ideals.

    I have tried to find something on this site with no results. I am still new at this. Trying to lean as much as I can. I am not a programmer but welling to learn if need be.


    Tony

  2. #2
    Join Date
    Dec 2014
    Location
    Southern California
    Posts
    1,202
    Post Thanks / Like

    Default Re: Arduino with Ethernet shield

    Kevin

  3. #3
    Join Date
    Jul 2014
    Location
    Missouri
    Posts
    141
    Post Thanks / Like

    Default Re: Arduino with Ethernet shield

    I run this sketch by a member of the forum for e1.31 control of relays on an arduino with ethershield.

    Code:
    /*
    Original code created January 4th, 2014 by Claude Heintz http://lx.claudeheintzdesign.com/lxarduino_sketches.html
     
    modified by: Jared Alexander
    This code is in the public domain.
    sACN E 1.31 is a public standard published by the PLASA technical standards program
    http://tsp.plasa.org/tsp/documents/published_docs.php
    Requires Arduino Ethernet Shield. Modifed to use the lastest version of Ethernet library included in Arduino 1.6.1. No need to install other libraries.
    Receives E1.31 data (SACN) and ArtNet data for control of relays. This sketch is designed for use with SainSmart Relay boards. 
    You can only send the Arduino one protocol (E1.31 or ArtNet) at a time.
    This sketch also includes a power on self test function to make sure everything is hooked up properly.
    */
     
    #include <SPI.h>    //Standard Library    
    #include <Ethernet.h> //Standard Library
    #include <EthernetUdp.h> //Standard Library
     
     
    /*  set the desired subnet and universe (first universe is 0)
        sACN starts with universe 1 so subtract 1 from sACN universe
        to get DMX_UNIVERSE.                                           */
    #define ARTNET_SUBNET 0 //defualt subnet is 0. Should not need to be changed.
    #define ARTNET_UNIVERSE 0 //first universe being used
    #define E131_SUBNET 0 //defualt subnet is 0. Should not need to be changed.
    #define ETHERNET_BUFFER_MAX 640
    #define ARTNET_ARTDMX 0x5000
    #define ARTNET_ARTPOLL 0x2000
    #define ARTNET_PORT 0x1936 //standard port
    #define ARTNET_START_ADDRESS 18 //Byte 18 in the packet contains channel 1 values. 
    #define E131_PORT 5568 //standard port
    #define E131_START_ADDRESS 126 //Byte 126 in the packet contains channel 1 values. Offset is set to one prior.
    #define STATUS_LED 13 //shows us when we are receiving data
    #define SDCARD_CONTROL 4 //set pin 4 to high to disable SD card interface on WiFi shield
    #define NUM_RELAYS 8 //total number of relays used
     
    int channel; //channel increment
     
    //Relay Pins array
    int Relay[] = {22, 23, 24, 25, 26, 27, 28, 29};
     
    //Timer Setup
    volatile byte currentcounter = 0; //counter for data reception
    byte previouscounter = 0; //counter for data reception
    unsigned long currentDelay = 0; //current time value for ArtNet and E1.31 reception
     
    //Ethernet Configuration
    byte mac[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
    IPAddress ip(192, 168, 1, 120);  //IP address of ethernet shield
     
    // buffer to hold E1.31 and Artnet data
    unsigned char packetBuffer[ETHERNET_BUFFER_MAX];
     
    // An EthernetUDP instance to let us send and receive packets over UDP
    // aUDP creates a socket for an Art-Net port
    // suUDP creates a socket for sACN that is unicast to the ip address
    EthernetUDP aUDP;
    EthernetUDP suUDP;
     
    void setup()
    {
      pinMode(STATUS_LED, OUTPUT); //Initialize status LED
      pinMode(SDCARD_CONTROL, OUTPUT); //Initialize Pin 4
      digitalWrite(SDCARD_CONTROL, HIGH); //Set pin 4 to high since we are not using the SD Card interface
      for(int a = 0; a < NUM_RELAYS; a++) //loop to initialize relay control pins
      {
       pinMode(Relay[a], OUTPUT); //initialize relay output pins
       digitalWrite(Relay[a], HIGH); //set pins to high for off
      }
      Ethernet.begin(mac,ip);  //Initialize Ethernet shield
      aUDP.begin(ARTNET_PORT); //Open Artnet Port
      suUDP.begin(E131_PORT); //Open E1.31 Port
      Serial.begin(9600); //Serial for debugging
      POST(); //Run Power On Self Test Function
      Serial.println("Setup Complete"); //print complete
    }
     
    /* artDMXReceived checks the universe and subnet then
       outputs the data to the relays */
     
    void artDMXReceived(unsigned char* pbuff)
    {
      if ( (pbuff[14] & 0xF) == ARTNET_UNIVERSE )
      {
        if ( (pbuff[14] >> 8) == ARTNET_SUBNET )
        {
          channel = 0; //reset channel offset to 0 each time through loop
          //loop turns relay on/off based on channel value starting at Artnet start address
          for(int b = 0; b < NUM_RELAYS; b++)
          {
           if(pbuff[ARTNET_START_ADDRESS + channel] > 127) //if channel value is greater then 127
          {
           digitalWrite(Relay[b], LOW); //turn relay on
          }
          else
          {
           digitalWrite(Relay[b], HIGH); //else turn it off
          }
          channel++; //increase channel offset by 1 each time through for loop
          }
        }
      }
    } //end artDMXReceived
     
    /*  artNetOpCode checks to see that the packet is actually Art-Net
        and returns the opcode telling what kind of Art-Net message it is.  */
     
    int artNetOpCode(unsigned char* pbuff)
    {
      String test = String((char*)pbuff);
      if ( test.equals("Art-Net") )
      {
        if ( pbuff[11] >= 14 )
        {            //protocol version [10] hi byte [11] lo byte
          return pbuff[9] *256 + pbuff[8];  //opcode lo byte first
        }
      }
     
      return 0;
    }
     
    /* sacnDMXReceived checks the universe and subnet then
       outputs the data to relays  */
     
    void sacnDMXReceived(unsigned char* pbuff, int count)
    {
        if ( pbuff[113] == E131_SUBNET )
      { 
          int addressOffset = 125; //first 125 bytes of packet are header information
          if ( pbuff[addressOffset] == 0 ) //start code must be 0
          { 
           channel = 0; //reset channel offset to 0 each time through loop
           //loop turns relay on/off based on channel value starting at E1.31 start address
          for(int c = 0; c < NUM_RELAYS; c++)
          {
           if(pbuff[E131_START_ADDRESS + channel] > 127) //if channel value is greater then 127
          {
           digitalWrite(Relay[c], LOW); //turn relay on
          }
          else
          {
           digitalWrite(Relay[c], HIGH); //turn relay off
          }
          channel++; //increment channel offset by 1
          }
          }
          }
        } //end sacnDMXReceived
        
      
      
    //checks to see if packet is E1.31 data
    int checkACNHeaders(unsigned char* messagein, int messagelength)
    {
      if ( messagein[1] == 0x10 && messagein[4] == 0x41 && messagein[12] == 0x37)
      {    
          int addresscount = messagein[123] * 256 + messagein[124]; // number of values plus start code
          return addresscount -1; //Return how many values are in the packet.
        }
      return 0;
    }
     
    /************************************************************************
     
      The main loop checks for and reads packets from the two UDP ethernet
      socket connections.  When a packet is recieved, it is checked to see if
      it is valid and then one of the DMXReceived functions is called, sending
      the DMX values to the output. There also is a timer to run a standby
      program if no data is received for 30 seconds.
     
    *************************************************************************/
     
    void loop()
    {
      if(currentcounter != previouscounter) //has the value changed?
      {
        currentDelay = millis(); //store the time since the value has increased
        previouscounter = currentcounter; //set the previous value equal to the current value
      }
     
      if(millis() - currentDelay > 30000) //is the time since the value changed greater than 30 seconds?
      {
       digitalWrite(STATUS_LED, LOW); //turn LED off. Not receiving E1.31 or ArtNet.
      }
     
      // first check to see if a packet is available on the Art-Net port
      int packetSize = aUDP.parsePacket();
      if( packetSize )
      {
        aUDP.read(packetBuffer, ETHERNET_BUFFER_MAX);
        /* after reading the packet into the buffer, check to make sure
           that it is an Art-Net packet and retrieve the opcode that
           tells what kind of message it is                         */
        int opcode = artNetOpCode(packetBuffer);
        if ( opcode == ARTNET_ARTDMX )
        {
          Serial.println("ArtNet Packet Received");
          artDMXReceived(packetBuffer);
          currentcounter++;  //increase counter by 1 each time through
          digitalWrite(STATUS_LED, HIGH); //turn status LED on
        }
      }
        else
        {
          /* then, if still no packet, check to see if a packet
             is available on the sACN unicastcast port         */
           packetSize = suUDP.parsePacket();
        if( packetSize )
        {
          suUDP.read(packetBuffer, ETHERNET_BUFFER_MAX);
          /* after reading the packet into the buffer, check to make sure
           that it is a valid sACN packet.*/
          int count = checkACNHeaders(packetBuffer, packetSize);
          if ( count )
          {
            Serial.println("E131 Packet Received");
            sacnDMXReceived(packetBuffer, count);
            currentcounter++;  //increase counter by 1 each time through
          digitalWrite(STATUS_LED, HIGH); //turn status LED on
          }
        }
         
        }
     
    } //End loop
     
    //Power on self test function to make sure everything is connected properly.
    void POST()
    {
      digitalWrite(Relay[0], LOW);
      delay(1000);
      digitalWrite(Relay[0], HIGH);
      digitalWrite(Relay[1], LOW);
      delay(1000);
      digitalWrite(Relay[1], HIGH);
      digitalWrite(Relay[2], LOW);
      delay(1000);
      digitalWrite(Relay[2], HIGH);
      digitalWrite(Relay[3], LOW);
      delay(1000);
      digitalWrite(Relay[3], HIGH);
      digitalWrite(Relay[4], LOW);
      delay(1000);
      digitalWrite(Relay[4], HIGH);
      digitalWrite(Relay[5], LOW);
      delay(1000);
      digitalWrite(Relay[5], HIGH);
      digitalWrite(Relay[6], LOW);
      delay(1000);
      digitalWrite(Relay[6], HIGH);
      digitalWrite(Relay[7], LOW);
      delay(1000);
      digitalWrite(Relay[7], HIGH);
      Serial.println("POST Complete");
    }

  4. Thanks AJVenti thanked for this post
  5. #4
    Join Date
    Oct 2014
    Location
    Sauk City, WI USA
    Posts
    1,797
    Post Thanks / Like

    Default Re: Arduino with Ethernet shield

    With the bridge running Renard out, you can easily build a simple sketch to receive the data and turn on some relays. Renard is slightly different from simple serial but not difficult to work with.

  6. #5
    Join Date
    Mar 2017
    Location
    Clinton Twp. Michigan
    Posts
    107
    Post Thanks / Like

    Default Re: Arduino with Ethernet shield

    The sketch from jwamsley07 worked great THANK
    Still playing with it need to input in to my VIXEN 3 and see how it works with what I have

    When are talking about a Renard sketch what is that?

  7. #6
    Join Date
    Oct 2014
    Location
    Sauk City, WI USA
    Posts
    1,797
    Post Thanks / Like

    Default Re: Arduino with Ethernet shield

    The renard protocol has a couple of data values that have special purposes and it has a way of addressing a specific controller. It isn't a one for one protocol like the data portion of the E1.31. If you are happy with the E1.31 solution and have it running, just do that. So much easier than messing around with other solutions. MadSci (Bill Porter) wrote a Renard "library" that handles the protocol. It is here if you are interested:
    https://github.com/madsci1016/Arduino-Renard
    I have been playing with it and found what seems to be an issue with the library. But you can just take out the transmit part if you are not using it and it receives a packet of data for you. See the example included for how easy it is to get the Renard data.

  8. #7
    Join Date
    Dec 2013
    Location
    Williamsburg, VA
    Posts
    923
    Post Thanks / Like

    Default Re: Arduino with Ethernet shield

    Quote Originally Posted by jwamsley07 View Post
    I run this sketch by a member of the forum for e1.31 control of relays on an arduino with ethershield.

    Code:
    /*
    Original code created January 4th, 2014 by Claude Heintz http://lx.claudeheintzdesign.com/lxarduino_sketches.html
     
    modified by: Jared Alexander
    This code is in the public domain.
    sACN E 1.31 is a public standard published by the PLASA technical standards program
    http://tsp.plasa.org/tsp/documents/published_docs.php
    Requires Arduino Ethernet Shield. Modifed to use the lastest version of Ethernet library included in Arduino 1.6.1. No need to install other libraries.
    Receives E1.31 data (SACN) and ArtNet data for control of relays. This sketch is designed for use with SainSmart Relay boards. 
    You can only send the Arduino one protocol (E1.31 or ArtNet) at a time.
    This sketch also includes a power on self test function to make sure everything is hooked up properly.
    */
     
    #include <SPI.h>    //Standard Library    
    #include <Ethernet.h> //Standard Library
    #include <EthernetUdp.h> //Standard Library
     
     
    /*  set the desired subnet and universe (first universe is 0)
        sACN starts with universe 1 so subtract 1 from sACN universe
        to get DMX_UNIVERSE.                                           */
    #define ARTNET_SUBNET 0 //defualt subnet is 0. Should not need to be changed.
    #define ARTNET_UNIVERSE 0 //first universe being used
    #define E131_SUBNET 0 //defualt subnet is 0. Should not need to be changed.
    #define ETHERNET_BUFFER_MAX 640
    #define ARTNET_ARTDMX 0x5000
    #define ARTNET_ARTPOLL 0x2000
    #define ARTNET_PORT 0x1936 //standard port
    #define ARTNET_START_ADDRESS 18 //Byte 18 in the packet contains channel 1 values. 
    #define E131_PORT 5568 //standard port
    #define E131_START_ADDRESS 126 //Byte 126 in the packet contains channel 1 values. Offset is set to one prior.
    #define STATUS_LED 13 //shows us when we are receiving data
    #define SDCARD_CONTROL 4 //set pin 4 to high to disable SD card interface on WiFi shield
    #define NUM_RELAYS 8 //total number of relays used
     
    int channel; //channel increment
     
    //Relay Pins array
    int Relay[] = {22, 23, 24, 25, 26, 27, 28, 29};
     
    //Timer Setup
    volatile byte currentcounter = 0; //counter for data reception
    byte previouscounter = 0; //counter for data reception
    unsigned long currentDelay = 0; //current time value for ArtNet and E1.31 reception
     
    //Ethernet Configuration
    byte mac[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
    IPAddress ip(192, 168, 1, 120);  //IP address of ethernet shield
     
    // buffer to hold E1.31 and Artnet data
    unsigned char packetBuffer[ETHERNET_BUFFER_MAX];
     
    // An EthernetUDP instance to let us send and receive packets over UDP
    // aUDP creates a socket for an Art-Net port
    // suUDP creates a socket for sACN that is unicast to the ip address
    EthernetUDP aUDP;
    EthernetUDP suUDP;
     
    void setup()
    {
      pinMode(STATUS_LED, OUTPUT); //Initialize status LED
      pinMode(SDCARD_CONTROL, OUTPUT); //Initialize Pin 4
      digitalWrite(SDCARD_CONTROL, HIGH); //Set pin 4 to high since we are not using the SD Card interface
      for(int a = 0; a < NUM_RELAYS; a++) //loop to initialize relay control pins
      {
       pinMode(Relay[a], OUTPUT); //initialize relay output pins
       digitalWrite(Relay[a], HIGH); //set pins to high for off
      }
      Ethernet.begin(mac,ip);  //Initialize Ethernet shield
      aUDP.begin(ARTNET_PORT); //Open Artnet Port
      suUDP.begin(E131_PORT); //Open E1.31 Port
      Serial.begin(9600); //Serial for debugging
      POST(); //Run Power On Self Test Function
      Serial.println("Setup Complete"); //print complete
    }
     
    /* artDMXReceived checks the universe and subnet then
       outputs the data to the relays */
     
    void artDMXReceived(unsigned char* pbuff)
    {
      if ( (pbuff[14] & 0xF) == ARTNET_UNIVERSE )
      {
        if ( (pbuff[14] >> 8) == ARTNET_SUBNET )
        {
          channel = 0; //reset channel offset to 0 each time through loop
          //loop turns relay on/off based on channel value starting at Artnet start address
          for(int b = 0; b < NUM_RELAYS; b++)
          {
           if(pbuff[ARTNET_START_ADDRESS + channel] > 127) //if channel value is greater then 127
          {
           digitalWrite(Relay[b], LOW); //turn relay on
          }
          else
          {
           digitalWrite(Relay[b], HIGH); //else turn it off
          }
          channel++; //increase channel offset by 1 each time through for loop
          }
        }
      }
    } //end artDMXReceived
     
    /*  artNetOpCode checks to see that the packet is actually Art-Net
        and returns the opcode telling what kind of Art-Net message it is.  */
     
    int artNetOpCode(unsigned char* pbuff)
    {
      String test = String((char*)pbuff);
      if ( test.equals("Art-Net") )
      {
        if ( pbuff[11] >= 14 )
        {            //protocol version [10] hi byte [11] lo byte
          return pbuff[9] *256 + pbuff[8];  //opcode lo byte first
        }
      }
     
      return 0;
    }
     
    /* sacnDMXReceived checks the universe and subnet then
       outputs the data to relays  */
     
    void sacnDMXReceived(unsigned char* pbuff, int count)
    {
        if ( pbuff[113] == E131_SUBNET )
      { 
          int addressOffset = 125; //first 125 bytes of packet are header information
          if ( pbuff[addressOffset] == 0 ) //start code must be 0
          { 
           channel = 0; //reset channel offset to 0 each time through loop
           //loop turns relay on/off based on channel value starting at E1.31 start address
          for(int c = 0; c < NUM_RELAYS; c++)
          {
           if(pbuff[E131_START_ADDRESS + channel] > 127) //if channel value is greater then 127
          {
           digitalWrite(Relay[c], LOW); //turn relay on
          }
          else
          {
           digitalWrite(Relay[c], HIGH); //turn relay off
          }
          channel++; //increment channel offset by 1
          }
          }
          }
        } //end sacnDMXReceived
        
      
      
    //checks to see if packet is E1.31 data
    int checkACNHeaders(unsigned char* messagein, int messagelength)
    {
      if ( messagein[1] == 0x10 && messagein[4] == 0x41 && messagein[12] == 0x37)
      {    
          int addresscount = messagein[123] * 256 + messagein[124]; // number of values plus start code
          return addresscount -1; //Return how many values are in the packet.
        }
      return 0;
    }
     
    /************************************************************************
     
      The main loop checks for and reads packets from the two UDP ethernet
      socket connections.  When a packet is recieved, it is checked to see if
      it is valid and then one of the DMXReceived functions is called, sending
      the DMX values to the output. There also is a timer to run a standby
      program if no data is received for 30 seconds.
     
    *************************************************************************/
     
    void loop()
    {
      if(currentcounter != previouscounter) //has the value changed?
      {
        currentDelay = millis(); //store the time since the value has increased
        previouscounter = currentcounter; //set the previous value equal to the current value
      }
     
      if(millis() - currentDelay > 30000) //is the time since the value changed greater than 30 seconds?
      {
       digitalWrite(STATUS_LED, LOW); //turn LED off. Not receiving E1.31 or ArtNet.
      }
     
      // first check to see if a packet is available on the Art-Net port
      int packetSize = aUDP.parsePacket();
      if( packetSize )
      {
        aUDP.read(packetBuffer, ETHERNET_BUFFER_MAX);
        /* after reading the packet into the buffer, check to make sure
           that it is an Art-Net packet and retrieve the opcode that
           tells what kind of message it is                         */
        int opcode = artNetOpCode(packetBuffer);
        if ( opcode == ARTNET_ARTDMX )
        {
          Serial.println("ArtNet Packet Received");
          artDMXReceived(packetBuffer);
          currentcounter++;  //increase counter by 1 each time through
          digitalWrite(STATUS_LED, HIGH); //turn status LED on
        }
      }
        else
        {
          /* then, if still no packet, check to see if a packet
             is available on the sACN unicastcast port         */
           packetSize = suUDP.parsePacket();
        if( packetSize )
        {
          suUDP.read(packetBuffer, ETHERNET_BUFFER_MAX);
          /* after reading the packet into the buffer, check to make sure
           that it is a valid sACN packet.*/
          int count = checkACNHeaders(packetBuffer, packetSize);
          if ( count )
          {
            Serial.println("E131 Packet Received");
            sacnDMXReceived(packetBuffer, count);
            currentcounter++;  //increase counter by 1 each time through
          digitalWrite(STATUS_LED, HIGH); //turn status LED on
          }
        }
         
        }
     
    } //End loop
     
    //Power on self test function to make sure everything is connected properly.
    void POST()
    {
      digitalWrite(Relay[0], LOW);
      delay(1000);
      digitalWrite(Relay[0], HIGH);
      digitalWrite(Relay[1], LOW);
      delay(1000);
      digitalWrite(Relay[1], HIGH);
      digitalWrite(Relay[2], LOW);
      delay(1000);
      digitalWrite(Relay[2], HIGH);
      digitalWrite(Relay[3], LOW);
      delay(1000);
      digitalWrite(Relay[3], HIGH);
      digitalWrite(Relay[4], LOW);
      delay(1000);
      digitalWrite(Relay[4], HIGH);
      digitalWrite(Relay[5], LOW);
      delay(1000);
      digitalWrite(Relay[5], HIGH);
      digitalWrite(Relay[6], LOW);
      delay(1000);
      digitalWrite(Relay[6], HIGH);
      digitalWrite(Relay[7], LOW);
      delay(1000);
      digitalWrite(Relay[7], HIGH);
      Serial.println("POST Complete");
    }
    This approach is what I'm looking for to run on a WeMos D1 board with ESP 8266 chip.
    wemos.JPG

    I want to run this shield on it that controls EL Wire. I have this Board from SparkFun working from Vixen but using Serial. I want to use E1.31 so that I can use WiFi to connect 3 or 4 of these together.
    This is the shield that I want to use on the WeMos.
    sparkfun_escudo.jpg
    I've heard the ESPixel Stick firmware will run on the WeMos because it is the same chip and all that would need to be modified is the portion of the code that controls the output. Not being a programmer, this is difficult for me. The working sketch for the standalone board is here

    Any thoughts on using the E1.31 sketch above to control the EL Wire shield? Is this as simple as modifying the outputs from the "relays" to the Pins on the El Wire Shield? or is it a total rewrite?

  9. #8
    Join Date
    Dec 2011
    Location
    UK S80 postcode
    Posts
    1,519
    Post Thanks / Like

    Default Re: Arduino with Ethernet shield

    Quote Originally Posted by JCook View Post
    This approach is what I'm looking for to run on a WeMos D1 board with ESP 8266 chip.
    wemos.JPG

    I want to run this shield on it that controls EL Wire. I have this Board from SparkFun working from Vixen but using Serial. I want to use E1.31 so that I can use WiFi to connect 3 or 4 of these together.
    This is the shield that I want to use on the WeMos.
    sparkfun_escudo.jpg
    I've heard the ESPixel Stick firmware will run on the WeMos because it is the same chip and all that would need to be modified is the portion of the code that controls the output. Not being a programmer, this is difficult for me. The working sketch for the standalone board is here

    Any thoughts on using the E1.31 sketch above to control the EL Wire shield? Is this as simple as modifying the outputs from the "relays" to the Pins on the El Wire Shield? or is it a total rewrite?
    Hi, hava look at this:
    http://doityourselfchristmas.com/for...ips-amp-floods

    If you have any questions post them in the tread (not this one) as I don't want to hijack it.

  10. Thanks JCook thanked for this post
  11. #9
    Join Date
    Mar 2017
    Location
    Clinton Twp. Michigan
    Posts
    107
    Post Thanks / Like

    Default Re: Arduino with Ethernet shield

    Well the sketch from jwamsley07 works great by it self. I tried to add it to my Vixen program and it went nuts. Not sure why can someone tell me what I did wrong.

  12. #10
    Join Date
    Jul 2014
    Location
    Missouri
    Posts
    141
    Post Thanks / Like

    Default Re: Arduino with Ethernet shield

    After getting the correct universe and outputs in the sketch, I just patched it in to vixen. Keep in mind, I did not create this sketch. (I am not that skilled in programming) Make sure you are changing the MAC address, ip address and universe. One of the only things I had to do to get mine to work properly was switch the HIGH and LOW for the relay.

    Here is my modified sketch for the example picture I am including.

    relays.JPG

    Code:
    /*
    Original code created January 4th, 2014 by Claude Heintz http://lx.claudeheintzdesign.com/lxarduino_sketches.html
    
    modified by: Jared Alexander
     
    This code is in the public domain.
    sACN E 1.31 is a public standard published by the PLASA technical standards program
    http://tsp.plasa.org/tsp/documents/published_docs.php
     
    Requires Arduino Ethernet Shield. Modifed to use the lastest version of Ethernet library included in Arduino 1.6.1. No need to install other libraries. 
    Receives E1.31 data (SACN) and ArtNet data for control of relays. This sketch is designed for use with SainSmart Relay boards.  
    You can only send the Arduino one protocol (E1.31 or ArtNet) at a time. 
    This sketch also includes a power on self test function to make sure everything is hooked up properly.
    */
    
    #include <SPI.h>    //Standard Library     
    #include <Ethernet.h> //Standard Library
    #include <EthernetUdp.h> //Standard Library
    
    
    /*  set the desired subnet and universe (first universe is 0)
        sACN starts with universe 1 so subtract 1 from sACN universe
        to get DMX_UNIVERSE.                                           */
    #define ARTNET_SUBNET 0 //defualt subnet is 0. Should not need to be changed. 
    #define ARTNET_UNIVERSE 0 //first universe being used
    #define E131_SUBNET 0 //defualt subnet is 0. Should not need to be changed. 
    #define ETHERNET_BUFFER_MAX 640
    #define ARTNET_ARTDMX 0x5000
    #define ARTNET_ARTPOLL 0x2000
    #define ARTNET_PORT 0x1936 //standard port
    #define ARTNET_START_ADDRESS 18 //Byte 18 in the packet contains channel 1 values.  
    #define E131_PORT 5568 //standard port 
    #define E131_START_ADDRESS 126 //Byte 126 in the packet contains channel 1 values. Offset is set to one prior. 
    #define STATUS_LED 13 //shows us when we are receiving data
    #define SDCARD_CONTROL 4 //set pin 4 to high to disable SD card interface on WiFi shield 
    #define NUM_RELAYS 16 //total number of relays used 
    
    int channel; //channel increment 
    
    //Relay Pins array
    int Relay[] = {22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37};
    
    //Timer Setup
    volatile byte currentcounter = 0; //counter for data reception
    byte previouscounter = 0; //counter for data reception 
    unsigned long currentDelay = 0; //current time value for ArtNet and E1.31 reception
    
    //Ethernet Configuration
    byte mac[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0xEB};
    IPAddress ip(192, 168, 175, 212);  //IP address of ethernet shield
    
    // buffer to hold E1.31 and Artnet data
    unsigned char packetBuffer[ETHERNET_BUFFER_MAX];
    
    // An EthernetUDP instance to let us send and receive packets over UDP
    // aUDP creates a socket for an Art-Net port
    // suUDP creates a socket for sACN that is unicast to the ip address
    EthernetUDP aUDP;
    EthernetUDP suUDP;
    
    void setup() 
    {
      pinMode(STATUS_LED, OUTPUT); //Initialize status LED
      pinMode(SDCARD_CONTROL, OUTPUT); //Initialize Pin 4
      digitalWrite(SDCARD_CONTROL, HIGH); //Set pin 4 to high since we are not using the SD Card interface
      for(int a = 0; a < NUM_RELAYS; a++) //loop to initialize relay control pins 
      {
       pinMode(Relay[a], OUTPUT); //initialize relay output pins
       digitalWrite(Relay[a], LOW); //set pins to high for off
      }
      Ethernet.begin(mac,ip);  //Initialize Ethernet shield 
      aUDP.begin(ARTNET_PORT); //Open Artnet Port
      suUDP.begin(E131_PORT); //Open E1.31 Port
      Serial.begin(9600); //Serial for debugging 
      POST(); //Run Power On Self Test Function
      Serial.println("Setup Complete"); //print complete 
    }
    
    /* artDMXReceived checks the universe and subnet then
       outputs the data to the relays */
    
    void artDMXReceived(unsigned char* pbuff) 
    {
      if ( (pbuff[14] & 0xF) == ARTNET_UNIVERSE ) 
      {
        if ( (pbuff[14] >> 8) == ARTNET_SUBNET ) 
        {
          channel = 0; //reset channel offset to 0 each time through loop
          //loop turns relay on/off based on channel value starting at Artnet start address
          for(int b = 0; b < NUM_RELAYS; b++) 
          {
           if(pbuff[ARTNET_START_ADDRESS + channel] > 127) //if channel value is greater then 127
          {
           digitalWrite(Relay[b], HIGH); //turn relay on 
          } 
          else
          {
           digitalWrite(Relay[b], LOW); //else turn it off 
          }
          channel++; //increase channel offset by 1 each time through for loop
          }
        }
      }
    } //end artDMXReceived 
    
    /*  artNetOpCode checks to see that the packet is actually Art-Net
        and returns the opcode telling what kind of Art-Net message it is.  */
    
    int artNetOpCode(unsigned char* pbuff) 
    {
      String test = String((char*)pbuff);
      if ( test.equals("Art-Net") ) 
      {
        if ( pbuff[11] >= 14 ) 
        {            //protocol version [10] hi byte [11] lo byte
          return pbuff[9] *256 + pbuff[8];  //opcode lo byte first
        }
      }
      
      return 0;
    }
    
    /* sacnDMXReceived checks the universe and subnet then
       outputs the data to relays  */
    
    void sacnDMXReceived(unsigned char* pbuff, int count) 
    {
        if ( pbuff[113] == E131_SUBNET ) 
      {  
          int addressOffset = 125; //first 125 bytes of packet are header information
          if ( pbuff[addressOffset] == 0 ) //start code must be 0
          {  
           channel = 0; //reset channel offset to 0 each time through loop
           //loop turns relay on/off based on channel value starting at E1.31 start address
          for(int c = 0; c < NUM_RELAYS; c++)
          {
           if(pbuff[E131_START_ADDRESS + channel] > 127) //if channel value is greater then 127
          {
           digitalWrite(Relay[c], HIGH); //turn relay on
          } 
          else
          {
           digitalWrite(Relay[c], LOW); //turn relay off 
          }
          channel++; //increment channel offset by 1
          }
          }
          } 
        } //end sacnDMXReceived 
        
      
      
    //checks to see if packet is E1.31 data
    int checkACNHeaders(unsigned char* messagein, int messagelength) 
    {
      if ( messagein[1] == 0x10 && messagein[4] == 0x41 && messagein[12] == 0x37) 
      {	
          int addresscount = messagein[123] * 256 + messagein[124]; // number of values plus start code
          return addresscount -1; //Return how many values are in the packet.
        }
      return 0;
    }
    
    /************************************************************************
    
      The main loop checks for and reads packets from the two UDP ethernet
      socket connections.  When a packet is recieved, it is checked to see if
      it is valid and then one of the DMXReceived functions is called, sending
      the DMX values to the output. There also is a timer to run a standby 
      program if no data is received for 30 seconds. 
    
    *************************************************************************/
    
    void loop() 
    {
      if(currentcounter != previouscounter) //has the value changed?
      {
        currentDelay = millis(); //store the time since the value has increased 
        previouscounter = currentcounter; //set the previous value equal to the current value
      }
      
      if(millis() - currentDelay > 3) //is the time since the value changed greater than 30 seconds?
      { 
       digitalWrite(STATUS_LED, LOW); //turn LED off. Not receiving E1.31 or ArtNet. 
      }
      
      // first check to see if a packet is available on the Art-Net port
      int packetSize = aUDP.parsePacket();
      if( packetSize )
      {
        aUDP.read(packetBuffer, ETHERNET_BUFFER_MAX);
        /* after reading the packet into the buffer, check to make sure
           that it is an Art-Net packet and retrieve the opcode that
           tells what kind of message it is                         */
        int opcode = artNetOpCode(packetBuffer);
        if ( opcode == ARTNET_ARTDMX ) 
        {
          Serial.println("ArtNet Packet Received");
          artDMXReceived(packetBuffer);
          currentcounter++;  //increase counter by 1 each time through 
          digitalWrite(STATUS_LED, LOW); //turn status LED on
        } 
      } 
        else 
        {
          /* then, if still no packet, check to see if a packet
             is available on the sACN unicastcast port         */
           packetSize = suUDP.parsePacket();
        if( packetSize ) 
        {
          suUDP.read(packetBuffer, ETHERNET_BUFFER_MAX);
          /* after reading the packet into the buffer, check to make sure
           that it is a valid sACN packet.*/
          int count = checkACNHeaders(packetBuffer, packetSize);
          if ( count ) 
          {
            Serial.println("E131 Packet Received");
            sacnDMXReceived(packetBuffer, count);
            currentcounter++;  //increase counter by 1 each time through 
          digitalWrite(STATUS_LED, LOW); //turn status LED on
          }
        }
          
        }
      
    } //End loop
    
    //Power on self test function to make sure everything is connected properly. 
    void POST()
    {
      digitalWrite(Relay[0], LOW);
      delay(1000);
      digitalWrite(Relay[0], HIGH);
      digitalWrite(Relay[1], LOW);
      delay(1000);
      digitalWrite(Relay[1], HIGH);
      digitalWrite(Relay[2], LOW);
      delay(1000);
      digitalWrite(Relay[2], HIGH);
      digitalWrite(Relay[3], LOW);
      delay(1000);
      digitalWrite(Relay[3], HIGH);
      digitalWrite(Relay[4], LOW);
      delay(1000);
      digitalWrite(Relay[4], HIGH);
      digitalWrite(Relay[5], LOW);
      delay(1000);
      digitalWrite(Relay[5], HIGH);
      digitalWrite(Relay[6], LOW);
      delay(1000);
      digitalWrite(Relay[6], HIGH);
      digitalWrite(Relay[7], LOW);
      delay(1000);
      digitalWrite(Relay[7], HIGH);
      digitalWrite(Relay[8], LOW);
      delay(1000);
      digitalWrite(Relay[8], HIGH);
      digitalWrite(Relay[9], LOW);
      delay(1000);
      digitalWrite(Relay[9], HIGH);
      digitalWrite(Relay[10], LOW);
      delay(1000);
      digitalWrite(Relay[10], HIGH);
      digitalWrite(Relay[11], LOW);
      delay(1000);
      digitalWrite(Relay[11], HIGH);
      digitalWrite(Relay[12], LOW);
      delay(1000);
      digitalWrite(Relay[12], HIGH);
      digitalWrite(Relay[13], LOW);
      delay(1000);
      digitalWrite(Relay[13], HIGH);
      digitalWrite(Relay[14], LOW);
      delay(1000);
      digitalWrite(Relay[14], HIGH);
      digitalWrite(Relay[15], LOW);
      delay(1000);
      digitalWrite(Relay[15], HIGH);
      Serial.println("POST Complete");
    }

  13. Thanks AJVenti thanked for this post
Page 1 of 3 123 LastLast

Tags for this Thread

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
  •