Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Vixen Lights + Arduino + Shift Registers - Help Needed

  1. #1
    Join Date
    Dec 2013
    Location
    UK
    Posts
    89
    Post Thanks / Like

    Default Vixen Lights + Arduino + Shift Registers - Help Needed

    Hi Guys,

    Still Having trouble setting up our light show. We are using 74HC595 Shift Registers Controlled off a Arduino Mega 2560. We need full dimming as we have alot of RGB in our show. We have successfully proven that the arduinio + Shift registers + Transistors works Using this code witch changes them between different colours:
    Code:
    /
    // You can choose the latch pin yourself.
    const int ShiftPWM_latchPin=53;
    
    // ** uncomment this part to NOT use the SPI port and change the pin numbers. This is 2.5x slower **
    // #define SHIFTPWM_NOSPI
    // const int ShiftPWM_dataPin = 11;
    // const int ShiftPWM_clockPin = 13;
    
    
    // If your LED's turn on if the pin is low, set this to true, otherwise set it to false.
    const bool ShiftPWM_invertOutputs = false; 
    
    // You can enable the option below to shift the PWM phase of each shift register by 8 compared to the previous.
    // This will slightly increase the interrupt load, but will prevent all PWM signals from becoming high at the same time.
    // This will be a bit easier on your power supply, because the current peaks are distributed.
    const bool ShiftPWM_balanceLoad = false;
    
    #include <ShiftPWM.h>   // include ShiftPWM.h after setting the pins!
    
    // Here you set the number of brightness levels, the update frequency and the number of shift registers.
    // These values affect the load of ShiftPWM.
    // Choose them wisely and use the PrintInterruptLoad() function to verify your load.
    // There is a calculator on my website to estimate the load.
    
    unsigned char maxBrightness = 255;
    unsigned char pwmFrequency = 75;
    int numRegisters = 5;
    int numRGBleds = numRegisters*8/3;
    
    void setup(){
      Serial.begin(9600);
    
      // Sets the number of 8-bit registers that are used.
      ShiftPWM.SetAmountOfRegisters(numRegisters);
    
      // SetPinGrouping allows flexibility in LED setup. 
      // If your LED's are connected like this: RRRRGGGGBBBBRRRRGGGGBBBB, use SetPinGrouping(4).
      ShiftPWM.SetPinGrouping(1); //This is the default, but I added here to demonstrate how to use the funtion
      
      ShiftPWM.Start(pwmFrequency,maxBrightness);
    }
    
    
    
    void loop()
    {    
      // Turn all LED's off.
      ShiftPWM.SetAll(0);
    
      // Print information about the interrupt frequency, duration and load on your program
      ShiftPWM.PrintInterruptLoad();
    
      // Fade in and fade out all outputs one by one fast. Usefull for testing your hardware. Use OneByOneSlow when this is going to fast.
      ShiftPWM.OneByOneFast();
    
      // Fade in all outputs
      for(int j=0;j<maxBrightness;j++){
        ShiftPWM.SetAll(j);  
        delay(20);
      }
      // Fade out all outputs
      for(int j=maxBrightness;j>=0;j--){
        ShiftPWM.SetAll(j);  
        delay(20);
      }
    
    
      // Fade in and out 2 outputs at a time
      for(int output=0;output<numRegisters*8-1;output++){
        ShiftPWM.SetAll(0);
        for(int brightness=0;brightness<maxBrightness;brightness++){
          ShiftPWM.SetOne(output+1,brightness);
          ShiftPWM.SetOne(output,maxBrightness-brightness);
          delay(1);
        }
      }
    
      // Hue shift all LED's
      for(int hue = 0; hue<360; hue++){
        ShiftPWM.SetAllHSV(hue, 255, 255); 
        delay(50);
      }
    
      // Alternate LED's in 6 different colors
      for(int shift=0;shift<6;shift++){
        for(int led=0; led<numRGBleds; led++){
          switch((led+shift)%6){
          case 0:
            ShiftPWM.SetRGB(led,255,0,0);    // red
            break;
          case 1:
            ShiftPWM.SetRGB(led,0,255,0);    // green
            break;
          case 2:
            ShiftPWM.SetRGB(led,0,0,255);    // blue
            break;
          case 3:
            ShiftPWM.SetRGB(led,255,128,0);  // orange
            break;
          case 4:
            ShiftPWM.SetRGB(led,0,255,255);  // turqoise
            break;
          case 5:
            ShiftPWM.SetRGB(led,255,0,255);  // purple
            break;
          }
        }
        delay(2000);
      }
    
      // Update random LED to random color. Funky!
      for(int i=0;i<1000;i++){
        ShiftPWM.SetHSV(random(numRGBleds),random(360),255,255);
        delay(15);
      }
    
    
      // Immitate a VU meter
      int peak=0;
      int prevPeak=0;
    
      int currentLevel = 0;
      for(int i=0;i<40;i++){
        prevPeak = peak;
        while(abs(peak-prevPeak)<5){
          peak =  random(numRGBleds); // pick a new peak value that differs at least 5 from previous peak
        }
        // animate to new top
        while(currentLevel!=peak){
          if(currentLevel<peak){
            currentLevel++;
          }
          else{
            currentLevel--;
          }
          for(int led=0;led<numRGBleds;led++){
            if(led<=currentLevel){
              int hue = (numRGBleds-1-led)*120/numRGBleds; // From green to red
              ShiftPWM.SetHSV(led,hue,255,255); 
            }
            else{
              ShiftPWM.SetRGB(led,0,0,0);
            }
          }
          delay((64/numRGBleds)*(numRGBleds-currentLevel)); // go slower near the top
        }
      }
    
      //  A moving rainbow for RGB leds:
      rgbLedRainbow(numRGBleds, 5, 3, numRegisters*8/3); // Fast, over all LED's
      rgbLedRainbow(numRGBleds, 10, 3, numRegisters*8/3*4); //slower, wider than the number of LED's
    }
    
    void rgbLedRainbow(int numRGBLeds, int delayVal, int numCycles, int rainbowWidth){
      // Displays a rainbow spread over a few LED's (numRGBLeds), which shifts in hue. 
      // The rainbow can be wider then the real number of LED's.
    
      ShiftPWM.SetAll(0);
      for(int cycle=0;cycle<numCycles;cycle++){ // loop through the hue shift a number of times (numCycles)
        for(int colorshift=0;colorshift<360;colorshift++){ // Shift over full color range (like the hue slider in photoshop)
          for(int led=0;led<numRGBLeds;led++){ // loop over all LED's
            int hue = ((led)*360/(rainbowWidth-1)+colorshift)%360; // Set hue from 0 to 360 from first to last led and shift the hue
            ShiftPWM.SetHSV(led, hue, 255, 255); // write the HSV values, with saturation and value at maximum
          }
          delay(delayVal); // this delay value determines the speed of hue shift
        } 
      }  
    }

    However when we come to using Vixen, nothing happens, we have different code obviously witch i will put bellow. All channels remain off. Please could someone tell me where i am going wrong. Also i have 40 Channels over 5 Shift Registers

    Code:
    int incomingByte[40];
    // You can choose the latch pin yourself.
    const int ShiftPWM_latchPin = 53;
    // Clock and data pins are pins from the hardware SPI, you cannot choose them yourself.
    // Data pin is MOSI (Uno and earlier: 11, Leonardo: ICSP 4, Mega: 51, Teensy 2.0: 2, Teensy 2.0++: 22) 
    // Clock pin is SCK (Uno and earlier: 13, Leonardo: ICSP 3, Mega: 52, Teensy 2.0: 1, Teensy 2.0++: 21)
    
    //#define SHIFTPWM_NOSPI
    //const int ShiftPWM_dataPin = 11;
    //const int ShiftPWM_clockPin = 13;
    
    // If your LED's turn on if the pin is low, set this to true, otherwise set it to false.
    const bool ShiftPWM_invertOutputs = false;
    
    // You can enable the option below to shift the PWM phase of each shift register by 8 compared to the previous.
    // This will slightly increase the interrupt load, but will prevent all PWM signals from becoming high at the same time.
    // This will be a bit easier on your power supply, because the current peaks are distributed.
    const bool ShiftPWM_balanceLoad = false;
    
    #include <ShiftPWM.h> // include ShiftPWM.h after setting the pins!
    
    // Here you set the number of brightness levels, the update frequency and the number of shift registers.
    unsigned char maxBrightness = 255;
    unsigned char pwmFrequency = 150;
    unsigned int numRegisters = 5;
    unsigned int numOutputs = numRegisters*8;
    unsigned int numRGBLeds = numRegisters*8/3;
    
    void setup(){
    
    Serial.begin(9600);
    
    // Sets the number of 8-bit registers that are used.
    ShiftPWM.SetAmountOfRegisters(numRegisters);
    ShiftPWM.Start(pwmFrequency,maxBrightness);
    
    delay(500);
    ShiftPWM.SetAll(0);
    delay(500);
    ShiftPWM.SetAll(255);
    delay(500);
    ShiftPWM.SetAll(0);
    delay(500);
    ShiftPWM.SetAll(255);
    delay(500);
    ShiftPWM.SetAll(0);
    delay(500);
    ShiftPWM.SetAll(255);
    delay(500);
    ShiftPWM.SetAll(0);
    delay(500);
    ShiftPWM.SetAll(255);
    delay(500);
    ShiftPWM.SetAll(0);
    delay(500);
    ShiftPWM.SetAll(255);
    delay(500);
    ShiftPWM.SetAll(0);
    }
    
    void loop()
     { 
       if (Serial.available() >= 40) 
       {
    // read the oldest byte in the serial buffer:
         for (int i=0; i<40; i++) 
         {
    // read each byte
           incomingByte[i] = Serial.read();
         } 
          ShiftPWM.SetOne(0, incomingByte[0]);
          ShiftPWM.SetOne(1, incomingByte[1]);
          ShiftPWM.SetOne(2, incomingByte[2]);
          ShiftPWM.SetOne(3, incomingByte[3]);
          ShiftPWM.SetOne(4, incomingByte[4]);
          ShiftPWM.SetOne(5, incomingByte[5]);
          ShiftPWM.SetOne(6, incomingByte[6]);
          ShiftPWM.SetOne(7, incomingByte[7]);
          ShiftPWM.SetOne(8, incomingByte[8]);
          ShiftPWM.SetOne(9, incomingByte[9]);
          ShiftPWM.SetOne(10, incomingByte[10]);
          ShiftPWM.SetOne(11, incomingByte[11]);
          ShiftPWM.SetOne(12, incomingByte[12]);
          ShiftPWM.SetOne(13, incomingByte[13]);
          ShiftPWM.SetOne(14, incomingByte[14]);
          ShiftPWM.SetOne(15, incomingByte[15]);
          ShiftPWM.SetOne(16, incomingByte[16]);
          ShiftPWM.SetOne(17, incomingByte[17]);
          ShiftPWM.SetOne(18, incomingByte[18]);
          ShiftPWM.SetOne(19, incomingByte[19]);
          ShiftPWM.SetOne(20, incomingByte[20]);
          ShiftPWM.SetOne(21, incomingByte[21]);
          ShiftPWM.SetOne(22, incomingByte[22]);
          ShiftPWM.SetOne(23, incomingByte[23]);
          ShiftPWM.SetOne(24, incomingByte[24]);
          ShiftPWM.SetOne(25, incomingByte[25]);
          ShiftPWM.SetOne(26, incomingByte[26]);
          ShiftPWM.SetOne(27, incomingByte[27]);
          ShiftPWM.SetOne(28, incomingByte[28]);
          ShiftPWM.SetOne(29, incomingByte[29]);
          ShiftPWM.SetOne(30, incomingByte[30]);
          ShiftPWM.SetOne(31, incomingByte[31]);
          ShiftPWM.SetOne(32, incomingByte[32]);
          ShiftPWM.SetOne(33, incomingByte[33]);
          ShiftPWM.SetOne(34, incomingByte[34]);
          ShiftPWM.SetOne(35, incomingByte[35]);
          ShiftPWM.SetOne(36, incomingByte[36]);
          ShiftPWM.SetOne(37, incomingByte[37]);
          ShiftPWM.SetOne(38, incomingByte[38]);
          ShiftPWM.SetOne(39, incomingByte[39]);
          ShiftPWM.SetOne(40, incomingByte[40]);
       }
    }
    Many Thanks

    JWhiteLights
    Last edited by jwhitelights; 12-11-2015 at 06:33 PM. Reason: Removing Old Signiture

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

    Default Re: Vixen Lights + Arduino + Shift Registers - Help Needed

    With regards to the second sketch, have you tried to fill the array incomingByte[i] via a sketch routine rather than Vixen - to verify that portion of the code?
    The Vixen part could be received via a FT232, then allowing you to use the Serial Monitor to validate the Vixen data stream.
    Of hand nothing jumps at me to raise a concern by viewing your sketch.

  3. #3
    Join Date
    Dec 2013
    Location
    UK
    Posts
    89
    Post Thanks / Like

    Default Re: Vixen Lights + Arduino + Shift Registers - Help Needed

    After A whole day researching and rewriting i have found that i had one to many lies of code writing to the shift registers. Silly me! Show Now running!
    Thanks for the help

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

    Default Re: Vixen Lights + Arduino + Shift Registers - Help Needed

    Good to hear you succeeded. Yes, redoing things can be a useful education.

  5. #5
    Join Date
    Dec 2016
    Posts
    2
    Post Thanks / Like

    Default Re: Vixen Lights + Arduino + Shift Registers - Help Needed

    i'm looking to do the same thing with shift registers. what line of code did u change to get it running

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

    Default Re: Vixen Lights + Arduino + Shift Registers - Help Needed

    Quote Originally Posted by andy932 View Post
    i'm looking to do the same thing with shift registers. what line of code did u change to get it running
    I think it depends on what you are doing.
    The hardware setup is designed for 5 shift registers which provides 40 channels of output. The sketch reads 40 channels worth to properly shift all the data through the shift registers.
    But RGB works in groups of 3 LEDs so you only get 13 RGB "pixels", or 39 channels. If Vixen is setup for 39 channels then your sketch will be out of sync since it wants to read 40 channels of data.

    So use the sketch as is and tell Vixen to send 40 channels of data, consisting of 13 RGB pixels, plus one channel (40th) with null data.

    The other way is to modify the sketch so that you only receive 39 channels and comment out the 40th, i.e. ShiftPWM.SetOne(40, incomingByte[40]); Now set Vixen to only send 13 RGB pixels, with no "dummy" channel.

    I haven't tried it so it is possible I overlooked something.
    Last edited by LightUp; 12-30-2016 at 11:41 AM.

  7. #7
    Join Date
    Jun 2018
    Posts
    10
    Post Thanks / Like

    Default Re: Vixen Lights + Arduino + Shift Registers - Help Needed

    Good evening, I apologize for reliving this topic. I followed the code of jwhitelights to connect my Arduino UNO +
    two Shift register + Vixen. I have managed the connection of twelve outputs but they are not aligned, that is, vixen sends the command that turns on port 1, 2 and 3 but turns on 1 and 4 with the order given for 1 and the order for port 3 turns on the 3, 6 and 7. There is an error that I still do not understand. I have taken this code because I want to make only three of the outputs can pwm.

    Thanks

    Code:
    int incomingByte[12];
    // You can choose the latch pin yourself.
    const int ShiftPWM_latchPin = 8;
    // Clock and data pins are pins from the hardware SPI, you cannot choose them yourself.
    // Data pin is MOSI (Uno and earlier: 11, Leonardo: ICSP 4, Mega: 51, Teensy 2.0: 2, Teensy 2.0++: 22) 
    // Clock pin is SCK (Uno and earlier: 13, Leonardo: ICSP 3, Mega: 52, Teensy 2.0: 1, Teensy 2.0++: 21)
    
    
    #define SHIFTPWM_NOSPI
    const int ShiftPWM_dataPin = 11;
    const int ShiftPWM_clockPin = 13;
    
    
    // If your LED's turn on if the pin is low, set this to true, otherwise set it to false.
    const bool ShiftPWM_invertOutputs = false;
    
    
    // You can enable the option below to shift the PWM phase of each shift register by 8 compared to the previous.
    // This will slightly increase the interrupt load, but will prevent all PWM signals from becoming high at the same time.
    // This will be a bit easier on your power supply, because the current peaks are distributed.
    const bool ShiftPWM_balanceLoad = false;
    
    
    #include <ShiftPWM.h> // include ShiftPWM.h after setting the pins!
    
    
    // Here you set the number of brightness levels, the update frequency and the number of shift registers.
    unsigned char maxBrightness = 255;
    unsigned char pwmFrequency = 75;
    unsigned int numRegisters = 2;
    unsigned int numOutputs = numRegisters*8;
    unsigned int numRGBLeds = numRegisters*8/1;
    
    
    void setup(){
    
    
    Serial.begin(9600);
    
    
    // Sets the number of 8-bit registers that are used.
    ShiftPWM.SetAmountOfRegisters(numRegisters);
    ShiftPWM.Start(pwmFrequency,maxBrightness);
    
    
    delay(500);
    ShiftPWM.SetAll(0);
    delay(500);
    ShiftPWM.SetAll(255);
    delay(500);
    ShiftPWM.SetAll(0);
    delay(500);
    ShiftPWM.SetAll(255);
    delay(500);
    ShiftPWM.SetAll(0);
    delay(500);
    ShiftPWM.SetAll(255);
    delay(500);
    ShiftPWM.SetAll(0);
    delay(500);
    ShiftPWM.SetAll(255);
    delay(500);
    ShiftPWM.SetAll(0);
    delay(500);
    ShiftPWM.SetAll(255);
    delay(500);
    ShiftPWM.SetAll(0);
    }
    
    
    void loop()
     { 
       if (Serial.available() >= 12) 
       {
    // read the oldest byte in the serial buffer:
         for (int i=0; i<12; i++) 
         {
    // read each byte
           incomingByte[i] = Serial.read();
         } 
          ShiftPWM.SetOne(0, incomingByte[0]);
          ShiftPWM.SetOne(1, incomingByte[1]);
          ShiftPWM.SetOne(2, incomingByte[2]);
          ShiftPWM.SetOne(3, incomingByte[3]);
          ShiftPWM.SetOne(4, incomingByte[4]);
          ShiftPWM.SetOne(5, incomingByte[5]);
          ShiftPWM.SetOne(6, incomingByte[6]);
          ShiftPWM.SetOne(7, incomingByte[7]);
          ShiftPWM.SetOne(8, incomingByte[8]);
          ShiftPWM.SetOne(9, incomingByte[9]);
          ShiftPWM.SetOne(10, incomingByte[10]);
          ShiftPWM.SetOne(11, incomingByte[11]);
          ShiftPWM.SetOne(12, incomingByte[12]);
    
    
       }
    }

  8. #8
    Join Date
    Oct 2014
    Location
    Sauk City, WI USA
    Posts
    947
    Post Thanks / Like

    Default Re: Vixen Lights + Arduino + Shift Registers - Help Needed

    Quote Originally Posted by Diego View Post
    Good evening, I apologize for reliving this topic.
    How do you know you are getting the right sequence of data from Vixen? Maybe you are receiving different channels than you think? Serial output from Vixen needs at least a header to tell it the start of the data packet has arrived. Create a loop reading the serial until it finds whatever header you set in Vixen. Then read the next 12 channel data.

    You are collecting 12 bytes of data but sending out 13 bytes (0-12).

    Have you tested that leds 0-11 turn on when ShiftPWM is called appropriately. Something like this in setup (untested):
    Code:
         // Incremental test (turns on LEDs in order)
         for (int i=0; i<12; i++) 
         {
          ShiftPWM.SetOne(i, 255);
          delay(1000);
          ShiftPWM.SetOne(i, 0);
         }

  9. #9
    Join Date
    Jun 2018
    Posts
    10
    Post Thanks / Like

    Default Re: Vixen Lights + Arduino + Shift Registers - Help Needed

    Quote Originally Posted by MikeKrebs View Post

    Have you tested that leds 0-11 turn on when ShiftPWM is called appropriately. Something like this in setup (untested):
    Hi, thank you very much for answering my question. Yes, I have tried and effectively all turn on perfectly. Also I have another code that works perfectly with the sequence of vixen, but it is not pwm, so I have rejected it, I want it to be pwm. attach the code that is not pwm so you can compare it.

    Code:
    //code to use one or multiple 595 shift registers, generic serial plugin//and VixenLights
    
    
    #include <Shifter.h>
    
    
    #define SER_Pin 8 //SER_IN
    #define RCLK_Pin 13 //L_CLOCK
    #define SRCLK_Pin 11 //CLOCK
    
    
    #define NUM_REGISTERS 2 //how many registers are in the chain
    
    
    
    
    //initaize shifter using the Shifter library
    Shifter shifter(SER_Pin, RCLK_Pin, SRCLK_Pin, NUM_REGISTERS);
    int incomingByte[12]; // array to store the 56 values from the serial port
    
    
    void setup(){
    Serial.begin(9600); 
    }
    
    
    void loop(){
    
    
    if (Serial.available() >= 12) {
    // read the oldest byte in the serial buffer:
    for (int i=0; i<12; i++) {
    // read each byte
    incomingByte[i] = Serial.read();
    }
    
    
    shifter.clear(); //set all pins on the shift register chain to LOW
    shifter.write(); //send changes to the chain and display them
    
    
    //delay(1000);
    
    
    //0-7 for 8 shift register outputs, continue with 8-15 for second 595 etc. for multiple 595's
    shifter.setPin(0, incomingByte[0]); 
    shifter.setPin(1, incomingByte[1]);
    shifter.setPin(2, incomingByte[2]);
    shifter.setPin(3, incomingByte[3]);
    shifter.setPin(4, incomingByte[4]);
    shifter.setPin(5, incomingByte[5]);
    shifter.setPin(6, incomingByte[6]);
    shifter.setPin(7, incomingByte[7]);
    shifter.setPin(8, incomingByte[8]);
    shifter.setPin(9, incomingByte[9]);
    shifter.setPin(10, incomingByte[10]);
    shifter.setPin(11, incomingByte[11]);
    shifter.setPin(12, incomingByte[12]);
    
    
    
    
    
    
    shifter.write(); //send changes to the chain and display them
    
    
    //delay(1000);
    }
    }

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

    Default Re: Vixen Lights + Arduino + Shift Registers - Help Needed

    this has almost no chance of being stable.. no frame sync. no port init etc. i suggest you look at the code jcook posted a few weeks ago and then modify yours to work
    Last edited by MartinMueller2003; 10-13-2018 at 05:13 PM.


    2018 - Moving and going to visit my Daughter in New Zealand. Most likely I will be dark or nearly dark, Some static stuff that is simple to put up.

Page 1 of 2 12 LastLast

Tags for this Thread

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
  •