Results 1 to 5 of 5

Thread: check my sketch please

  1. #1
    Join Date
    Dec 2016
    Posts
    8
    Post Thanks / Like

    Default check my sketch please

    I'm trying to write the most efficient code possible for my 16 channel generic serial however I am getting plugin error messages after the sequence has been running for over 80 seconds. Can someone help please.





    // Global Constants
    #include <avr/wdt.h> // Watchdog timer library
    #define Channel_Counter 16 // How many Channels will vixen be sending.
    #define Com_Speed 57600 // Com port speed
    #define Timeout 2000 // Timeout waiting for serial input before switching off the relays

    // Assign pins to Channels
    #define Ch01 4 //relay 1
    #define Ch02 5 //relay 2
    #define Ch03 6 //relay 3
    #define Ch04 7 //relay 4
    #define Ch05 8 //relay 5
    #define Ch06 9 //relay 6
    #define Ch07 10 //relay 7
    #define Ch08 11 //relay 8
    #define Ch09 12 //relay 9
    #define Ch10 13 //relay 10
    #define Ch11 A0 //relay 11
    #define Ch12 A1 //relay 12
    #define Ch13 A2 //relay 13
    #define Ch14 A3 //relay 14
    #define Ch15 A4 //relay 15
    #define Ch16 A5 //relay 16


    // Global variables
    int Channels[] = {Ch01,Ch02,Ch03,Ch04,Ch05,Ch06,Ch07,Ch08,Ch09,Ch10 ,Ch11,Ch12,Ch13,Ch14,Ch15,Ch16};
    int incomingByte[Channel_Counter];
    int i = 0; // loop counter
    int waitTime = 500; // time to initalise relays during testSequence
    volatile unsigned long timer_a = 0; // new line


    // Setup the pins as outputs
    void setup()
    {
    wdt_enable(WDTO_8S); // watchdog timer resets itself after 1 second
    Serial.begin(Com_Speed); // set up serial speed
    for (i=0; i < Channel_Counter; i++)
    {
    pinMode(Channels[i], OUTPUT); // initalize PWM and Analog In channels as outputs
    digitalWrite(Channels[i], HIGH);
    }
    testSequence();

    }


    void loop()
    {
    if (Serial.available() >= (Channel_Counter+2))
    {
    wdt_reset(); // reset watchdog
    timer_a = millis (); // new line
    int uno = Serial.read();
    if (uno == 126)
    {
    int dos = Serial.read();
    if (dos == 33)
    {
    for (i=0; i < Channel_Counter; i++) // read each byte
    {
    incomingByte[i] = Serial.read();
    }
    for (i=0; i < Channel_Counter; i++)
    {
    int value = incomingByte[i];
    if (value < 255)
    {
    digitalWrite(Channels[i], HIGH);
    }
    else
    {
    digitalWrite(Channels[i], LOW);
    }
    }
    }
    }
    }

    else // switch off relays if no serial input
    {
    wdt_reset(); // reset watchdog
    unsigned long diff = millis() - timer_a;
    if (diff >= Timeout)
    {
    timer_a = millis ();
    for (i=0; i < Channel_Counter; i++)
    {
    digitalWrite(Channels[i], HIGH);
    } // end for statement
    } // end if statement
    } // end else statement
    } // end void loop

    void testSequence()
    {
    for (i=0; i < Channel_Counter; i++)
    {
    wdt_reset(); // reset watchdog
    digitalWrite(Channels[i], HIGH);
    delay (waitTime);
    digitalWrite(Channels[i], LOW);
    }
    }

  2. #2
    Join Date
    Dec 2014
    Location
    Southern California
    Posts
    418
    Post Thanks / Like

    Default Re: check my sketch please

    Are you using Vixen? If so, what version? Sounds like you might have a sequencing software issue, not the sketch.
    Kevin

    2016 - 184 channels of Blinking/Flashing using 4 Arduino MEGAs and cheap home-made props.

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

    Default Re: check my sketch please

    Hi, can you put code tags around the sketch in the first post as without it is not always displayed correct!y. I can,t show you as they don't show up.
    Open square bracket CODE close square bracket at the start and open square bracket / CLOSE close square bracket at the end.
    The forum sometimes sees parts of the sketch as formattinging instructions. It know that anything between code tags should be displayed as is.

  4. #4
    Join Date
    Dec 2016
    Posts
    8
    Post Thanks / Like

    Default Re: check my sketch please

    Dear Barnabybear,


    [code]

    // Global Constants
    #include <avr/wdt.h> // Watchdog timer library
    #define Channel_Counter 16 // How many Channels will vixen be sending.
    #define Com_Speed 57600 // Com port speed
    #define Timeout 2000 // Timeout waiting for serial input before switching off the relays

    // Assign pins to Channels
    #define Ch01 4 //relay 1
    #define Ch02 5 //relay 2
    #define Ch03 6 //relay 3
    #define Ch04 7 //relay 4
    #define Ch05 8 //relay 5
    #define Ch06 9 //relay 6
    #define Ch07 10 //relay 7
    #define Ch08 11 //relay 8
    #define Ch09 12 //relay 9
    #define Ch10 13 //relay 10
    #define Ch11 A0 //relay 11
    #define Ch12 A1 //relay 12
    #define Ch13 A2 //relay 13
    #define Ch14 A3 //relay 14
    #define Ch15 A4 //relay 15
    #define Ch16 A5 //relay 16


    // Global variables
    int Channels[] = {Ch01,Ch02,Ch03,Ch04,Ch05,Ch06,Ch07,Ch08,Ch09,Ch10 ,Ch11,Ch12,Ch13,Ch14,Ch15,Ch16};
    int incomingByte[Channel_Counter];
    int i = 0; // loop counter
    int waitTime = 500; // time to initalise relays during testSequence
    volatile unsigned long timer_a = 0; // new line


    // Setup the pins as outputs
    void setup()
    {
    wdt_enable(WDTO_8S); // watchdog timer resets itself after 1 second
    Serial.begin(Com_Speed); // set up serial speed
    for (i=0; i < Channel_Counter; i++)
    {
    pinMode(Channels[i], OUTPUT); // initalize PWM and Analog In channels as outputs
    digitalWrite(Channels[i], HIGH);
    }
    testSequence();

    }


    void loop()
    {
    if (Serial.available() >= (Channel_Counter+2))
    {
    wdt_reset(); // reset watchdog
    timer_a = millis (); // new line
    int uno = Serial.read();
    if (uno == 126)
    {
    int dos = Serial.read();
    if (dos == 33)
    {
    for (i=0; i < Channel_Counter; i++) // read each byte
    {
    incomingByte[i] = Serial.read();
    }
    for (i=0; i < Channel_Counter; i++)
    {
    int value = incomingByte[i];
    if (value < 255)
    {
    digitalWrite(Channels[i], HIGH);
    }
    else
    {
    digitalWrite(Channels[i], LOW);
    }
    }
    }
    }
    }

    else // switch off relays if no serial input
    {
    wdt_reset(); // reset watchdog
    unsigned long diff = millis() - timer_a;
    if (diff >= Timeout)
    {
    timer_a = millis ();
    for (i=0; i < Channel_Counter; i++)
    {
    digitalWrite(Channels[i], HIGH);
    } // end for statement
    } // end if statement
    } // end else statement
    } // end void loop

    void testSequence()
    {
    for (i=0; i < Channel_Counter; i++)
    {
    wdt_reset(); // reset watchdog
    digitalWrite(Channels[i], HIGH);
    delay (waitTime);
    digitalWrite(Channels[i], LOW);
    }
    }
    [close]

  5. #5
    Join Date
    Dec 2014
    Location
    Southern California
    Posts
    418
    Post Thanks / Like

    Default Re: check my sketch please

    if you are using Vixen and the error you mentioned is from your computer running Vixen, then it probably has nothing to do with the sketch. Don't connect the controller and run the sequence. I bet you get the same error.
    Kevin

    2016 - 184 channels of Blinking/Flashing using 4 Arduino MEGAs and cheap home-made props.

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
  •