Pages: 1 [2]   Go Down
Author Topic: Simplifying control of LED 2801 square pixel  (Read 3475 times)
0 Members and 1 Guest are viewing this topic.
Colorado
Offline Offline
Edison Member
*
Karma: 47
Posts: 1562
Reviving dead brain cells with Arduinos.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh yeah, in your sample code, any loop after the first one will not run because you've set 'done' to 1 in the first one.  So the second loop, when it checks whether done = 0 and finds it false, it skips the loop and moves on.  This is what I mean with, if you're setting everything in one shot, you can encapsulate the whole series of loops with one break.  If that's even necessary.  Not knowing how you plan on implementing it, I don't really know what would work here.
Logged

Hamburg
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there,

Is there a specific reason for why FastSPI_LED.h is recommended for this task rather than SPI.h? There will be 80 LEDs in total.

Thanks
Logged

Colorado
Offline Offline
Edison Member
*
Karma: 47
Posts: 1562
Reviving dead brain cells with Arduinos.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The SPI library is exactly that, a library to control the SPI functions on an Atmel.  The FastSPI_LED however is a library written to control a bunch of different types of LED drivers, including the WS2801.  So, if you only use the SPI library, you still have to write the various functions needed to control those LED drivers.  Whereas with FastSPI_LED, it's already done for you.  You just call the necessary functions.
Logged

Hamburg
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi KirAsh4,

Thanks for your feedback. I now have the FastSPI doing what I want it too - hurray! The following step was to add Ethernet functionality so it's now calling a variable PHP file on a web server. As soon as that was added, we're getting 'disco lights' on the LEDs – specifically when it's connecting via the ethernet. Once the code is triggered the lights behave correctly, then go back to disco lights when its finished. This didn't happen when we're using the regular SPI but something on FastSPI sets it off. Is this a common problem that can be worked around? We're using an Arduino Ethernet so I'm wondering if there's a PIN conflict on the default 11 and 13... Could that be? Best
Logged

Colorado
Offline Offline
Edison Member
*
Karma: 47
Posts: 1562
Reviving dead brain cells with Arduinos.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That is because the ethernet add-on that you're using is more than likely also using the SPI bus.  And since the  LED drivers don't have a select pin, just about anything that goes over the SPI bus will in some way or another mess with the LEDs.  That's exactly what you're seeing.  You have two options:

a) don't use FastSPI.  Use bit-banging instead on two completely different pins, which will leave the SPI open for other devices, or
b) use a gate to control the LEDs, and you can still use FastSPI.  It gets a bit trickier, but it can be done.

For my own project last year, I went the bit-bang route.  I only had two strings of 20 LEDs each.  I used the analog pins (of all things) to control the strings, A0 and A1 for one, and A2 and A3 for the other.  Then I had an RF module on the SPI bus.

Note: bit banging IS slower than SPI, so depending on how fast you plan on sending data to the LEDs, bit-banging them may not work for you.  For me it was plenty fast still.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've gotten some great info from this topic, (and others) so I hope its okay that I necroposted. I'm starting down this path myself. Following all the great tips I can control my LEDS individually (mostly) using fastspi, but in seeing the last few posts I know I'm running up against my next obstacle soon smiley-grin

That is because the ethernet add-on that you're using is more than likely also using the SPI bus.  

.......

For my own project last year, I went the bit-bang route.  I only had two strings of 20 LEDs each.  I used the analog pins (of all things) to control the strings, A0 and A1 for one, and A2 and A3 for the other.  
Note: bit banging IS slower than SPI, so depending on how fast you plan on sending data to the LEDs, bit-banging them may not work for you.  For me it was plenty fast still.

Could you go into a bit more detail about bitbanging these pixels? Like most people, I'd like to write a function that will do most of the lifting and let me do changeLED(LED[1],'blue'); Since I'll be using the standard Ethernet shield on 13, I'll need a way to go without fastSPI. I'm hoping my project will accept http requests to turn a pixel a certain color, and then another digital out to set of an alarm (when a project needs attention) So I dont think it needs to be fast, the colors wont change rapidly and will stay solid lit.

Should I just look at a basic spi library? https://github.com/adafruit/Adafruit-WS2801-Library/blob/master/examples/strandtest/strandtest.pde I'm at work and cant check that out, but it seems close to what I'll need. I don't have the adafruit string, but I assume most 2801 will be similar

You also said
Just set everything to white first (you don't need an array for that), then cycle through the BlueLEDgroup array and turn those blue.  When you're done with that, then you can call FastSPI_LED.show() which will turn the LEDs on.
Even though I'll be moving off fastspi after your advice, I'm curious what the single command is to set the whole string white smiley

Thanks!
« Last Edit: March 08, 2013, 09:21:39 am by AceoStar » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For those who end up here for info some day, yes, if you want an easy way to control a ws2801 string download the adafruit library,  https://github.com/adafruit/Adafruit-WS2801-Library/blob/master/examples/strandtest/strandtest.pde run the example and easily pick up on how to control each individual LED.   This allows you to still use the standard ethernet shield for control.

Use the following to light up the pixel of your choice
Code:
      strip.setPixelColor(21,Color(0, 0, 255));
« Last Edit: March 09, 2013, 06:11:44 pm by AceoStar » Logged

Colorado
Offline Offline
Edison Member
*
Karma: 47
Posts: 1562
Reviving dead brain cells with Arduinos.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That Adafruit library is a good start for bit-banging SPI on different pins.  There are ways to make both the LED string as well as another shield that requires the same SPI pins to work together, but you would have to add additional circuitry to isolate the string every time you need to access the shield.  Bit banging is easier, though a tad slower.
Logged

Hamburg
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So my project has progressed following the previous help you offered, particularly electronically. There's one sticking point I can't figure out that I'd very much appreciate a suggestion on. I can't work out how to make a function look up the values of the pixel arrays using the variable 'personsname'. The following code is a very stripped back version to highlight the exact problem area...

Code:
#include "SPI.h"
#include "Adafruit_WS2801.h"


//DEFINE OUTPUT PINS
int dataPin  = 2; //Yellow wire
int clockPin = 3; //Green wire

//SET NUMBER OF PIXELS
Adafruit_WS2801 strip = Adafruit_WS2801(20, dataPin, clockPin);

//PIXEL ARRAYS
byte Pete[] = { 0, 19, 43, 63};
byte Stephen[] = { 25, 32, 37, 59, 60, 63, 71};
byte Jack[] = { 20, 59, 61, 68};



//SETUP
void setup(){
  strip.begin();
  strip.show();
  Serial.begin(9600);
}

//CHECK & UPDATE LOOP
void loop(){
  
      colorFade(Color(0, 0, 255), "Pete");
    }
    delay(10000); //wait 10 seconds before connecting again
  }




// MAIN FUNCTIONS

//Fade to color
void colorFade(uint32_t c, char* personsname) {
  int i, j;
  for (c=0; c < 256; c++) {
    for (i=0; i < sizeof(personsname); i++) { //Can't get this to work. I can't figure out how to make the function look up the values of the pixel array using the variable 'personsname'. It works if a name is entered directly instead of "personsname", e.g. "Jack" will light up the correct LEDs.
      strip.setPixelColor(personsname[i], c); //Same here.
    }  
    strip.show();   // write all the pixels out
    delay(50);
    Serial.print("Fade In: ");Serial.print(personsname);Serial.println("");
  }
}

Any tips gratefully received. Thanks
Logged

US
Offline Offline
Newbie
*
Karma: 2
Posts: 35
Hi! I wrote and maintain the FastSPI_LED library. Working on trying to keep it up to date.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The most recent major revision of the FastSPI library will let you use arbitrary pins - and does very high performance bit-banging (faster than just about any other library i've seen out there) when you aren't using the SPI ports.  The next version preview release is documented here - http://waitingforbigo.com - and i'm hoping to put up another rev of the library shortly with some more chipsets and refining (I'm shaking out some of the new API pieces by feedback from people using it).

In addition the new library will let you use multiple strips on different pins (and even mix and match the types of strips) and no longer compiles in code for strips that you aren't using, saving you much more program flash memory as well.
Logged

--

FastLED (formerly FastSPI_LED) -- new home http://fastled.io

Pages: 1 [2]   Go Up
Jump to: