Author Topic: vixen 3.2u1 + 2 arduino mega + 150 ws2811 = Problem  (Read 3030 times)

Offline skykicker

  • Jr. Member
  • **
  • Posts: 7
 ;D so i have a working code for 32 channel relay broad running on one of the megas
Code: You are not allowed to view links. Register or Login
const int numChannels = 32;
// List Arduino pins in Channel number order
int channels[numChannels] = {2,3,4,5,6,7,8,9,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45};
int incomingByte[numChannels];

void setup()
{
Serial.begin(9600);



for(int i = 0; i < numChannels; i++){
pinMode(channels[i], OUTPUT);
// Start with lights turned off
//digitalWrite(channels[i],0);
digitalWrite(channels[i],0);
}


}

void loop()
{
if (Serial.available() >= numChannels)
{
for (int i=0; i<numChannels;i++)
incomingByte[i] = Serial.read();


for(int i = 0; i < numChannels; i++)
//digitalWrite(channels[i], incomingByte[i]);
digitalWrite(channels[i], incomingByte[i]);
//LED STUFF

}
}

fastled test works fine. :)
but this code and vixen do radom things.
 what did i do wrong with the code?
Code: You are not allowed to view links. Register or Login

void setup() {

         FastLED.addLeds<WS2811, PIN, RGB>(leds, NUM_LEDS);
  Serial.begin(115200);

}

void loop() {

 
for(int i = 0; i < NUM_LEDS; i++) {
  if (Serial.available() > 2) {
    Serial.readBytes( (char*)leds, NUM_LEDS * 3);
   
  }
    FastLED.show();
 }

}

 ???
one of the main things it will do is start at light 2 for light 1, even though i made sure the controller points to the right spot

any help would be aprecited thanks

this coden works for pixels 1-21 then the rest are wierd
Code: You are not allowed to view links. Register or Login
#include <Adafruit_NeoPixel.h>    //  This is the Neo-Pixel library (ws2812)
                                  //  Change to the library for your pixel types
                                  //  Suggest using a library created by Adafruit
                                  //  so the function names will be the same                               
                                 
                                 
                                 
#define DPIN 6                    //  Change this to the pin# connected to your pixels DataIn
                                  //  Will probably need to define a ClockPin for other pixel


int   PixelCount = 150;             //  Set this to the number of Pixels connected

int   bugLevel  = 0;              //  This is just a way I manage turning debugging over serial on/off

 

/*  Sets up the NeoPixel Strip object
 Replace with proper Object initiation for your pixel types */
Adafruit_NeoPixel strip = Adafruit_NeoPixel(150, DPIN, NEO_RGB + NEO_KHZ800);   



void setup()
{
  delay(50);                    //  A delay for a reason I can't remember. I can live with one in the setup. 
  strip.begin();                 //  Get strip started
  strip.show();                  //  Initialize all pixels to 'off'
 
  Serial.begin(115200);          //  Start the Serial communication
  bugit("Setup Complete",0);    //  DEBUG: Confirm setup is complete


}






void loop()
{                                       // START LOOP
 


 
  if (Serial.available()>2)             // Wait for a few bytes to be recieved
  {
    bugit("Waiting for Header",10);     // DEBUG: Header waiting started
    waitForVixenHeader();               // Header check function
    bugit("VixStart Triggered",10);     //  DEBUG: Header found; getting color data
 
    for (int pixCount=0; pixCount<PixelCount;pixCount++)       // Do this for as many Pixels defined in PixelCount
    {
      int RGB[3];                             // Create array to hold this pixels RGB value                   
      for (int color = 0;color<3;color++)     // For the next 3 incoming bytes
      {                       
        while (Serial.available() < 1)        // Wait for bytes to be received
        {
          delay(10);
        }
        RGB[color] = Serial.read();           // Save this byte to the correct RGB value
      }                                       // Repeat until bytes for this pixels RGB value have been recieved

      strip.setPixelColor(pixCount,RGB[0],RGB[1],RGB[2]);  //Set this pixels new color
     
    }                                         // Repeat untill all pixels have had new RGB value set
    strip.show();                             // Update the strip and show with new color                             
  }                                           // YAY! DO IT AGAIN!
}                                              // END OF LOOP



/**
 *  FUNC    bugit           [manages printing of debugging based on debugging level]
 *  @param  String  bugstr  [string to be be printed]
 *  @param  int     blevel  [the level at which this debugging should be ignored]
 *   
*/


int bugit(String bugstr,int blevel)
{
  if (blevel < bugLevel)
  {
    Serial.println(bugstr);
  }
}


/**
 * I 'borrowed' snippets of this waitForVixenHeader() function from some code I found online
 * Can't find the originator now but thank you. It works well. 
 *
 */
void waitForVixenHeader()
{

    bugit("Waiting Loop",10);
    char *header="VIXStart";
    char buffer[3];
    int index = 0;

    while (true)
    {

        int inByte = Serial.read();
        if(inByte==-1)
        {
          continue;
        }
       
        buffer[index] = inByte;
        if(buffer[index]!=header[index])
        {           
            index=-1;                     // not the right sequence restart
        }
       
        buffer[index+1] = 0;              // add null
        index++;
        if(index==8)
        {
          return;
        }
    }
}[\code]
« Last Edit: November 08, 2015, by skykicker »

Offline TexasStingray

  • Coop Manager
  • Sr. Member
  • *
  • Posts: 791
Re: vixen 3.2u1 + 2 arduino mega + 150 ws2811 = Problem
« Reply #1 on: November 08, 2015, »
You would be better off posting this on an arduino forum.
Scott Wanner
TX

Watch my videos
You are not allowed to view links. Register or Login

Offline skykicker

  • Jr. Member
  • **
  • Posts: 7
Re: vixen 3.2u1 + 2 arduino mega + 150 ws2811 = Problem
« Reply #2 on: November 08, 2015, »
just t6ring a few forums to see who has best answers