Page 27 of 27 FirstFirst ... 17252627
Results 261 to 263 of 263

Thread: Simple code for Arduino Uno/Mega. Up to 48 realy/SSR channels, with Random mode

  1. #261
    Join Date
    Dec 2014
    Location
    Southern California
    Posts
    897
    Post Thanks / Like

    Default Re: Simple code for Arduino Uno/Mega. Up to 48 realy/SSR channels, with Random mode

    Quote Originally Posted by yukonjoe74 View Post
    the above code is working great. i changes it to only 8 channels 34-41 for my singing face. i took out the random sequence but now when my vixen is off it just constantly repeats the test sequence over and over. how can i change the code to make it run the test sequence only once and then wait for a serial connection ? so the face will be off until needed?? any help would be greatly appreciated.
    Code:
    // This code was written by Victor Perez for doityourselfchristmas.com based on the code from Zparticle, Si_champion and Neil Tapp.
     // To adapt the code to your case, just change this top section, with the #define lines.
     
     // Includes the watchdog timer library
     #include <avr/wdt.h>
     
    
     // This sets how many channels will vixen be sending. Can be set to any number from 1 to 48 for Arduino Mega, and 1 to 18 for Arduino Uno.
    
     #define CHANNEL_COUNT 8
    
     // speed for the com port for talking with vixen. From 9600 to 115200. Use the same speed as set in Vixen.
     
    #define VIXEN_COM_SPEED 57600 // tried all baud rates, 9600 lagged, no difference observed between 57600 and 115200
     
     // Timeout waiting for serial input before going to random mode (in milliseconds).
     #define TIME_OUT 1000
     
     // If the relays turn On and Off opposite to Vixen sequence, change "#define MODE NOT_INVERTED" for "#define MODE INVERTED"
     #define NOT_INVERTED 0
     #define INVERTED 1
     #define MODE INVERTED
    
     // which pins control which channels
     
    // Mechanical relay channels
     #define CH01 34
     #define CH02 35
     #define CH03 36
     #define CH04 37
     #define CH05 38
     #define CH06 39
     #define CH07 40
     #define CH08 41
     
     
    
     
     int channels[] = {CH01,CH02,CH03,CH04,CH05 ,CH06,CH07,CH08};
    
     int incomingByte[CHANNEL_COUNT];
    
    int i = 0;     // Loop counter
    volatile unsigned long  timer_a = 0; // new line
    
    //setup the pins/ inputs & outputs
    void setup(){
    
      // enable the watchdog timer with a time of 1 second. If the board freezes, it will reset itself after 1 second.
      wdt_enable(WDTO_1S);
      
      // specifically for the UNO
      sei();  
    
    // initalize PWM Channels / Pins
     for (i=0; i < CHANNEL_COUNT; i++){
        pinMode(channels[i], OUTPUT);
      }
    
    // set all the realys to off to start with
    
    //kev edit
    if (MODE == NOT_INVERTED) {
      for (i=0; i < 24; i++){
        digitalWrite(channels[i], LOW);
      }
    }
    else  {
      for (i=0; i< 24; i++){
        digitalWrite(channels[i], HIGH);
      }
    }
    if (MODE == NOT_INVERTED) {
      for (i=24; i < CHANNEL_COUNT; i++){
        digitalWrite(channels[i], HIGH);
      }
    }
    else  {
      for (i=24; i < CHANNEL_COUNT; i++){
        digitalWrite(channels[i],LOW);
     }
      
    }
    
    
    
    
     testSequence();
     
    // set up Serial according to the speed defined above.
      Serial.begin(VIXEN_COM_SPEED);
    }
    
    void loop()
    {
       if (Serial.available() >= (CHANNEL_COUNT+2)) {
         wdt_reset(); // resets the 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_COUNT; i++) {
                 // read each byte
              incomingByte[i] = Serial.read();
             }  
              
    if (incomingByte[0] <= 127) {
            digitalWrite(channels[0], HIGH);
          }
          else {
            digitalWrite(channels[0], LOW);
          }
     
      if (incomingByte[1] <= 127) {
            digitalWrite(channels[1], HIGH);
          }
          else {
            digitalWrite(channels[1], LOW);
          }
          
      if (incomingByte[2] <= 127) {
            digitalWrite(channels[2], HIGH);
          }
          else {
            digitalWrite(channels[2], LOW);
          }
          
      if (incomingByte[3] <= 127) {
            digitalWrite(channels[3], HIGH);
          }
          else {
            digitalWrite(channels[3], LOW);
          }
          
      if (incomingByte[4] <= 127) {
            digitalWrite(channels[4], HIGH);
          }
          else {
            digitalWrite(channels[4], LOW);
          }
          
      if (incomingByte[5] <= 127) {
            digitalWrite(channels[5], HIGH);
          }
          else {
            digitalWrite(channels[5], LOW);
          }
          
      if (incomingByte[6] <= 127) {
            digitalWrite(channels[6], HIGH);
          }
          else {
            digitalWrite(channels[6], LOW);
          }
    
     if (incomingByte[7] <= 127) {
            digitalWrite(channels[7], HIGH);
          }
          else {
            digitalWrite(channels[7], LOW);
          }
    
     if (incomingByte[8] <= 127) {
            digitalWrite(channels[8], HIGH);
          }
          else {
            digitalWrite(channels[8], LOW);
          }
           }     
         }
       }
    }
    
    
    
    
    // Random mode code. Random mode starts if no serial input has been received in TIME_OUT millisenconds
    //   else {
    //     wdt_reset(); // resets the watchdog
    //     unsigned long diff = millis() - timer_a;
    //     if (diff >= TIME_OUT) {
    //      timer_a = millis ();
    //       int random_a = 0;
    //       
    //      for (i=0; i < CHANNEL_COUNT; i++){
    //           random_a = random(0, 2);
    //           if (random_a == 0) {
    //             digitalWrite(channels[i], LOW);
    //           }
    //           else {
    //             digitalWrite(channels[i], HIGH);
    //           }
    //         }
    //         
    //   }
    //}
    //   }
    
    
    //TEST SEQUENCE ACTUALLY WORKS THE SAME FOR ALL CHANNELS - TEST OUTPUT FOR 1-24 CHANNELS APPEARS NOT_INVERTED WHILE FOR 25-32 APPEARS INVERTED -- THUS ALL LOOK THE SAME
    void testSequence(){
    
    if (MODE == NOT_INVERTED) {
     for (i=0; i < 24; i++){
       wdt_reset(); // resets the watchdog
       digitalWrite(channels[i], HIGH);
       delay (500);
       digitalWrite(channels[i], LOW);
     }
    }
    
    else {
     for (i=0; i < 24; i++){
       wdt_reset(); // resets the watchdog
       digitalWrite(channels[i], LOW);
       delay (500);
       digitalWrite(channels[i], HIGH);
       }
     }
    if (MODE == NOT_INVERTED) {
      for (i=24; i < CHANNEL_COUNT; i++){
        wdt_reset(); 
        digitalWrite(channels[i], LOW);
        delay(500);
        digitalWrite(channels[i], HIGH);
      }
      }
    else {
      for (i=24; i < CHANNEL_COUNT; i++){
        wdt_reset();
        digitalWrite(channels[i], HIGH);
        delay (500);
        digitalWrite(channels[i], LOW);
      }
      
    }
     
    }
    First of all, IMO, you should not be using the code listed above that has already been modified by LateralLiz. She had a specific need for the modified code that you do not. I suggest going to post #1 and use the code there. Then if you do not want Random lights when Vixen is not running, then try commenting out the two digitalWrite statements in the Random section (don't comment out the whole section).
    Kevin

    2017 - Pi3 w/FPP controlling 8 ESPixelsticks driving 1250pixels and 3 Arduino MEGAS communicating with ESP-01s driving 96 channels
    2016 - 184 channels of Blinking/Flashing using 4 Arduino MEGAs and cheap home-made props.

  2. #262
    Join Date
    Nov 2014
    Posts
    11
    Post Thanks / Like

    Default Re: Simple code for Arduino Uno/Mega. Up to 48 realy/SSR channels, with Random mode

    Quote Originally Posted by kev View Post
    First of all, IMO, you should not be using the code listed above that has already been modified by LateralLiz. She had a specific need for the modified code that you do not. I suggest going to post #1 and use the code there. Then if you do not want Random lights when Vixen is not running, then try commenting out the two digitalWrite statements in the Random section (don't comment out the whole section).
    I Tried the first page code but did not work lights were on all the time. so the code by LeteralLiz works great except if there is no signal from computer it loops the self test over and over again. I also tried what you suggested about commenting out just the digitalwrite lines out of the random code but I still get the same looping test result.

    Does anyone know how i can modify this code to prevent the constant repeat of the test procedure all day? i only want test to run once and then wait for computer signal or show to start?

    here is my current code
    Code:
    // This code was written by Victor Perez for doityourselfchristmas.com based on the code from Zparticle, Si_champion and Neil Tapp.
     // To adapt the code to your case, just change this top section, with the #define lines.
     
     // Includes the watchdog timer library
     #include <avr/wdt.h>
     
    
     // This sets how many channels will vixen be sending. Can be set to any number from 1 to 48 for Arduino Mega, and 1 to 18 for Arduino Uno.
    
     #define CHANNEL_COUNT 8
    
     // speed for the com port for talking with vixen. From 9600 to 115200. Use the same speed as set in Vixen.
     
    #define VIXEN_COM_SPEED 57600 // tried all baud rates, 9600 lagged, no difference observed between 57600 and 115200
     
     // Timeout waiting for serial input before going to random mode (in milliseconds).
     #define TIME_OUT 1000
     
     // If the relays turn On and Off opposite to Vixen sequence, change "#define MODE NOT_INVERTED" for "#define MODE INVERTED"
     #define NOT_INVERTED 0
     #define INVERTED 1
     #define MODE INVERTED
    
     // which pins control which channels
     
    // Mechanical relay channels
     #define CH01 34
     #define CH02 35
     #define CH03 36
     #define CH04 37
     #define CH05 38
     #define CH06 39
     #define CH07 40
     #define CH08 41
     
     
    
     
     int channels[] = {CH01,CH02,CH03,CH04,CH05 ,CH06,CH07,CH08};
    
     int incomingByte[CHANNEL_COUNT];
    
    int i = 0;     // Loop counter
    volatile unsigned long  timer_a = 0; // new line
    
    //setup the pins/ inputs & outputs
    void setup(){
    
      // enable the watchdog timer with a time of 1 second. If the board freezes, it will reset itself after 1 second.
      wdt_enable(WDTO_1S);
      
      // specifically for the UNO
      sei();  
    
    // initalize PWM Channels / Pins
     for (i=0; i < CHANNEL_COUNT; i++){
        pinMode(channels[i], OUTPUT);
      }
    
    // set all the realys to off to start with
    
    //kev edit
    if (MODE == NOT_INVERTED) {
      for (i=0; i < 24; i++){
        digitalWrite(channels[i], LOW);
      }
    }
    else  {
      for (i=0; i< 24; i++){
        digitalWrite(channels[i], HIGH);
      }
    }
    if (MODE == NOT_INVERTED) {
      for (i=24; i < CHANNEL_COUNT; i++){
        digitalWrite(channels[i], HIGH);
      }
    }
    else  {
      for (i=24; i < CHANNEL_COUNT; i++){
        digitalWrite(channels[i],LOW);
     }
      
    }
    
    
    
    
     testSequence();
     
    // set up Serial according to the speed defined above.
      Serial.begin(VIXEN_COM_SPEED);
    }
    
    void loop()
    {
       if (Serial.available() >= (CHANNEL_COUNT+2)) {
         wdt_reset(); // resets the 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_COUNT; i++) {
                 // read each byte
              incomingByte[i] = Serial.read();
             }  
              
    if (incomingByte[0] <= 127) {
            digitalWrite(channels[0], HIGH);
          }
          else {
            digitalWrite(channels[0], LOW);
          }
     
      if (incomingByte[1] <= 127) {
            digitalWrite(channels[1], HIGH);
          }
          else {
            digitalWrite(channels[1], LOW);
          }
          
      if (incomingByte[2] <= 127) {
            digitalWrite(channels[2], HIGH);
          }
          else {
            digitalWrite(channels[2], LOW);
          }
          
      if (incomingByte[3] <= 127) {
            digitalWrite(channels[3], HIGH);
          }
          else {
            digitalWrite(channels[3], LOW);
          }
          
      if (incomingByte[4] <= 127) {
            digitalWrite(channels[4], HIGH);
          }
          else {
            digitalWrite(channels[4], LOW);
          }
          
      if (incomingByte[5] <= 127) {
            digitalWrite(channels[5], HIGH);
          }
          else {
            digitalWrite(channels[5], LOW);
          }
          
      if (incomingByte[6] <= 127) {
            digitalWrite(channels[6], HIGH);
          }
          else {
            digitalWrite(channels[6], LOW);
          }
    
     if (incomingByte[7] <= 127) {
            digitalWrite(channels[7], HIGH);
          }
          else {
            digitalWrite(channels[7], LOW);
          }
    
     if (incomingByte[8] <= 127) {
            digitalWrite(channels[8], HIGH);
          }
          else {
            digitalWrite(channels[8], LOW);
          }
           }     
         }
       }
    }
    
    
    
    
    // Random mode code. Random mode starts if no serial input has been received in TIME_OUT millisenconds
       else {
         wdt_reset(); // resets the watchdog
         unsigned long diff = millis() - timer_a;
         if (diff >= TIME_OUT) {
          timer_a = millis ();
           int random_a = 0;
           
          for (i=0; i < CHANNEL_COUNT; i++){
               random_a = random(0, 2);
               if (random_a == 0) {
    //             digitalWrite(channels[i], LOW);
               }
               else {
    //             digitalWrite(channels[i], HIGH);
               }
             }
             
       }
    }
       }
    
    
    //TEST SEQUENCE ACTUALLY WORKS THE SAME FOR ALL CHANNELS - TEST OUTPUT FOR 1-24 CHANNELS APPEARS NOT_INVERTED WHILE FOR 25-32 APPEARS INVERTED -- THUS ALL LOOK THE SAME
    void testSequence(){
    
    if (MODE == NOT_INVERTED) {
     for (i=0; i < 24; i++){
       wdt_reset(); // resets the watchdog
       digitalWrite(channels[i], HIGH);
       delay (500);
       digitalWrite(channels[i], LOW);
     }
    }
    
    else {
     for (i=0; i < 24; i++){
       wdt_reset(); // resets the watchdog
       digitalWrite(channels[i], LOW);
       delay (500);
       digitalWrite(channels[i], HIGH);
       }
     }
    if (MODE == NOT_INVERTED) {
      for (i=24; i < CHANNEL_COUNT; i++){
        wdt_reset(); 
        digitalWrite(channels[i], LOW);
        delay(500);
        digitalWrite(channels[i], HIGH);
      }
      }
    else {
      for (i=24; i < CHANNEL_COUNT; i++){
        wdt_reset();
        digitalWrite(channels[i], HIGH);
        delay (500);
        digitalWrite(channels[i], LOW);
      }
      
    }
     
    }

  3. #263
    Join Date
    Oct 2019
    Location
    SoCal
    Posts
    55
    Post Thanks / Like

    Default Re: Simple code for Arduino Uno/Mega. Up to 48 realy/SSR channels, with Random mode

    Quote Originally Posted by yukonjoe74 View Post
    I Tried the first page code but did not work lights were on all the time. so the code by LeteralLiz works great except if there is no signal from computer it loops the self test over and over again. I also tried what you suggested about commenting out just the digitalwrite lines out of the random code but I still get the same looping test result.

    Does anyone know how i can modify this code to prevent the constant repeat of the test procedure all day? i only want test to run once and then wait for computer signal or show to start?

    here is my current code
    Code:
    // This code was written by Victor Perez for doityourselfchristmas.com based on the code from Zparticle, Si_champion and Neil Tapp.
     // To adapt the code to your case, just change this top section, with the #define lines.
     
     // Includes the watchdog timer library
     #include <avr/wdt.h>
     
    
     // This sets how many channels will vixen be sending. Can be set to any number from 1 to 48 for Arduino Mega, and 1 to 18 for Arduino Uno.
    
     #define CHANNEL_COUNT 8
    
     // speed for the com port for talking with vixen. From 9600 to 115200. Use the same speed as set in Vixen.
     
    #define VIXEN_COM_SPEED 57600 // tried all baud rates, 9600 lagged, no difference observed between 57600 and 115200
     
     // Timeout waiting for serial input before going to random mode (in milliseconds).
     #define TIME_OUT 1000
     
     // If the relays turn On and Off opposite to Vixen sequence, change "#define MODE NOT_INVERTED" for "#define MODE INVERTED"
     #define NOT_INVERTED 0
     #define INVERTED 1
     #define MODE INVERTED
    
     // which pins control which channels
     
    // Mechanical relay channels
     #define CH01 34
     #define CH02 35
     #define CH03 36
     #define CH04 37
     #define CH05 38
     #define CH06 39
     #define CH07 40
     #define CH08 41
     
     
    
     
     int channels[] = {CH01,CH02,CH03,CH04,CH05 ,CH06,CH07,CH08};
    
     int incomingByte[CHANNEL_COUNT];
    
    int i = 0;     // Loop counter
    volatile unsigned long  timer_a = 0; // new line
    
    //setup the pins/ inputs & outputs
    void setup(){
    
      // enable the watchdog timer with a time of 1 second. If the board freezes, it will reset itself after 1 second.
      wdt_enable(WDTO_1S);
      
      // specifically for the UNO
      sei();  
    
    // initalize PWM Channels / Pins
     for (i=0; i < CHANNEL_COUNT; i++){
        pinMode(channels[i], OUTPUT);
      }
    
    // set all the realys to off to start with
    
    //kev edit
    if (MODE == NOT_INVERTED) {
      for (i=0; i < 24; i++){
        digitalWrite(channels[i], LOW);
      }
    }
    else  {
      for (i=0; i< 24; i++){
        digitalWrite(channels[i], HIGH);
      }
    }
    if (MODE == NOT_INVERTED) {
      for (i=24; i < CHANNEL_COUNT; i++){
        digitalWrite(channels[i], HIGH);
      }
    }
    else  {
      for (i=24; i < CHANNEL_COUNT; i++){
        digitalWrite(channels[i],LOW);
     }
      
    }
    
    
    
    
     testSequence();
     
    // set up Serial according to the speed defined above.
      Serial.begin(VIXEN_COM_SPEED);
    }
    
    void loop()
    {
       if (Serial.available() >= (CHANNEL_COUNT+2)) {
         wdt_reset(); // resets the 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_COUNT; i++) {
                 // read each byte
              incomingByte[i] = Serial.read();
             }  
              
    if (incomingByte[0] <= 127) {
            digitalWrite(channels[0], HIGH);
          }
          else {
            digitalWrite(channels[0], LOW);
          }
     
      if (incomingByte[1] <= 127) {
            digitalWrite(channels[1], HIGH);
          }
          else {
            digitalWrite(channels[1], LOW);
          }
          
      if (incomingByte[2] <= 127) {
            digitalWrite(channels[2], HIGH);
          }
          else {
            digitalWrite(channels[2], LOW);
          }
          
      if (incomingByte[3] <= 127) {
            digitalWrite(channels[3], HIGH);
          }
          else {
            digitalWrite(channels[3], LOW);
          }
          
      if (incomingByte[4] <= 127) {
            digitalWrite(channels[4], HIGH);
          }
          else {
            digitalWrite(channels[4], LOW);
          }
          
      if (incomingByte[5] <= 127) {
            digitalWrite(channels[5], HIGH);
          }
          else {
            digitalWrite(channels[5], LOW);
          }
          
      if (incomingByte[6] <= 127) {
            digitalWrite(channels[6], HIGH);
          }
          else {
            digitalWrite(channels[6], LOW);
          }
    
     if (incomingByte[7] <= 127) {
            digitalWrite(channels[7], HIGH);
          }
          else {
            digitalWrite(channels[7], LOW);
          }
    
     if (incomingByte[8] <= 127) {
            digitalWrite(channels[8], HIGH);
          }
          else {
            digitalWrite(channels[8], LOW);
          }
           }     
         }
       }
    }
    
    
    
    
    // Random mode code. Random mode starts if no serial input has been received in TIME_OUT millisenconds
       else {
         wdt_reset(); // resets the watchdog
         unsigned long diff = millis() - timer_a;
         if (diff >= TIME_OUT) {
          timer_a = millis ();
           int random_a = 0;
           
          for (i=0; i < CHANNEL_COUNT; i++){
               random_a = random(0, 2);
               if (random_a == 0) {
    //             digitalWrite(channels[i], LOW);
               }
               else {
    //             digitalWrite(channels[i], HIGH);
               }
             }
             
       }
    }
       }
    
    
    //TEST SEQUENCE ACTUALLY WORKS THE SAME FOR ALL CHANNELS - TEST OUTPUT FOR 1-24 CHANNELS APPEARS NOT_INVERTED WHILE FOR 25-32 APPEARS INVERTED -- THUS ALL LOOK THE SAME
    void testSequence(){
    
    if (MODE == NOT_INVERTED) {
     for (i=0; i < 24; i++){
       wdt_reset(); // resets the watchdog
       digitalWrite(channels[i], HIGH);
       delay (500);
       digitalWrite(channels[i], LOW);
     }
    }
    
    else {
     for (i=0; i < 24; i++){
       wdt_reset(); // resets the watchdog
       digitalWrite(channels[i], LOW);
       delay (500);
       digitalWrite(channels[i], HIGH);
       }
     }
    if (MODE == NOT_INVERTED) {
      for (i=24; i < CHANNEL_COUNT; i++){
        wdt_reset(); 
        digitalWrite(channels[i], LOW);
        delay(500);
        digitalWrite(channels[i], HIGH);
      }
      }
    else {
      for (i=24; i < CHANNEL_COUNT; i++){
        wdt_reset();
        digitalWrite(channels[i], HIGH);
        delay (500);
        digitalWrite(channels[i], LOW);
      }
      
    }
     
    }
    Have you checked if the baud rate in your code matches the baud rate you have set in Vixen/Xlights/FPP/etc.?

Page 27 of 27 FirstFirst ... 17252627

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
  •