Page 3 of 5 FirstFirst 12345 LastLast
Results 21 to 30 of 41

Thread: Multiple Arduinos

  1. #21
    Join Date
    Sep 2017
    Posts
    3
    Post Thanks / Like

    Default Re: Multiple Arduinos

    Quote Originally Posted by jetty View Post
    Hi Spankyty,

    To do this is really simple. Currently when there's no transmission, it switches everything to off to stop one channel being on for example if your computer crashed mid sequence, so we'll just change it to on instead, then when your computer stops transmitting, after the INACTIVITY_TIMEOUT it will switch everything on.

    Find this piece of code:
    Code:
        if ( inactivityTimer > INACTIVITY_TIMEOUT )
        {
          // We don't use a for loop here, for speed reasons
          pwm[0] = 0;
          pwm[1] = 0;
          pwm[2] = 0;
          pwm[3] = 0;
          pwm[4] = 0;
          pwm[5] = 0;
          pwm[6] = 0;
          pwm[7] = 0;
          pwm[8] = 0;
          pwm[9] = 0;
          pwm[10] = 0;
          pwm[11] = 0;
          pwm[12] = 0;
          pwm[13] = 0;
          pwm[14] = 0;
          pwm[15] = 0;
    
          inactivityTimer = 0;
        }
    For each of pwm[0] = 0; to pwm[15] = 0; change them to pwm[0] = 255; to pwm[15] = 255;
    0 is full off
    255 is full on

    That simple.

    If you need to change the time for the timeout (currently set to 1 minute) change the first "1" in this:

    Code:
    #define INACTIVITY_TIMEOUT (1 * 60 * 120 )  //1 Min * 60 Seconds * (60Hz * 2)
    Note: when you start up everything defaults to off and that would still occur, until 1min, then everything would go on,
    so if you need that to default to on at startup too, find this piece of code:

    Code:
      for ( uint8_t i = 0; i < CHANNELS; i ++ )
      {
        pwm[i] = 0;
        
        // Set pin to output
        ddrBCD[ssrPortIndex[i]] |= _BV(ssrBit[i]);    
      }
    and change: pwm[i] = 0; to pwm[i] = 255;

    Is there any way to make the lights stay on when the sequence ends using the shorter code that you provided:
    Code:
    #define MEGA_VIXEN
    //#define UNO_VIXEN
    
    #ifdef MEGA_VIXEN
      #define MAX_CHANNELS 48
      int channels[MAX_CHANNELS] = {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,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]);
    }
    Please help ASAP!
    Last edited by Dumbledore712; 10-06-2017 at 03:58 PM. Reason: Add Code Tags

  2. #22
    Join Date
    Dec 2012
    Posts
    152
    Post Thanks / Like

    Default Re: Multiple Arduinos

    Quote Originally Posted by Dumbledore712 View Post
    Is there any way to make the lights stay on when the sequence ends using the shorter code that you provided:
    Please help ASAP!
    Here you go. It compiles, should work (although I haven't verified).

    A couple of things here though. This is all based on the code from the original poster, there are a few issues in general.

    1. analogWrite only works with PWM, i.e. if you wish to have dimming. The original poster used all the pins on the devices (of which only a few
    are PWM). analogWrite on a non-PWM pin will result in On or Off but no dimming. You can always cut down the number of pins to just the PWM pins
    or just live with it

    2. If you're gonna just live with it, you may as well have On/Off on all pins, in which case use digitalWrite instead of analogWrite. digitalWrite takes
    HIGH or LOW instead of 255..0, so you'll need to make a few changes, but I leave that as an exercise. digitalWrite is considerably faster than
    analogWrite.

    3. Faster than analogWrite / digitalWrite is port manipulation. If you're using Uno, you may as well just set everything to Renard, dump this code below completely and
    go with this code I wrote for FoxCub16: https://github.com/jetty840/FoxCub16Firmware
    It's full featured, will dim on all channels and can run at 115200 with no issues.

    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
    
    #define POWER_UP_STATE    0    //0 = Lights off at power up, 255 = lights on at power up
    #define INACTIVITY_STATE  255  //0 = Lights off when inactive, 255 = lights on when inactive
    
    #define INACTIVITY_TIMEOUT_MILLISECONDS (20UL * 1000UL)   // 20 = 20 seconds, 1000 = 1000 milliseconds in a second
    
    int incomingByte[MAX_CHANNELS];
    
    unsigned long inactivityTimer;
    
    void setup()
    {
      int i;
      
      Serial.begin(9600); // set up Serial at 9600 bps
    
      for ( i = 0; i < MAX_CHANNELS; i ++ )
      {
        pinMode(channels[i], OUTPUT);
        analogWrite(channels[i], POWER_UP_STATE);
      }
      
      inactivityTimer = millis();
    }
    
    void loop()
    {
      int i;
      
      if (Serial.available() >= MAX_CHANNELS)
      {
        for (i=0; i < MAX_CHANNELS; i ++)      incomingByte[i] = Serial.read();
        inactivityTimer = millis();
      }
    
      if ( (millis() - inactivityTimer) >= INACTIVITY_TIMEOUT_MILLISECONDS )
      {
        for ( i = 0; i < MAX_CHANNELS; i ++ )  incomingByte[i] = INACTIVITY_STATE;
      }
     
      for (i = 0; i < MAX_CHANNELS; i ++ )  analogWrite(channels[i], incomingByte[i]);
    }

  3. #23
    Join Date
    Sep 2017
    Posts
    3
    Post Thanks / Like

    Default Re: Multiple Arduinos

    Quote Originally Posted by jetty View Post
    Here you go. It compiles, should work (although I haven't verified).

    A couple of things here though. This is all based on the code from the original poster, there are a few issues in general.

    1. analogWrite only works with PWM, i.e. if you wish to have dimming. The original poster used all the pins on the devices (of which only a few
    are PWM). analogWrite on a non-PWM pin will result in On or Off but no dimming. You can always cut down the number of pins to just the PWM pins
    or just live with it

    2. If you're gonna just live with it, you may as well have On/Off on all pins, in which case use digitalWrite instead of analogWrite. digitalWrite takes
    HIGH or LOW instead of 255..0, so you'll need to make a few changes, but I leave that as an exercise. digitalWrite is considerably faster than
    analogWrite.

    3. Faster than analogWrite / digitalWrite is port manipulation. If you're using Uno, you may as well just set everything to Renard, dump this code below completely and
    go with this code I wrote for FoxCub16: https://github.com/jetty840/FoxCub16Firmware
    It's full featured, will dim on all channels and can run at 115200 with no issues.

    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
    
    #define POWER_UP_STATE    0    //0 = Lights off at power up, 255 = lights on at power up
    #define INACTIVITY_STATE  255  //0 = Lights off when inactive, 255 = lights on when inactive
    
    #define INACTIVITY_TIMEOUT_MILLISECONDS (20UL * 1000UL)   // 20 = 20 seconds, 1000 = 1000 milliseconds in a second
    
    int incomingByte[MAX_CHANNELS];
    
    unsigned long inactivityTimer;
    
    void setup()
    {
      int i;
      
      Serial.begin(9600); // set up Serial at 9600 bps
    
      for ( i = 0; i < MAX_CHANNELS; i ++ )
      {
        pinMode(channels[i], OUTPUT);
        analogWrite(channels[i], POWER_UP_STATE);
      }
      
      inactivityTimer = millis();
    }
    
    void loop()
    {
      int i;
      
      if (Serial.available() >= MAX_CHANNELS)
      {
        for (i=0; i < MAX_CHANNELS; i ++)      incomingByte[i] = Serial.read();
        inactivityTimer = millis();
      }
    
      if ( (millis() - inactivityTimer) >= INACTIVITY_TIMEOUT_MILLISECONDS )
      {
        for ( i = 0; i < MAX_CHANNELS; i ++ )  incomingByte[i] = INACTIVITY_STATE;
      }
     
      for (i = 0; i < MAX_CHANNELS; i ++ )  analogWrite(channels[i], incomingByte[i]);
    }
    I am using no dimming, and controlling everything from an arduino mega 2560, so should I change every instance of analogWrite to digitalWrite? And also, this keeps all of the lights in "On" after the sequence ends, right?

  4. #24
    Join Date
    Dec 2012
    Posts
    152
    Post Thanks / Like

    Default Re: Multiple Arduinos

    Quote Originally Posted by Dumbledore712 View Post
    I am using no dimming, and controlling everything from an arduino mega 2560, so should I change every instance of analogWrite to digitalWrite? And also, this keeps all of the lights in "On" after the sequence ends, right?
    Correct

    INACTIVITY_STATE sets the light to on after the sequence ends. (you can change it to off too)

    Anything that is digitalWriting should be writing LOW or HIGH instead of 0 or 255.

    Here is the code converted to digitalWrite:

    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
    
    #define POWER_UP_STATE    LOW    //0 = Lights off at power up, 255 = lights on at power up
    #define INACTIVITY_STATE  HIGH  //0 = Lights off when inactive, 255 = lights on when inactive
    
    #define INACTIVITY_TIMEOUT_MILLISECONDS (20UL * 1000UL)   // 20 = 20 seconds, 1000 = 1000 milliseconds in a second
    
    int incomingByte[MAX_CHANNELS];
    
    unsigned long inactivityTimer;
    
    void setup()
    {
      int i;
      
      Serial.begin(9600); // set up Serial at 9600 bps
    
      for ( i = 0; i < MAX_CHANNELS; i ++ )
      {
        pinMode(channels[i], OUTPUT);
        digitalWrite(channels[i], POWER_UP_STATE);
      }
      
      inactivityTimer = millis();
    }
    
    void loop()
    {
      int i;
      
      if (Serial.available() >= MAX_CHANNELS)
      {
        for (i=0; i < MAX_CHANNELS; i ++)      incomingByte[i] = Serial.read();
        inactivityTimer = millis();
      }
    
      if ( (millis() - inactivityTimer) >= INACTIVITY_TIMEOUT_MILLISECONDS )
      {
        for ( i = 0; i < MAX_CHANNELS; i ++ )  incomingByte[i] = INACTIVITY_STATE;
      }
     
      for (i = 0; i < MAX_CHANNELS; i ++ )  digitalWrite(channels[i], incomingByte[i]);
    }

  5. #25
    Join Date
    Oct 2017
    Location
    oregon
    Posts
    3
    Post Thanks / Like

    Default Re: Multiple Arduinos

    hey guys im a total new guy i saw this on a chance and have gone nuts
    i have a arduino mega 2560 16 Chanel click type relay board AND VIXEN 3. WHATEVER THE NEW VS IS
    ive copied the sketch from above with the 20 second time out
    but my lights stay on and turn off when the vixen tells it to turn on
    can anyone help me add the necessary code to start with lights off
    i have the relays wired in the NO setting and dont want to have to rewire this since the relays get a little warm in the oalways on setting from the arduino
    thanks in advance scv

  6. #26
    Join Date
    Dec 2012
    Posts
    152
    Post Thanks / Like

    Default Re: Multiple Arduinos

    Quote Originally Posted by kasatka6991 View Post
    hey guys im a total new guy i saw this on a chance and have gone nuts
    i have a arduino mega 2560 16 Chanel click type relay board AND VIXEN 3. WHATEVER THE NEW VS IS
    ive copied the sketch from above with the 20 second time out
    but my lights stay on and turn off when the vixen tells it to turn on
    can anyone help me add the necessary code to start with lights off
    i have the relays wired in the NO setting and dont want to have to rewire this since the relays get a little warm in the oalways on setting from the arduino
    thanks in advance scv
    If it's switching opposite, then you can switch HIGH to LOW and LOW to HIGH, however...

    It's a very bad idea to drive lights with regular relays. Switching relays at Vixen speeds to music, heats up the relays significantly, to the point where
    it melts the relay and catches on fire. There have been a few instances on this forum that you can dig up where fires started in installations, one
    of the cases nearly burnt down a community center.

    Also, relays getting warm indicates you maybe overloading the relay to start. Also if driving relays from an Arduino, watch out for the coil current versus Arduino 20ma drive current, and
    it's an inductive load so you need a diode.

    But I can't stress this enough, using relays for fast switching is extremely dangerous. Change to Zero Crossing Solid State Relays or making one of the SSR boards.

    The only time where regular relays make sense is where there is no fast animation (i.e. switching on your FM Frequency display board, which remains on for the display).

  7. #27
    Join Date
    Oct 2017
    Location
    oregon
    Posts
    3
    Post Thanks / Like

    Default Re: Multiple Arduinos

    I SWITCHED TO DIGITAL WRITE GOT RID OF ANALOG
    AND ADDED LOW AND HIGH INSTEAD OF 0 AND 255
    its working now
    i dont plan on keeping click relays
    but it is my 1st year
    im hoping for some light controll that is not to crazy just better than on only
    in new vixen i find it harder to write the sequences since i have only single strings &
    8 channels with the vs3.0 vs2.1.1 is simpler but in the area where i can choose on or off the boxes are slighly darker in color that the rest and i can chose them

  8. #28
    Join Date
    Oct 2017
    Location
    oregon
    Posts
    3
    Post Thanks / Like

    Default Re: Multiple Arduinos

    #define MEGA_VIXEN
    //vixen issue.png

    #ifdef MEGA_VIXEN
    #define MAX_CHANNELS 8
    int channels[MAX_CHANNELS] = {2,3,4,5,6,7,8,9};
    #endif


    #define POWER_UP_STATE LOW //0 = Lights on at power up, 255 = lights off at power up
    #define INACTIVITY_STATE HIGH //0 = Lights on when inactive, 255 = lights off when inactive

    #define INACTIVITY_TIMEOUT_MILLISECONDS (20UL * 1000UL) // 20 = 20 seconds, 1000 = 1000 milliseconds in a second

    int incomingByte[MAX_CHANNELS];

    unsigned long inactivityTimer;

    void setup()
    {
    int i;

    Serial.begin(57600); // set up Serial at 57600 bps

    for ( i = 0; i < MAX_CHANNELS; i ++ )
    {
    pinMode(channels[i], OUTPUT);
    digitalWrite(channels[i], POWER_UP_STATE);
    }

    inactivityTimer = millis();
    }

    void loop()
    {
    int i;

    if (Serial.available() >= MAX_CHANNELS)
    {
    for (i=0; i < MAX_CHANNELS; i ++) incomingByte[i] = Serial.read();
    inactivityTimer = millis();
    }

    if ( (millis() - inactivityTimer) >= INACTIVITY_TIMEOUT_MILLISECONDS )
    {
    for ( i = 0; i < MAX_CHANNELS; i ++ ) incomingByte[i] = INACTIVITY_STATE;
    }

    for (i = 0; i < MAX_CHANNELS; i ++ ) digitalWrite(channels[i], incomingByte[i]);}



    thats the code i have butchered from the source
    and a pic of my sequence
    the grey is the off in vixen but on in arduino
    and the white is the opposite

  9. #29
    Join Date
    Oct 2017
    Posts
    2
    Post Thanks / Like

    Question Re: Multiple Arduinos

    Hello everyone. Thank you all for the time you put into this. I am learning a lot about different functions and appreciate the community.
    Halloween_2017-640x480.jpg
    I'm having the same experience as kasatka6991. --Relays are on when they should be off and off when they should be on-- I am using an UNO with an 8 relay module I paid $10 for through Amazon. I reversed the POWER_STATE and INACTIVITY_STATE (HIGH and LOW) as suggested by Jetty but there is no impact to the behavior (that seemed odd...). Inactivity is working, meaning that after 5 seconds the relays turn off but as soon as I turn on Vixen, they all turn on again.
    The relays will be pushing 5W LED spotlights following along a recorded dialog between seven characters. This is for a Halloween set up of dragons and skulls (image attached). No fast switching with music, although I do plan to use this at Christmas time so I will heed the advice of getting Zero Crossing Solid State Relays (THANK YOU!).

    Here is the code. Any help is appreciated.

    //#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 8
    int channels[MAX_CHANNELS] = {2,3,4,5,6,7,8,9};
    #endif

    #define POWER_UP_STATE HIGH //0 = Lights off at power up, 255 = lights on at power up
    #define INACTIVITY_STATE LOW //0 = Lights off when inactive, 255 = lights on when inactive

    #define INACTIVITY_TIMEOUT_MILLISECONDS (5UL * 1000UL) // 5 = 5 seconds, 1000 = 1000 milliseconds in a second

    int incomingByte[MAX_CHANNELS];

    unsigned long inactivityTimer;

    void setup()
    {
    int i;

    Serial.begin(9600); // set up Serial at 9600 bps

    for ( i = 0; i < MAX_CHANNELS; i ++ )
    {
    pinMode(channels[i], OUTPUT);
    digitalWrite(channels[i], POWER_UP_STATE);
    }

    inactivityTimer = millis();
    }

    void loop()
    {
    int i;

    if (Serial.available() >= MAX_CHANNELS)
    {
    for (i=0; i < MAX_CHANNELS; i ++) incomingByte[i] = Serial.read();
    inactivityTimer = millis();
    }

    if ( (millis() - inactivityTimer) >= INACTIVITY_TIMEOUT_MILLISECONDS )
    {
    for ( i = 0; i < MAX_CHANNELS; i ++ ) incomingByte[i] = INACTIVITY_STATE;
    }

    for (i = 0; i < MAX_CHANNELS; i ++ ) digitalWrite(channels[i], incomingByte[i]);
    }

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

    Default Re: Multiple Arduinos

    you need to determine how your relay works and then write your sketch to match.

    write a sketch that prints the relay and what state you are setting. Observe your output and then flip the write in your vixen sketch.

Page 3 of 5 FirstFirst 12345 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
  •