Go Down

Topic: Very new to arduino (first day), need sample code to at least turn on a WS2811 (Read 5415 times) previous topic - next topic

hamster462

I spent a few hours searching but found 100% no code that would even get one of the LED's to turn on. I managed to import the FastSPI_LED library and then must have tried 30 different pieces of code and nothing has worked.

Hi, I recently got an arduino uno and would and a 50LED WS2811 light strip.

The LED strip has 4 wires (red, black (which I connected to a 5V rail of an old computer power supply), and the final 2 wires are a green and a white wire.  (the white and black wire seem to be connected together as the resistance reads as 0.3 ohms )

I took a picture of the hardware. http://i.imgur.com/SDrDLsY.jpg


I would at least like to get the LED's to turn on  (First time using arduino)



The LED's purchased were these: http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=151023467725&ssPageName=ADME:X:BOCOR:US:1123


hamster462

That was one of the first ones I tried. (the writer made it quite difficult to find the code )
http://sourceforge.net/p/abavr/lib/ci/e3429e3493e08015d94d9237699bf15c085970c7/tree/WS2811/WS2811.h

That was the one I tried copying, and confirmed that the correct pin was used, and the LED's did not attempt to light.

the next that I tried was
http://funkboxing.com/wordpress/wp-content/_postfiles/sk_qLEDFX_POST.ino

but it would not even let me flash it

I also tried

http://arduino.cc/forum/index.php?topic=80567.20;wap2

and other than those, I mostly found forum post with sample code but none of the code was in a form where it can just be used, they were all partial.
eg http://arduino.cc/forum/index.php?topic=164120.0

Just not sure what I am doing wrong.

Edit: I originally started off with the info provided on this video and imported the libraries listed http://code.google.com/p/fastspi/source/browse/#svn%2Ftrunk%253Fstate%253Dclosed for the library, and

https://github.com/tomfinnie/LEDstrip/tree/master/switched for the users code (also did not work)

fungus

Try this:

Code: [Select]

/*------------------------------------------------------------------------
 WS2811 demo
------------------------------------------------------------------------*/
#include <Arduino.h>
#include <util/delay.h>

/*------------------------------------------------------------------------
 Pin mappings for different chips
------------------------------------------------------------------------*/

#if defined (__AVR_ATtiny85__)
#define LED_DDR DDRB
#define LED_PORT PORTB
#define LED_PIN PINB
#define LED_BIT _BV(3)

#elif defined (__AVR_ATtiny84__)
#define LED_DDR DDRA
#define LED_PORT PORTA
#define LED_PIN PINA
#define LED_BIT _BV(0)

#else
// Assume Arduino Uno, digital pin 8 (ie. port B, pin 0)
// See http://arduino.cc/en/Hacking/PinMapping168 for pin mappings

#define LED_DDR DDRB
#define LED_PORT PORTB
#define LED_PIN PINB
#define LED_BIT _BV(0)

#endif

#define NOP __asm__("nop\n\t")

/*------------------------------------------------------------------------
 Set the LED pin as output on startup
------------------------------------------------------------------------*/
class WS2811 {
public:
 static void init() {
   LED_PORT &= ~LED_BIT;
   LED_DDR |= LED_BIT;
 }

 static void sendByte(byte b) {
   byte i=8;
   do {
     if ((b&0x80)==0) {
       // Send a '0'
       if (F_CPU==16000000L) {
         LED_PIN=LED_BIT;NOP;// Hi (start)
         NOP;NOP;            // Hi
         LED_PIN=LED_BIT;NOP;// Lo (250ns)
         NOP;NOP;            // Lo
         NOP;NOP;            // Lo (500ns)
       }
       else if (F_CPU==8000000L) {
         LED_PIN = LED_BIT;  // Hi (start)
         NOP;                // Hi
         LED_PIN = LED_BIT;  // Lo (250ns)
         NOP;                // Lo
         NOP;                // Lo (500ns)
         NOP;                // Lo (data bit here!)  
         NOP;                // Lo (750ns)
       }
     }
     else {
       // Send a '1'
       if (F_CPU==16000000L) {
         LED_PIN=LED_BIT;NOP;// Hi (start)
         NOP;NOP;            // Hi
         NOP;NOP;            // Hi (250ns)
         NOP;NOP;            // Hi
         NOP;NOP;            // Hi (500ns)
         LED_PIN=LED_BIT;    // Lo (625ns)
       }
       else if (F_CPU==8000000L) {
         LED_PIN = LED_BIT;  // Hi (start)
         NOP;                // Hi
         NOP;                // Hi (250ns)
         NOP;                // Hi
         NOP;                // Hi (500ns)
         NOP;                // Hi (data bit here!)
         LED_PIN = LED_BIT;  // Lo (750ns)
       }
     }
     b = b+b;
   } while (--i!=0);
 }
};
WS2811 ws2811;

/*------------------------------------------------------------------------
 LED object
------------------------------------------------------------------------*/
class LED {
 byte r_,g_,b_;
public:
 LED& setColor(byte r, byte g, byte b) {
   r_ = r;
   g_ = g;
   b_ = b;
 }
 // nb. Interrupts must be disabled when you call this (use "cli()")
 void send() const {
   ws2811.sendByte(g_);
   ws2811.sendByte(b_);
   ws2811.sendByte(r_);
 }
};

/*------------------------------------------------------------------------
 Three LEDs
------------------------------------------------------------------------*/
LED led1,led2,led3;

void sendLEDs()
{
 // Interrupts off
 cli();
 // Send 60 LEDs
 for (byte i=0; i<20; ++i) {
   led1.send();
   led2.send();
   led3.send();
 }
 // Interrupts on again
 sei();
}

/*------------------------------------------------------------------------
 Testing on the Mega328
------------------------------------------------------------------------*/
void setup()
{
 // Initialize ws2811 object
 ws2811.init();

 // Set LED colors
 byte a = 0x00;
 byte b = 0xff;
 led1.setColor(b,b,a);
 led2.setColor(a,a,b);
 led3.setColor(a,b,b);
}

void loop()
{
 // Update LEDs
 sendLEDs();

 // Wait one second
 _delay_ms(1000);

 // Swap the LEDs around
 LED t = led1;
 led1 = led2;
 led2 = led3;
 led3 = t;
}




The LED strip has 4 wires (red, black (which I connected to a 5V rail of an old computer power supply), and the final 2 wires are a green and a white wire.  (the white and black wire seem to be connected together as the resistance reads as 0.3 ohms )


Connect the green wire to Arduino pin 8 and the white wire to Arduino GND.

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)


Renizy

okay that sample code worked for me very well. After I flipped around my strips so I was using the right input T-T
I was wondering if someone could elaborate on how it all works?
I have worked out that the A is 0 and B is 1 or at least A makes one of the colors turn off in the RGB on and then B make them turn on and that I can add more to the led1-led3 and make more than 3 in a row changing color.
so if the first part of the coding has the timing that sends out the on and off how would I add more precise color changing to my strip like having it make R255, G128, B000, hex color ff8000, which should be orange in color.

 

fungus


okay that sample code worked for me very well. After I flipped around my strips so I was using the right input T-T
I was wondering if someone could elaborate on how it all works?
I have worked out that the A is 0 and B is 1 or at least A makes one of the colors turn off in the RGB on and then B make them turn on and that I can add more to the led1-led3 and make more than 3 in a row changing color.
so if the first part of the coding has the timing that sends out the on and off how would I add more precise color changing to my strip like having it make R255, G128, B000, hex color ff8000, which should be orange in color.


led1.setColor(255,128,0);

Oh, and some strips have the colors switched around. You might need to change the "send()" function in the LED class to this:

Code: [Select]

  void send() const {
    ws2811.sendByte(g_);
    ws2811.sendByte(r_);
    ws2811.sendByte(b_);
  }


No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Renizy

Okay I have fiddled with it for a while.  I have found that the best results are from using the ws2811.h library from  http://bleaklow.com/2012/12/02/driving_the_ws2811_at_800khz_with_a_16mhz_avr.html and the code that this guy made https://www.youtube.com/watch?v=qwWkKQoja8s  I am do not have a mic to hook up to it at the moment but they do make a really pretty color flow with nothing but the lights attached on my arduino uno. http://www.amazon.com/gp/product/B006H06TVG/ref=oh_details_o03_s00_i00?ie=UTF8&psc=1

Basically what I want to do is use either a few buttons, or a few pots (I have both) to switch between light patterns.

thanks for any help.

Go Up