Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: Arduino nano with ethernet shield long delay please help

  1. #1
    Join Date
    Dec 2016
    Location
    Miami, FL
    Posts
    31
    Post Thanks / Like

    Default Arduino nano with ethernet shield long delay please help

    hi, back at it again. I am trying to improve communication to my relays out in the yard. Last year I had problems with the long USB extensions. I have purchased arduino nano's and ethernet shields. i flashed them with the following code.

    Code:
    /* A simple sketch to switch relays/SSRs from an E1.31 source.
    * Copyright 2017 Barnabybear <diychristmas.org> Full details at end of code.
    * First issue 25-Oct-2017
    *
    * Ethercard section based on a sketch 'udpListner' by Brian Lee <cybexsoft@hotmail.com> 2013-4-7
    */
    
    #include <EtherCard.h>
    #include <IPAddress.h>
    
    // sets static IP 
    #define STATIC 0  // set to 1 to disable DHCP (adjust myip/gwip values below)
    
    #if STATIC
    // ethernet interface ip address
    static byte myip[] = { 192, 168, 1, 62 };
    // gateway ip address
    static byte gwip[] = { 192, 168, 1, 1 };
    #endif
    
    // ethernet mac address - must be unique on your network.
    static byte mymac[] = { 0x70, 0x69, 0x69, 0x2D, 0x30, 0x31 };
    
    // the universe number to listen for.
    unsigned int universe = 1;
    
    // the number of outputs used (1 to 16).
    const byte num_outs = 14;
    
    // the channel numbers to apply to the outputs (1 to 512).
    int channel[16] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
    
    // the output numbers to use - channel order from above is displayed on these outputs.
    // 10, 11, 12 & 13 are used by the ethernet module.
    byte output_num[16] = {2, 3, 4, 5, 6, 7, 8, 9, 14, 15, 16, 17, 18, 19};
    
    // to use all 16 outputs - change 'num_outs' to 16.
    // comment out the line above and uncomment the line below.
    // NOTE: you will need to remove the nano from your circuit to flash it 
    // as we are now using Tx & Rx to drive relays and comment out the
    // serial output for testing or it will switch your relays/SSRs.
    
    //byte output_num[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 14, 15, 16, 17, 18, 19};
    
    // set outputs as standard or inverted - one pair must be commented out.
    // standard outputs: on = high, off = low.
    //bool out_on = 1;
    //bool out_off = 0;
    // inverted outputs: on = low, high = high.
    bool out_on = 0;
    bool out_off = 1;
    
    // enables the serial output for setup testing -  one set must be commented out.
    //bool setup_output = 0; // serial output disabled
    bool setup_output = 1; // serial output enabled
    
    int n; // a variable for counters
    byte data_1; // a variable for data
    
    byte Ethernet::buffer[681]; // tcp/ip send and receive buffer
    
    
    //callback that prints received packets to the serial port
    void sACN_data(uint16_t dest_port, uint8_t src_ip[IP_LEN], uint16_t src_port, const char *data, uint16_t len) {
    
      // check to see if the packet is an ASC-E1.17 type
      if (!((data[4] ^ 0x41) && (data[5] ^ 0x53) && (data[6] ^ 0x43) && (data[7] ^ 0x2D) &&
            (data[8] ^ 0x45) && (data[9] ^ 0x31) && (data[10] ^ 0x2E) && (data[11] ^ 0x31) &&
            (data[12] ^ 0x37))) {
    
    // check to see if the universe number is correct
        if (!((universe ^ data[114]) + (universe >> 8 ^ data[113]))) {
        if (setup_output) {
        Serial.print("Universe = ");
        Serial.println((data[113] <<8)+(data[114]));
        }
        
    //    Serial.print("Channel count = ");
    //    unsigned int x = (((data[123] << 8) + data[124]) - 1);
    //    Serial.println(x);
    
          for ( n = 0; n < num_outs; n++) {
            data_1 = data[channel[n] + 125];
    
            if (data_1 > 127) {
              digitalWrite(output_num[n], out_on);
              if (setup_output) print_high(); // setup print
    
            }
            else {
              digitalWrite(output_num[n], out_off);
              if (setup_output) print_low(); // debug print - comment out during normal use.
            }
          }
        }
      }
    }
    void setup() {
      if (setup_output) Serial.begin(115200); // debug print - comment out during normal use.
    
      for (n = 0; n < num_outs; n++) {
        pinMode(output_num[n], OUTPUT);
        digitalWrite(output_num[n], out_off);
      }
    
      if (setup_output) Serial.println(F("\n[backSoon]")); // debug print - comment out during normal use.
    
      if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0)
        if (setup_output) Serial.println(F("Failed to access Ethernet controller")); // debug print - comment out during normal use.
    #if STATIC
      ether.staticSetup(myip, gwip);
    #else
      if (!ether.dhcpSetup())
        if (setup_output) Serial.println(F("DHCP failed")); // debug print - comment out during normal use.
    #endif
    
      if (setup_output) {
      ether.printIp("IP:  ", ether.myip);
      ether.printIp("GW:  ", ether.gwip);
      ether.printIp("DNS: ", ether.dnsip);
      }
    
      //register udpSerialPrint() to port 5568 (e1.31 port).
      ether.udpServerListenOnPort(&sACN_data, 5568);
    
      //register udpSerialPrint() to port 42.
      ether.udpServerListenOnPort(&sACN_data, 42);
      //  Serial.end();
      for (n = 0; n < num_outs; n++) {
        pinMode(output_num[n], OUTPUT);
        digitalWrite(output_num[n], LOW);
      }
    }
    
    void loop() {
      //this must be called for ethercard functions to work.
      ether.packetLoop(ether.packetReceive());
      delay(1);
    }
    
    // a function to print data for setup.
    void print_high() {
    
      Serial.print("Output ");
      Serial.print(output_num[n]);
      Serial.print(" : Channel ");
      Serial.print(channel[n]);
      Serial.print(" : Channel offset ");
      Serial.print(channel[n] + 125);
      Serial.print(" : Channel data ");
      Serial.print(data_1);
      Serial.print(" : Output ON ");
      Serial.println("");
    }
    
    // a function to print data for debuging.
    void print_low() {
    
      Serial.print("Output ");
      Serial.print(output_num[n]);
      Serial.print(" : Channel ");
      Serial.print(channel[n]);
      Serial.print(" : Channel offset ");
      Serial.print(channel[n] + 125);
      Serial.print(" : Channel data ");
      Serial.print(data_1);
      Serial.print(" : Output OFF ");
      Serial.println("");
    }
    
    
    /*
    * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
    * and associated documentation files (the "Software"), to deal in the Software without restriction, 
    * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
    * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
    * furnished to do so, subject to the following conditions:
    *
    * The above copyright notice and this permission notice shall be included in all copies or 
    * substantial portions of the Software.
    *
    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
    * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
    * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 
    * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
    * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 
    * IN THE SOFTWARE.
    */
    hope I did that right. Vixen is communicating with the board but has about a 2 to 3 second delay. I have also tested with XLights with the same result.

    https://www.youtube.com/edit?o=U&video_id=WRHiwPZ-tZA

    Any help would be appreciated.

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

    Default Re: Arduino nano with ethernet shield long delay please help

    Hi benny1495. Thanks for running my code and I’m sorry it’s not running out of the box for you.
    I’m guessing the Nano / Ethernet shield are good as it works.
    Testing with both Vixen and xLights has ruled out the source of communications.
    Could you please give us some details of your network.

  3. #3
    Join Date
    Dec 2016
    Location
    Miami, FL
    Posts
    31
    Post Thanks / Like

    Default Re: Arduino nano with ethernet shield long delay please help

    Hi thanks for answering. I am running a netgear wndr3400v2 that I have dedicated to my Christmas network. The Arduino shield is wired directly to the router.

  4. #4
    Join Date
    Dec 2016
    Location
    Miami, FL
    Posts
    31
    Post Thanks / Like

    Default Re: Arduino nano with ethernet shield long delay please help


  5. #5
    Join Date
    Oct 2014
    Location
    Sauk City, WI USA
    Posts
    947
    Post Thanks / Like

    Default Re: Arduino nano with ethernet shield long delay please help

    Does the nano respond to ping? What kind of ping do you get from the show computer to the nano?

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

    Default Re: Arduino nano with ethernet shield long delay please help

    I forgot to say to run it with -t (ping -t xxx.xxx.xxx.xxx) both before starting vixen and then when sending a sequence. Before the sequence you want a very low number and very consistent. During the sequence it should also be consistent. ctrl c to stop it

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

    Default Re: Arduino nano with ethernet shield long delay please help

    Hi, a consistent two to three second delay would be more lag than expected when running on its own network.
    A quick thought; is there defiantly a lag or are the outputs inverted giving the impression of lag? By default the sketch is set to invert the outputs, this matched my relays; it can be changed as below.
    Code:
    // set outputs as standard or inverted - one pair must be commented out.
    // standard outputs: on = high, off = low.
    //bool out_on = 1;
    //bool out_off = 0;
    // inverted outputs: on = low, high = high.
    bool out_on = 0;
    bool out_off = 1;
    Code:
    // set outputs as standard or inverted - one pair must be commented out.
    // standard outputs: on = high, off = low.
    bool out_on = 1;
    bool out_off = 0;
    // inverted outputs: on = low, high = high.
    //bool out_on = 0;
    //bool out_off = 1;

  8. #8
    Join Date
    Dec 2016
    Location
    Miami, FL
    Posts
    31
    Post Thanks / Like

    Default Re: Arduino nano with ethernet shield long delay please help

    Code:
     
    Without Vixen running
    C:\Users\Benny Rodriguez>ping -t 10.0.0.6
    
    Pinging 10.0.0.6 with 32 bytes of data:
    Reply from 10.0.0.6: bytes=32 time=4ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=3ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=4ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=5ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=6ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=5ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=2ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=4ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=2ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=4ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=4ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=4ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=5ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=2ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=3ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=6ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=3ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=5ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=2ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=2ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=4ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=5ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=6ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=2ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=5ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=4ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=4ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=4ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=2ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=2ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=3ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=2ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=2ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=6ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=3ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=3ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=3ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=3ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=4ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=4ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=4ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=5ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=5ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=2ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=2ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=5ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=3ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=2ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=5ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=3ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=2ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=3ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=6ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=5ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=4ms TTL=64
    
    Ping statistics for 10.0.0.6:
        Packets: Sent = 55, Received = 55, Lost = 0 (0% loss),
    Approximate round trip times in milli-seconds:
        Minimum = 2ms, Maximum = 6ms, Average = 3ms
    
    with vixen running
    
    C:\Users\Benny Rodriguez>ping -t 10.0.0.6
    
    Pinging 10.0.0.6 with 32 bytes of data:
    Reply from 10.0.0.6: bytes=32 time=1277ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=1048ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=1049ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=1047ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=1047ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=1383ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=1388ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=1395ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=1388ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=1034ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=1052ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=1051ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=1043ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=1052ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=1050ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=1380ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=1320ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=1049ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=1393ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=1393ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=1052ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=1051ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=1040ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=1051ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=1052ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=1051ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=1050ms TTL=64
    Reply from 10.0.0.6: bytes=32 time=1052ms TTL=64
    
    Ping statistics for 10.0.0.6:
        Packets: Sent = 28, Received = 28, Lost = 0 (0% loss),
    Approximate round trip times in milli-seconds:
        Minimum = 1034ms, Maximum = 1395ms, Average = 1151ms

  9. #9
    Join Date
    Dec 2016
    Location
    Miami, FL
    Posts
    31
    Post Thanks / Like

    Default Re: Arduino nano with ethernet shield long delay please help

    I tried another board with the same results.

  10. #10
    Join Date
    Oct 2014
    Location
    Sauk City, WI USA
    Posts
    947
    Post Thanks / Like

    Default Re: Arduino nano with ethernet shield long delay please help

    The first one is perfect.. the second one says the nano is doing took much work. how many channels are you sending out?

Page 1 of 2 12 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
  •