Oct 262012
Some LED effects I’ve written for Arduino and FastSPI library.
Mostly written for a circle of LEDs but plenty useful for any configuration.
Code available here… the code
Used WS2811 strip, but have also tested with WS2801.
I’ve only tested this on the duemilanove and nano boards. It’s looking like this does not work on the UNO and I’m not sure about the Leonardo or the new Due.
Several people have indicated problems finding the SerialCommand library – so here’s the version I’m using SerialCommand
Here’s where I found it. Thanks to this guy for the library- Steven Cogswell
http://husks.wordpress.com/2011/05/23/a-minimal-arduino-library-for-processing-serial- commands/
Looks great
How is the Arduino when it comes to timekeeping? Could you make that into a clock with the color components representing the hour, minute and second hands? (perhaps using gradients, or solid bands; also perhaps sending the hands for a full turn on each of their respective ticks like on that Chronophage clock?)
Cool idea.
Shouldn’t be that hard by adding an RTC module to keep time (otherwise the arduino would loose time on every power off)
I’d also thought a cool clock could be made by using a servo to turn a mirror to split the beam of a laser for the ‘hands’ of the clock..
good work! Do you known if the fastSpi library allows you to set multiple pins when using WS2811. so could i have two different strips hooked up to do different pins? or does the library only allow you to set one pin?
thanks
…from the FastSPI website
“Also – important note for the tm1809 chipset. Unlike the other chipsets, the tm1809 chipset doesn’t make use of the SPI core. This means that you can use any of pin 0-13 to drive your leds! Use the FastSPI_LED.setPin(pin); method to set which pin you’re driving.”
I haven’t tested multiple strips on separate pins but this seems to indicate it’s a possibility.
so the ws2811 and the tm1809 chipsets have the same timings?
The setting
FastSPI_LED.setChipset(CFastSPI_LED::SPI_TM1809);
works for me so I’m assuming the timing is the same, not certain though.
-also there’s a good explanation of the differences between ws2801 and ws2811 here: http://forums.lightorama.com/index.php?/topic/22698-ws2801-vs-ws2811/
Hi,
I bought the item:
http://www.ebay.com/itm/5m-60-LED-m-RGB-LED-Light-Strip-5V-WS2811-WS2801-Waterproof-Addressable-Color-/150931961150
but i could not run your code in arduino nano. It was necessary to change the library fastspi?
Tks,
Rodolfo (Brazil)
The ad lists these as WS2811 (WS2801), which is weird as these require different params in FastSPI. I did have a little trouble with the FastSPI library with the ws2801 at first but a patched build fixed the issue. I had no problems with WS2811 when I used the settings for tm1809 in Fast SPI.
FYI I’ve tested this on Due and Nano.
Let me know how it goes.
I’m not getting this serial stuff…
What do I write in the serial monitor to change mode?
Crap…I cannot for the life of me figure out how to input serial commands. It just sits there with SETUP COMPLETE and does not respond to anything I put in.
Are you using the Arduino IDE for serial?
If you see ‘SETUP COMPLETE’ then your receiving serial messages.
Try loading an example sketch that echo’s the serial input and see if your input is working.
Something like -http://arduino.cc/en/Tutorial/ASCIITable is good start.
Got it working. Not quite sure if it was my terminal program or what, but it works now. Thanks. One other question. I am using the WS2801 in 5m strips with 160 totals LEDs. It will only works up to 156 LEDs and when I go above that point it never gets through the setup loop and just hangs any ideas? I have tested up to 320 LEDs with the FastSPI_LED library and it seems to work great so I don’t think that the library itself is the problem.
It chokes on this function:
void copy_led_array(){
for(int i = 0; i < NUM_LEDS; i++ ) {
ledsX[i][0] = leds[i].r;
ledsX[i][1] = leds[i].g;
ledsX[i][2] = leds[i].b;
}
}
Its possible you are out of memory. Update size below with you SRAM available for the chip you are using. Those two data structures you have there look to take up about 1k and depending on the efficiency of your code, you could be above the amount of storage you have available.
int availableMemory()
{
int size = 2047;
byte *buf;
while ((buf = (byte *) malloc(–size)) == NULL);
free(buf);
return size;
}
I’m stupid and was putting , between the m and the mode.
nah, not stupid at all.
Actually I was thinking of switching to comma delimited
Hi, took a risk I would be able to get this strip to work (newbie to arduino) and thanks to your code and a bit of googling on the pins its working like a treat! Much appreciated. I just stuck 12V and GND onto the strip and then connected Pin 3 off the Arduino Due to DI and it just plain worked! Now to understand why
John
Right on, glad it worked!
but what strip are you using? if it’s ws2801/2811 they’re 5V. I would think 12V would be bright but brief ;-{
you can run about 30 LED’s from the arduino’s 5V, past that you should use another supply probably.
Have fun!
The WS2811 strips are available with the chip Integrated into the LED, have you got this to work with this variant?
Yup, those are WS2811 in the video, says so in the post.
They work with the config settings for TM1809 chips.
Hello,
Thanks for the awesome post!
How would I go about using this with ws2801 strips? What pins connect to what wires?
The two links below can replace the broken one in the article.
https://github.com/scogswell/ArduinoSerialCommand
http://awtfy.com/2011/05/23/a-minimal-arduino-library-for-processing-serial-commands/
WS2801 use SPI to connect CLOCK-13 and DATA-11
Thanks for the links!
Hi all,
and your code really hits a dry spot – thanks.
on a steep learning curve here
I am wondering tho’ – why use TM1809 settings when the lib supports WS2811 (you just have to edit the setting string)?
Hi Soren.
It seems that the TM1809 and the WS2811 shares the same settings.
If you look in the library header file: FastSPI_LED.h:
enum EChipSet {
SPI_595 = 0×01,
SPI_HL1606 = 0×02,
SPI_LPD6803 = 0×04,
SPI_WS2801 = 0×08,
SPI_TM1809 = 0×10,
SPI_WS2811 = 0×10,
SPI_TM1804 = 0×10,
SPI_LPD8806 = 0×20,
SPI_UCS1903 = 0×40,
SPI_SM16716 = 0×80
};
you’ll see that both types are initialized with 0×10.
[...] And here’s a blog post describing their use. [...]
Hey
I tested your Code with an Arduino Pro Micro (Leonardo). It was hard to get the right Pin. With the actual Libary, its working.
One thing: If u want to switch Modes, u have to boot the Arduino with Mode 0 (int ledMode = 0;), not in Demomode. In Demo Mode, u cant put in some, the Arduino is not responding to your Input. So switch to Mode 0 at Start, connect with Serial – and it works.
So for all, where the serial command not work ^^
Is it possible, to switch the Modes with a PPM SIgnal, instead of serial?
Want to use it with my RC Plane and switch the Modes with my Radio Control (Graupner MX-20).
Yeah, in some modes it has to finish the loop before it processes the next command.
About the PPM I’m sure there’s a way, found this library but not sure what wiring would be involved.
https://github.com/kiuz/PPM-Signal-Reader-ARDUINO
What was your setup on the Leonardo? I haven’t gotten it working.
I haven’t tested it on the Leonardo.
I got it working. I connected to pin 16 on the Leo (MOSI, on ICSP header) and set to pin 16 in code. worked fine. I’d previously tried PWM pins, without success. I tested on a LeOlympia, not Leonardo, but for this use they are the same.
Great news! Glad it worked for you!
[...] Going to try this guy's code, he seems happy and lots of google searching proves it should work: http://funkboxing.com/wordpress/?p=1366 As for your helmet, wow sorry it won't fit. You could sell it as is with the working LEDs for an [...]
Thanks a lot for that article, I’m enjoying the sample code and driving about 140 pixels on my arduino(I have a 60 led/m 4m strip that I bought in china for cheap). More and I run out of memory and/or power (5V 3A).
Looking forward to doing my project, the “bounce” function will prove very useful.
For those who might be reading and looking how to use the mode switcher, open serial (make sure to select something for a line end) and type for example: “m 4″ *Enter*. (separate m and the mode with a space)
Hi, thanks for sharing your great work. I wonder if there is much that must be changed to last FastSPI_LED2 to work?
Thanks
Not sure- I’ll have to do some testing to see what I have to do to get it running the new lib.
It would be very appreciated, thanks.
Tape S2801 connects to Arduino to pin 11 and 13. Sketch does not work. Please tell me which lines in the sketch should be changed and how? Here’s the problem -
#define PIN 3
//#define PIN 4
?
Line 42 of the sketch should be changed to “What do you get if you multiply six by nine?”
This will answer all your questions.
Great info here. I’m fairly rusty using c and am having a bit of trouble getting this to compile.
I’ve dropped the include files from above in the hardware\arduino\cores\arduino folder but still get erros when tryhing to verify the code. I am getting these errors :
FastSPI_Demo.cpp.o: In function `__static_initialization_and_destruction_0′:
C:\arduino-1.0.4/FastSPI_Demo.ino:45: undefined reference to `SerialCommand::SerialCommand()’
FastSPI_Demo.cpp.o: In function `pacman(int)’:
C:\arduino-1.0.4/FastSPI_Demo.ino:755: undefined reference to `FastSPI_LED’
C:\arduino-1.0.4/FastSPI_Demo.ino:755: undefined reference to `FastSPI_LED’
C:\arduino-1.0.4/FastSPI_Demo.ino:755: undefined reference to `CFastSPI_LED::show()’
I’m certain it’s me doing something silly here, but I can’t get any further. Anybody got an pointers please ?
Thanks
Phil
Looks like it’s not finding the SerialCommand and FastSPI libs
I believe the includes should be placed in the sketchbook folder in /libraries. Try that and let me know what happens.
I worked this bit out. I didn’t put the .cpp files in there as well, just the.h files…. Anyway, it compiles and uploads, says Setup Complete, but doesn’t do anything else. Adding serial print lines shows the code is looping, but nothing lights up. I have a 60 led 1m WS2811 strip.
A shame, as I am hopefully going to build a fancy clock.
I read somewhere there is problems with the timing on these strips, do you know anything about that ?
Just a few thoughts
- what arduino board are you using?
- do you have the code set to use TM1809?
- is your data pin on a PWM capable pin?
- also try playing with setDataRate() 0-7
- have you tested the strip another way to see if it is functional?
Thanks for your help up to now.
As said, I’m VERY rusty on C code having been used to the pleasantries of VB and C#.net in recent years
I’m using an UNO with the same settings as your code above, so yes, it’s using TM1809 and Pin 3.
I tried a couple of different values (0,3, & 7) but still got no output. I’ll try them all tonight.
It’s responding to the set mode command, so the sketch is running fine,
The power is coming from the Arduino board via the USB, so I’m only trying the first 5 LEDS.
I tried a new sketch with the bare essentials of you code in them, but I have now tried any other code to try to see if it works. Can you point the way to a simple, drop-upload-test code I could use ?
Many thanks for you help so far, I appreciate it.
You could try a demo sketch from the FastSPI library.
Another thought- are you certain these are 5V, not 12V strips? I’ve heard of there being 12V WS2811 out there.
None of the demo sketches work.
I’ve tried the fastSPI, the new V2 FastSPI, the Adafruit NeoPixel and the code from Alan Burlison. None of them work.
The strip itself has 5v written on it. I tried nudging the voltage up and some of the leds came on, but not being driven by the UNO.
I guess I must have just got a faulty strip, or just be plain unlucky.
It came fro mthe US, as I can;t get them in the UK yet, so it will cost too much to send it back for a refund. Maybe I can strip it down for another project later.
Looks like I’ll have to go back to discrete LED and 595′s. Bummer…
Thanks anyway
Hi, just a little update.
I bit the bullet and ordered another ws2811 led strip. This one worked fine on my UNO.
So I guess the first one was broken.
Thanks for your help and your code.
Excellent, glad you got it working and thanks for the update, now I know it works with UNO also.
Sorry about the bad strip
OK. Thanks for you help anyway.
This strip works fine, but the LED seems to be inverted. i.e. RGB 0,0,0 is white, RGB 255,255,255 is off.
Your Police Lights, for example, are Yellow and Cyan, so the RED and BLUE switched off !!
Strange
Least I get light from it.
I’m trying to work ok the code to invert it all, rather than each call.
Yes, the RGB sequence seems to be different in every strip I get.
This is the line you’ll need to adjust.
//-YOU MAY HAVE TO PLAY WITH THE R,G,B ORDER OF THIS TO SUIT YOUR STRIP
struct CRGB { unsigned char g; unsigned char r; unsigned char b; };
//struct CRGB { unsigned char r; unsigned char b; unsigned char g; };
//struct CRGB { unsigned char b; unsigned char g; unsigned char r; };
The RGB order was correct, but I had been playing around with the timings in the fastspi.h file when trying to get the old strip working.
I had inverted the nop_short and nop_long values. That made the colours inverted.
Once put back, then everything is working great.
Thanks again.
Right on, glad to hear it’s working finally!
Just wanted to say thanks for sharing.
Your code worked straight out of the download folder
Nice effects!
How do I wire the LED strip to the Arduino ?
Can you point me to a circuit diagram ?
I have a Nano V3.0
Thanks, Geeorg
Depends on the strip. Whatcha got?
WS2811 LED digital strip from Aliexpress.
Arduino Nano V3.0
Can I wire the pixels data-in directly to the Arduino (what pin) or do I need a buffer or something in between ?
Georg
Found it ! Data in goes to D3.
Demo works fine.
Thank you for your code.
Georg