Page 1 of 4 123 ... LastLast
Results 1 to 10 of 35

Thread: Sketch to keep lights lit when no in sequence?

  1. #1
    Join Date
    Nov 2017
    Posts
    39
    Post Thanks / Like

    Default Sketch to keep lights lit when no in sequence?

    Would anyone happen to have an example of a sketch where the lights stay lit when a Vixen sequence isn't running? I would like the elements to stay lit when I don't have a show going.

    If it helps, I am using the Mega 2560.

    Thank you!

  2. #2
    Join Date
    Dec 2014
    Posts
    126
    Post Thanks / Like

    Default Re: Sketch to keep lights lit when no in sequence?

    can you just turn on the lights at the end of the sequence?
    or does vixen automatically turn everything off at end of srquence?

  3. #3
    Join Date
    Nov 2017
    Posts
    39
    Post Thanks / Like

    Default Re: Sketch to keep lights lit when no in sequence?

    Quote Originally Posted by MrDudeMan View Post
    can you just turn on the lights at the end of the sequence?
    or does vixen automatically turn everything off at end of srquence?
    I'm new to this so I am still getting accustomed to it. I'm not sure if it's Vixen or the Arduino Sketch that are doing it, but my lights are getting turned off at the end of the sequence. Here is the sketch I'm using:

    Code:
    #define MEGA_VIXEN
    //#define UNO_VIXEN
    
    #ifdef MEGA_VIXEN
      #define MAX_CHANNELS 52
      int channels[MAX_CHANNELS] = {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53};
    #endif
    
    #ifdef UNO_VIXEN
      #define MAX_CHANNELS 18
      int channels[MAX_CHANNELS] = {2,3,4,5,6,7,8,9,10,11,12,13,A0,A1,A2,A3,A4,A5};
    #endif
    
    int incomingByte[MAX_CHANNELS];
    
    void setup()
    {
      int i;
      
      Serial.begin(9600); // set up Serial at 9600 bps
    
      for ( i = 0; i < MAX_CHANNELS; i ++ )  pinMode(channels[i], OUTPUT);
    }
    
    void loop()
    {
      int i;
      
      if (Serial.available() >= MAX_CHANNELS)
      {
        for (i=0; i < MAX_CHANNELS; i ++)      incomingByte[i] = Serial.read();
      }
    
      for (i = 0; i < MAX_CHANNELS; i ++ )    analogWrite(channels[i], incomingByte[i]);
    }

  4. #4
    Join Date
    Dec 2012
    Location
    Hudson MA
    Posts
    2,296
    Post Thanks / Like

    Default Re: Sketch to keep lights lit when no in sequence?

    This is not the type of code you want to run relays. You need digital output, not analog. Next there is no sync logic so you can never align with a data stream. You will count on luck. Next you will only process the received data after more an additional frame arrives, making your output a minimum of one frame behind. I suggest you look at some of the other sketches available that will process something like the Renard protocol.

    Quote Originally Posted by darko886 View Post
    I'm new to this so I am still getting accustomed to it. I'm not sure if it's Vixen or the Arduino Sketch that are doing it, but my lights are getting turned off at the end of the sequence. Here is the sketch I'm using:

    Code:
    #define MEGA_VIXEN
    //#define UNO_VIXEN
    
    #ifdef MEGA_VIXEN
      #define MAX_CHANNELS 52
      int channels[MAX_CHANNELS] = {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53};
    #endif
    
    #ifdef UNO_VIXEN
      #define MAX_CHANNELS 18
      int channels[MAX_CHANNELS] = {2,3,4,5,6,7,8,9,10,11,12,13,A0,A1,A2,A3,A4,A5};
    #endif
    
    int incomingByte[MAX_CHANNELS];
    
    void setup()
    {
      int i;
      
      Serial.begin(9600); // set up Serial at 9600 bps
    
      for ( i = 0; i < MAX_CHANNELS; i ++ )  pinMode(channels[i], OUTPUT);
    }
    
    void loop()
    {
      int i;
      
      if (Serial.available() >= MAX_CHANNELS)
      {
        for (i=0; i < MAX_CHANNELS; i ++)      incomingByte[i] = Serial.read();
      }
    
      for (i = 0; i < MAX_CHANNELS; i ++ )    analogWrite(channels[i], incomingByte[i]);
    }

    2017 adding 2 more candy canes, 7 Mid trees and a Halloween show. Removing most 2812 strips and replacing them with bullet pixel mounting strips. Replacing many buck converter waterproof bags with printed boxes.

  5. #5
    Join Date
    Nov 2009
    Location
    Morrisburg, On, Canada
    Posts
    2,470
    Post Thanks / Like

    Default Re: Sketch to keep lights lit when no in sequence?

    Quote Originally Posted by darko886 View Post
    I'm new to this so I am still getting accustomed to it. I'm not sure if it's Vixen or the Arduino Sketch that are doing it, but my lights are getting turned off at the end of the sequence...
    This is normal for Vixen 3x. Vixen 3x continues to send null data when your sequence has finished. Null data is off effectively for each channel.

    If your channel count isn't too large it is possible to test for all channels being a null over a period of time and then make a decision that it must be at the end of a sequence and thus turn all the lights on.

    Or, you could add a channel in your Vixen sequence that is always on during the sequence, Then when the sequence stops this channel will become a null. Your Arduino code detects this null and turns on all your lights.

    Or, you could add a switch that you manually flip to let the Arduino turn all the lights on. This would not be automatic as the previous two methods. However, you will need to modify the sketch for all these special cases.

    Then as Martin mentioned, this isn't a robust code you want use because of his mentioned defects. Hence you'd want a more robust sketch to tinker with.

  6. #6
    Join Date
    Nov 2017
    Posts
    39
    Post Thanks / Like

    Default Re: Sketch to keep lights lit when no in sequence?

    As people suggested to me, I will try to switch to Victor's sketch, and then I'll play with the randomized lights code. Is this code better?

    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 16
    
     // 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 9600
     
     // 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 NOT_INVERTED
    
     // which pins control which channels
     // You can change these assignment to use different pins, but be very careful to not repeat the same pin number for 2 channels. 
     // DO NOT use pings 0 and 1, as those are for the serial port to talk to the computer.
     #define CH01 2
     #define CH02 3
     #define CH03 4
     #define CH04 5
     #define CH05 6
     #define CH06 7
     #define CH07 8
     #define CH08 9
     #define CH09 10
     #define CH10 11
     #define CH11 12
     #define CH12 13
     #define CH13 14
     #define CH14 15
     #define CH15 16
     #define CH16 17
     
     int channels[] = {CH01,CH02,CH03,CH04,CH05 ,CH06,CH07,CH08,CH09,
     CH10,CH11,CH12,CH13,CH14,CH15,CH16};
    
     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
    if (MODE == NOT_INVERTED) {
     for (i=0; i < CHANNEL_COUNT; i++){
         digitalWrite(channels[i], LOW);
    
     }
    }
    
    else {
     for (i=0; i < CHANNEL_COUNT; i++){
         digitalWrite(channels[i], HIGH);
     }
    }
    
     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 (MODE == NOT_INVERTED) {
    			for (i=0; i < CHANNEL_COUNT; i++){
    			int value = incomingByte[i];
    			if (value <= 127) {
    				digitalWrite(channels[i], LOW);
    			}
    			else {
    				digitalWrite(channels[i], HIGH);
    			}
    			}
    		 }
    		 else {
    		 for (i=0; i < CHANNEL_COUNT; i++){
    			int value = incomingByte[i];
    			if (value < 127) {
    				digitalWrite(channels[i], HIGH);
    			}
    			else {
    				digitalWrite(channels[i], 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);
             }
           }
         }
       }
    }
    
    void testSequence(){
    
    if (MODE == NOT_INVERTED) {
     for (i=0; i < CHANNEL_COUNT; i++){
       wdt_reset(); // resets the watchdog
       digitalWrite(channels[i], HIGH);
       delay (500);
       digitalWrite(channels[i], LOW);
     }
    }
    
    else {
     for (i=0; i < CHANNEL_COUNT; i++){
       wdt_reset(); // resets the watchdog
       digitalWrite(channels[i], LOW);
       delay (500);
       digitalWrite(channels[i], HIGH);
       }
     }
    }

  7. #7
    Join Date
    Nov 2009
    Location
    Morrisburg, On, Canada
    Posts
    2,470
    Post Thanks / Like

    Default Re: Sketch to keep lights lit when no in sequence?

    Yes.

  8. #8
    Join Date
    Dec 2012
    Location
    Hudson MA
    Posts
    2,296
    Post Thanks / Like

    Default Re: Sketch to keep lights lit when no in sequence?

    Yes it is better. As long as the values you send are either 0 (off) or 255 (on) then you will be ok (dimming is not possible with relays so these two values should not be an issue). The code uses a value of 33 to detect a start of frame and will throw away data until it finds it. The loop still waits for more than a frame to arrive before processing anything so you will always be one frame late (most people wont notice since relays are horribly slow anyway).

    2017 adding 2 more candy canes, 7 Mid trees and a Halloween show. Removing most 2812 strips and replacing them with bullet pixel mounting strips. Replacing many buck converter waterproof bags with printed boxes.

  9. #9
    Join Date
    Nov 2009
    Location
    Morrisburg, On, Canada
    Posts
    2,470
    Post Thanks / Like

    Default Re: Sketch to keep lights lit when no in sequence?

    Victor's sketch was developed in the days when Vixen 2x was the rage. Hence it used a watchdog timer to indicate that a sequence is done. If so the watchdog timer didn't get reset with no Vixen data and thus timeout and switch to random mode. This will not work for Vixen 3x as Vixen 3x always sends serial data even when the sequence is done. Therefore the watchdog timer will always get reset.

    You could work on a scheme where you have one Vixen element (i.e. one channel) always full on during a sequence. Then when the sequence is done this element will become a null. In your Arduino sketch you constantly check for a null and go to random mode when it is a null, or you could turn all your lights on, or whatever other feature you want.

  10. #10
    Join Date
    Nov 2017
    Posts
    39
    Post Thanks / Like

    Default Re: Sketch to keep lights lit when no in sequence?

    Quote Originally Posted by LightUp View Post
    Victor's sketch was developed in the days when Vixen 2x was the rage. Hence it used a watchdog timer to indicate that a sequence is done. If so the watchdog timer didn't get reset with no Vixen data and thus timeout and switch to random mode. This will not work for Vixen 3x as Vixen 3x always sends serial data even when the sequence is done. Therefore the watchdog timer will always get reset.

    You could work on a scheme where you have one Vixen element (i.e. one channel) always full on during a sequence. Then when the sequence is done this element will become a null. In your Arduino sketch you constantly check for a null and go to random mode when it is a null, or you could turn all your lights on, or whatever other feature you want.
    So if I'm understanding you correctly, this sketch will still run a sequence correctly, it just would never get to the random mode?

    If that's the case, should I get rid of (or replace) all mentions of the watchdog timer?

    In addition, is there a sample code that is just the basics, just one that will run sequences, and then I can start with that and test things out?

Page 1 of 4 123 ... LastLast

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
  •