Pages: [1]   Go Down
Author Topic: Addressable LED strips - how to?  (Read 1683 times)
0 Members and 1 Guest are viewing this topic.
Vancouver, Canada
Offline Offline
Jr. Member
**
Karma: 0
Posts: 73
I want to make a living designing robots
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello, Arduinonauts.  I am very stuck on a problem and would greatly appreciate your kind help, please!

I thought I was careful and very specific when purchasing this 5m strip of water-resistant, addressable LEDs: I wanted to be able to program these from an Arduino.  I should have demanded to see it programmed in store.  I was told it's exactly the same as the Adafruit 8806 strips (http://www.adafruit.com/products/306).  I find that neither of the Adafruit tutorials matches what I have in front of me and I'm really concerned that I'll hook it up wrong and either fry my Arduino, the strip, or both.

There are two wires coming out of the near end.  Wire A is a 12v/GND supply.  Wire B is a 4 pin (jni?) connector.  I match the colors on the pin to the wires in the strip and it looks like they go to D1, C1, St, L1.  There's some doubling in there - the 12v/GND is wired to D1? and L1?  When I plug in a 12v10a the strip lights up white.  There is another 4-pin connector at the far end for daisy chaining strips together. 

The default controller for these strips is the ZJ-168 (seen here: ) which I do not have.

Note that the strip itself is a white color like in the ZJ-168 video, not the gold seen in the Adafruit tutorials.

My questions are:
- How do I wire the 4 pin to the Arduino correctly?
- What kind of 5v power do I need to run the logic?
- If I get this working I'll be extending it to 20m.  What would my current usage look like then?
- Do I need to worry about running too many amps through the 5v? (I'm imagining if one of the strips gets disconnected
- Do I need a common ground?  I'm guessing yes.
- Do you know the original manufacturer?  I'd love to contact them directly and get a sample Arduino app to extend for my use.

I know these are a lot of questions and it's a big ask.  If you can answer any of these it would be a big help.

Thank you so much!
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

- How do I wire the 4 pin to the Arduino correctly?
I think that those drivers are I2C ¿?

- What kind of 5v power do I need to run the logic?
Do you mean to get the arduino working? Just USB power would be ok, or any stabilized 5 V PSU would work. You do not need much power (amps)

- If I get this working I'll be extending it to 20m.  What would my current usage look like then?
-That would depend on how many LEDs / drivers you have, and how much current they need to work, but it will be quite a bit.

- Do I need to worry about running too many amps through the 5v? (I'm imagining if one of the strips gets disconnected
through the 5v¿? Nope, you have to worry about the 12 Volts instead, that is where the LEDs/Drivers will get feed. 5 Volts is only for the arduino. Look out, since you are using just 12 volts over a long strip you will get voltaje drops, maybe you want to feed it not from an end, but from some places.

- Do I need a common ground?  I'm guessing yes.
Of course, ALWAYS!! Even if you do not need it, always put all the grounds together.

- Do you know the original manufacturer?  I'd love to contact them directly and get a sample Arduino app to extend for my use.
Not me.
Logged

Vancouver, Canada
Offline Offline
Jr. Member
**
Karma: 0
Posts: 73
I want to make a living designing robots
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

nahiko -

Thanks for the quick response.  I have no idea if they're i2c or not.  I've been told to try the code at the end of this post but it leave me scratching my head - I don't know where to attach the clock & data pins, the strip documentation is missing.

about the 5v... I've seen some documentation suggest I need as much as 1a/m to send the address&value to each "pixel" on the strip.  This is frightening - I imagine the whole strip melting.

Code:
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
#include <TimerOne.h>


//------------------------------------------------------------------------------
//Example to control 10 RGB LED Modules.
//Bliptronics.com
//Ben Moyes 2009
//Use this as you wish, but please give credit, or at least buy some of my LEDs!
//
// Choose which 2 pins you will use for output.
// Can be any valid output pins.
int clockPin = 2;  // connect to
int dataPin = 3;   // connect to

byte  SendMode=0;   // Used in interrupt 0=start,1=header,2=data,3=data done
byte  BitCount=0;   // Used in interrupt
byte  LedIndex=0;   // Used in interrupt - Which LED we are sending.
byte  BlankCounter=0;  //Used in interrupt.
unsigned int BitMask;   //Used in interrupt.

//Holds the 15 bit RGB values for each LED.
//You'll need one for each LED, we're using 10 LEDs here.
//Note you've only got limited memory on the Arduino, so you can only control
//Several hundred LEDs on a normal arduino. Double that on a Duemilanove.
unsigned int Display[10]; 


//------------------------------------------------------------------------------
void setup() {
 byte Counter;

 pinMode(clockPin, OUTPUT);
 pinMode(dataPin, OUTPUT);

 // Turn all LEDs off.
 for(Counter=0;Counter < 10; Counter++)
   Display[Counter]=Color(Counter,0,31-Counter);
 
 show();

 Timer1.initialize(25);           // initialize timer1, 25 microseconds refresh rate.
 Timer1.attachInterrupt(LedOut);  // attaches callback() as a timer overflow interrupt

}


//------------------------------------------------------------------------------
//Interrupt routine.
//Frequency was set in setup(). Called once for every bit of data sent
//In your code, set global Sendmode to 0 to re-send the data to the pixels
//Otherwise it will just send clocks.
void LedOut()
{
 switch(SendMode)
 {
   case 3:            //Done..just send clocks with zero data
     digitalWrite(dataPin, 0);
     digitalWrite(clockPin, HIGH);
     digitalWrite(clockPin, LOW);
     break;
   case 2:               //Sending Data
     if (BitCount==0)    //First bit is always 1
       {  digitalWrite(dataPin, 1);
           BitMask=0x8000;//Init bit mask
       }
     else if(BitMask & Display[LedIndex])  //If not the first bit then output the next bits (Starting with MSB bit 15 down.)
       digitalWrite(dataPin, 1);
     else
       digitalWrite(dataPin, 0);
     
     BitMask>>=1;
     BitCount++;
     
     if(BitCount == 16)    //Last bit?
     {
       LedIndex++;        //Move to next LED
       if (LedIndex < 10) //Still more leds to go or are we done?
       {
         BitCount=0;      //Start from the fist bit of the next LED           
       }
       else
         SendMode=3;  //No more LEDs to go, we are done!
     }
     // Clock out data.
     digitalWrite(clockPin, HIGH);
     digitalWrite(clockPin, LOW);
     break;     
   case 1:            //Header
       if (BitCount < 32)             
       {
       digitalWrite(dataPin, 0);
       BitCount++;
       if(BitCount==32)
         {
           SendMode++;      //If this was the last bit of header then move on to data.
           LedIndex=0;
           BitCount=0;
         }
       }
     digitalWrite(clockPin, HIGH);
     digitalWrite(clockPin, LOW);

     break;
   case 0:            //Start
     if(!BlankCounter)    //AS SOON AS CURRENT pwm IS DONE. BlankCounter
     {
       BitCount=0;
       LedIndex=0;
       SendMode=1;
     } 
     digitalWrite(clockPin, HIGH);
     digitalWrite(clockPin, LOW);

     break; 
 }
 //Keep track of where the LEDs are at in their pwm cycle.
 BlankCounter++;
}


//------------------------------------------------------------------------------
void show() {
  // The interrupt routine will see this as re-send LED color data.
  SendMode = 0;
}


//------------------------------------------------------------------------------
// Create a 15 bit color value from R,G,B
unsigned int Color(byte r, byte g, byte b) {
 //Take the lowest 5 bits of each value and append them end to end
 return( ((unsigned int)g & 0x1F )<<10 | ((unsigned int)b & 0x1F)<<5 | (unsigned int)r & 0x1F);
}


//------------------------------------------------------------------------------
// Show a colour bar going up from 0 to 9
void ColorUp( unsigned int ColourToUse) {
 byte Counter;
 for(Counter=0;Counter < 10; Counter++) {
   Display[Counter]=ColourToUse;
   show();
   delay(25);
 } 
}


//------------------------------------------------------------------------------
// Show a colour bar going down from 9 to 0
void ColorDown( unsigned int ColourToUse) {
 byte Counter;

 for(Counter=10;Counter > 0; Counter--) {
   Display[Counter-1]=ColourToUse;
   show();
   delay(25);
 } 
}


//------------------------------------------------------------------------------
//Input a value 0 to 127 to get a color value.
//The colours are a transition r - g -b - back to r
unsigned int Wheel(byte WheelPos) {
 byte r,g,b;
 switch(WheelPos >> 5) {
   case 0:
     r=31- WheelPos % 32;   //Red down
     g=WheelPos % 32;      // Green up
     b=0;                  //blue off
     break;
   case 1:
     g=31- WheelPos % 32;  //green down
     b=WheelPos % 32;      //blue up
     r=0;                  //red off
     break;
   case 2:
     b=31- WheelPos % 32;  //blue down
     r=WheelPos % 32;      //red up
     g=0;                  //green off
     break;
 }
 return(Color(r,g,b));
}



//------------------------------------------------------------------------------
void loop() {
  unsigned int Counter, Counter2, Counter3;
 
  // Lets show some demo patterns.
  // Just change Display array, then set SendMode to 0
 
  //Spin LED with colour changing
  for(Counter=0;Counter < 10;Counter++) {
    for(Counter2=0; Counter2 < 10 ; Counter2++) {
      Display[Counter2] = Wheel(Counter * 10 + Counter2);
      show();
 
      delay(25);
      Display[Counter2] = Color(0,0,0) ;   
      show();
    }
  }

  //Scrolling Rainbow Effect
  for(Counter=0; Counter < 200 ; Counter++) {
    Counter3=Counter * 1;
    for(Counter2=0; Counter2 < 10; Counter2++) {
      Display[Counter2] = Wheel(Counter3%95);  //There's only 96 colors in this pallette.
      Counter3+=10;
    }   
    show();
    delay(25);
  }

  //Color wipes.
  for(Counter=0;Counter < 2;Counter++) {
    ColorUp(Color(random(0,32),random(0,32),random(0,32)));
    delay(500);
    ColorDown(Color(random(0,32),random(0,32),random(0,32)));
    delay(500);
  }
}
Logged

Pages: [1]   Go Up
Jump to: