Page 2 of 5 FirstFirst 1234 ... LastLast
Results 11 to 20 of 41

Thread: Multiple Arduinos

  1. #11
    Join Date
    Dec 2012
    Posts
    152
    Post Thanks / Like

    Default Re: Multiple Arduinos

    Oh and, here's a more concise and defensive version of your code. This same code will run on either your Uno or Mega, just uncomment and comment the appropriate #define at the top.
    Any changes to the number of channels or arduino type then only happens in one place. I haven't tested compilation, but if it doesn't compile immediately, any typos should be obvious.

    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]);
    }
    Last edited by jetty; 12-18-2014 at 09:24 PM. Reason: Adding code tag

  2. Likes SuperMariojr liked this post
  3. #12
    Join Date
    Dec 2012
    Posts
    152
    Post Thanks / Like

    Default Re: Multiple Arduinos

    Oh and for some reason it lost the formatting, does this forum have a "code" button somewhere?

    Update: Haven't found the code button, but a tag with "CODE" in works.
    Last edited by jetty; 12-18-2014 at 09:27 PM. Reason: Found code tag

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

    Default Re: Multiple Arduinos

    And just a general comment, these sequences being sent from Vixen should really be framed with a starting byte as Renard is.

    The reason is, if you get any serial corruption at all since the Arduino was powered on, or you don't process the data fast enough and the serial buffer
    overflows (it's only 64 bytes), then incomingBytes will lose positional sync with the data, all your channels will be wrong, and you'll be one frame late too.

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

    Default Re: Multiple Arduinos

    Quote Originally Posted by jetty View Post
    Oh and for some reason it lost the formatting, does this forum have a "code" button somewhere?

    Update: Haven't found the code button, but a tag with "CODE" in works.
    The "code button" is in the "Go Advanced" selection. Yes, you just type the code tags in "Post Quick Reply" and insert your code between the two tags - as you discovered.

  6. #15
    Join Date
    Oct 2013
    Location
    Hornsea, United Kingdom
    Posts
    74
    Post Thanks / Like

    Default Re: Multiple Arduinos

    Hi jetty, Thanks for the code but unfortuntly cant get it to work, But here's the weird thing, ive uploaded my original sketches to all arduino's numerous times while connecting and unconnecting usb ports and hay presto!! all working fine again. Bloody weird Eh!!

    Thanks guys..

  7. #16
    Join Date
    Nov 2011
    Location
    Chicago - Southwest Suburbs
    Posts
    7,615
    Post Thanks / Like

    Default Re: Multiple Arduinos

    Another thing to remember guys is that Vixen 3 sends data the entire time it's open, regardless of whether you're playing a sequence or not. If you're not playing a sequence, it just sends 0x00 for all channels.

  8. #17
    Join Date
    Nov 2009
    Location
    Morrisburg, On, Canada
    Posts
    2,540
    Post Thanks / Like

    Default Re: Multiple Arduinos

    Quote Originally Posted by jchuchla View Post
    Another thing to remember guys is that Vixen 3 sends data the entire time it's open, regardless of whether you're playing a sequence or not. If you're not playing a sequence, it just sends 0x00 for all channels.
    That's the angle I also was looking at. But in post#6 he implies that Vixen is not sending data on some ports, as observed on the RX line of the respective Arduino.
    Perhaps I'm misinterpreting his results.

  9. #18
    Join Date
    Dec 2016
    Location
    Hicksville, New York
    Posts
    102
    Post Thanks / Like

    Default Re: Multiple Arduinos

    Hello, Jetty, I was wondering if there was a way to make the lights stay on when music is not playing and disconnected from my computer. If there is can someone edit the code for me for it to do that? Thanks and thanks for the code, Jetty! It works great.

  10. #19
    Join Date
    Dec 2012
    Posts
    152
    Post Thanks / Like

    Default Re: Multiple Arduinos

    Quote Originally Posted by Spankyty View Post
    Hello, Jetty, I was wondering if there was a way to make the lights stay on when music is not playing and disconnected from my computer. If there is can someone edit the code for me for it to do that? Thanks and thanks for the code, Jetty! It works great.
    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;

  11. #20
    Join Date
    Dec 2016
    Location
    Hicksville, New York
    Posts
    102
    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;
    Thank You!!!!

Page 2 of 5 FirstFirst 1234 ... 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
  •