Arduino Forum

Using Arduino => LEDs and Multiplexing => Topic started by: V1x0r on Dec 15, 2013, 05:37 am

Title: Dynamically determine length of WS2812B LED strands
Post by: V1x0r on Dec 15, 2013, 05:37 am
hey guys!  I'm a huge fan of these forums and I have been searching for a few days here (and other places) and have not been able to find what i'm looking or.  :(   

I have purchased a couple of these for experimenting and getting ideas http://www.aliexpress.com/item/3-Key-Mini-Controller-For-Test-WS2811-WS2812-WS2812B-Pixel-LED-Strip-Light-DC5V/1498586246.html (http://www.aliexpress.com/item/3-Key-Mini-Controller-For-Test-WS2811-WS2812-WS2812B-Pixel-LED-Strip-Light-DC5V/1498586246.html)  and I'm trying to figure out how they have been able to determine the length of the strand.   I have many of these light strands (ws2812B).  And when connected to the device a 1meter strand will function the same way as a 5meter strand.  Not just for rainbow affects but  a chasing led affect.  (Sends 2 pixels down the strand until the end is reached then starts over, as well as another which sends a few pixels (more on the larger strand so clearly math is used for this function) to the end with a faded tail until the end is reached, then it starts over again.   

My only assumption is that due to the fact that the device is designed to run only so many leds that it is checking after each pixel color is set if that pixel actually has a color.  if there is no pixel then it returns a false/null type statement thus restarting the affect in the next color.   The adafruit library does this...are there others?


Also, is there a repository for many light affects?  I really like the water torture affect, but everywhere I go it's in java script.  no c++  :(   

Anyway, thanks in advance everyone!!!! 
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: fungus on Dec 15, 2013, 10:07 am
There's no way to tell how many LEDs are connected. You change the effects by editing the program to match the strip.

A repository for many light affects? Try your imagination...
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: Paul__B on Dec 15, 2013, 01:19 pm
Presumably you could loop the shift output from the end of the chain back to the controller and examine the codes received, but considering how tricky it is merely to transmit the codes in the first place, this would be quite a challenge.
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: fungus on Dec 15, 2013, 02:03 pm

Presumably you could loop the shift output from the end of the chain back to the controller and examine the codes received, but considering how tricky it is merely to transmit the codes in the first place, this would be quite a challenge.


Hmmm...I guess that might work. When you see data coming out of the last LED you know you've reached the end of the strip.
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: V1x0r on Dec 15, 2013, 09:40 pm
So, i've tested the getpixelcolor method using this
Code: [Select]
#include <Adafruit_NeoPixel.h>
#define PIN 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(100, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  Serial.begin(115200);
  Serial.println("First_Color");
  Serial.println(strip.getPixelColor(60));
}

void loop() {
  // Some example procedures showing how to display to the pixels:
  colorWipe(strip.Color(255, 0, 0), 50); // Red
  Serial.println("Pixel 1");
  Serial.println(strip.getPixelColor(1));
  Serial.println("pixel 44");
  Serial.println(strip.getPixelColor(44));
  Serial.println("pixel 60");
  Serial.println(strip.getPixelColor(60));
  Serial.println("pixel 120");
  Serial.println(strip.getPixelColor(120));
}

// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
  }
}


but all that did was give me the logic that was supposed to go to that pixel.  not read what was actually in that pixel.  I'll have to test Octows2811's library as it has a similar function.  Maybe it runs it differently.

Quote
There's no way to tell how many LEDs are connected. You change the effects by editing the program to match the strip.


My controllers say differently my friend.  as a 1m strip will function the same as a 5m strip which would require being able to determine the number of functioning LEDs.   I'm assuming the method is relatively old as these controllers (though really new) were designed for compatibility with the ws2811 hardware. 

Quote
A repository for many light affects? Try your imagination...


This is backwards support.  I'm currently building a repository of collected and homemade affects.  I'm at just over 30 affects currently (and growing).  Which isn't very many I know, but will be nice to be able to share them with people.  I just didn't want to rebuild something that had already been publicly built.  Instead I'd rather add or touch up what was already existent. 

Quote
Presumably you could loop the shift output from the end of the chain back to the controller and examine the codes received, but considering how tricky it is merely to transmit the codes in the first place, this would be quite a challenge.


That does sound very helpful!    hrmmmmm...I wonder how one would best go about doing this.   I'm learning a lot about these lights...they are very impressive!  :)

Thank you everyone for the help and support on this.  I look forward to reading more as it comes.  ^_^
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: fungus on Dec 16, 2013, 10:52 am

Quote
There's no way to tell how many LEDs are connected. You change the effects by editing the program to match the strip.


My controllers say differently my friend.  as a 1m strip will function the same as a 5m strip which would require being able to determine the number of functioning LEDs.   I'm assuming the method is relatively old as these controllers (though really new) were designed for compatibility with the ws2811 hardware.  


Are both ends of the strip connected to the controller?

I can send 5m of data to a 1m strip, no problem. It will simply display 1/5 of the pattern.
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: V1x0r on Dec 16, 2013, 05:05 pm
It is connected to a single end.  This device can send  (for instance) a few leds down the strand and cycle right after it reaches the end.  your example would have a pause if you wrote it for 150leds.  This device does not have a pause.  it starts over right after it reaches the end of the strand.  with 30 leds, or with 150 leds. 
It IS dynamically determining the length of the strip.  Whether it is a check before executing light affects or during.  I'm more curious how to replicate this.  a cheap unit can do it effectively as well as with additional modes, speed transitions, etc.  I've tested this repeatedly on my strands and it is impressive.   I'm trying to talk the manufacturer out of the source code but I doubt I'll get it.    So far I can get them to build a custom device for me at least if I supply them my stuff. 
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: fungus on Dec 16, 2013, 05:52 pm

It is connected to a single end.  This device can send  (for instance) a few leds down the strand and cycle right after it reaches the end. 


Maybe it monitors the current draw. Does the 5V power go through the device?

Title: Re: Dynamically determine length of WS2812B LED strands
Post by: jasmine2501 on Dec 16, 2013, 07:14 pm

It is connected to a single end.  This device can send  (for instance) a few leds down the strand and cycle right after it reaches the end.  your example would have a pause if you wrote it for 150leds.  This device does not have a pause.  it starts over right after it reaches the end of the strand.  with 30 leds, or with 150 leds. 
It IS dynamically determining the length of the strip.  Whether it is a check before executing light affects or during.  I'm more curious how to replicate this.  a cheap unit can do it effectively as well as with additional modes, speed transitions, etc.  I've tested this repeatedly on my strands and it is impressive.   I'm trying to talk the manufacturer out of the source code but I doubt I'll get it.    So far I can get them to build a custom device for me at least if I supply them my stuff. 


Put it in debug mode and run it and check the loops yourself. It it probably sending 5 meters worth of data regardless of what is connected. The patterns will still look the same - you're just viewing a "window" on the whole pattern when you have less lights.

Post the code, maybe I can explain it. I've worked with these quite a bit. There is no repository of effects because most of them are visually obvious what it's doing, but I've posted a couple effects on Github.
https://github.com/jasmine2501/LedStripSimple
(There was a few more codes up there, Github isn't playing nice, I'll see if I can get them back up there.)
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: V1x0r on Dec 16, 2013, 09:50 pm

Maybe it monitors the current draw. Does the 5V power go through the device?


That's what I was thinking at first too.  it is on a 5v circuit.  But how would it know it's at the strand?  i've monitored  voltage draw with my own setup so as to determine how large of a battery pack will be needed to run the needed amount of hours and unless it's on a change affect it stays pretty stable on the draw.  Which makes sense...unless it is sending through a very large strand it shouldn't have any problem with voltage other than natural resistance from the components.  I haven't tested the octows2811 library yet, but it does give support for get led color...maybe it doesn't reference the code and instead references the colors actually on the chip.  :/  

@Jasmin - Thank you for your suggestion.  the problem is with trying to reverse engineer someone else's code based on how it appears to function.     i.e.  Sending 2 pixels of color to the end of the strip, and as soon as it reaches the end it starts over again with a very very short cycle to the beginning (almost instantly).   This is true for 30leds to 180 leds.  150 led difference on a slow line send would have a very long wait before recycling the lights again.  
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: jasmine2501 on Dec 16, 2013, 10:20 pm
Quote

@Jasmin - Thank you for your suggestion.  the problem is with trying to reverse engineer someone else's code based on how it appears to function.     i.e.  Sending 2 pixels of color to the end of the strip, and as soon as it reaches the end it starts over again with a very very short cycle to the beginning (almost instantly).   This is true for 30leds to 180 leds.  150 led difference on a slow line send would have a very long wait before recycling the lights again.  


That isn't how it works. When you send data to the line of WS2812s (or TM1803s) you are sending a complete data packet with a space, then an "EOF" signal. The chips don't reset the LEDs to a new color until they see the "EOF" signal. It's not like a chip holds a color and then passes it to the next one on the next refresh. You have to refresh ALL the LEDs EVERY TIME.

So, here's how it works - lets say you have 10 WS2812s on a line...
You can send 10 RGB colors down that line - the WS2812s will eat each color in sequence, color0 will go to chip0, color1 goes to chip1, etc... then you send the EOF signal, and at that point, is when the WS2812s will light up with the colors you just sent.

You can send 20 colors down the line - 10 WS2812s will eat the first 10 colors, and the last 10 colors will be sent "to nowhere" because there's nobody connected to the last chip. It will begin passing data after 10 colors arrive, but that data won't go anywhere.

You can send 5 colors down the line - the first 5 WS2812s will light up, and the last 5 will NOT - they will never see anything.


So, in the case you're describing, where you have 1 meter of lights and 5 meters of data, it's just ignoring 4 meters worth of data, and going slower than it needs to. That is just how the WS2812 works, and there isn't any way to check how many are connected. Look at the data sheet... it explains the 50us "frame sync" and everything.

http://www.adafruit.com/datasheets/WS2812.pdf

And yes, it does have a "data out" pin - but that pin doesn't do anything but pass the data through, after the chip receives 24 bits. Each chip on the line does that - it eats 24 bits and passes everything else along the line, waiting for the EOF signal.
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: Grumpy_Mike on Dec 17, 2013, 04:54 am
I think what V1x0r is saying is that he has a strip of 10 LEDs where just the first led is lit. That lit LED is the "moved" to the second position after a second. This repeats until the lit LED reaches the 10th position and after a one second gap that lit LED appears on the first position again.
Now with the same code you attach a 20 LED strip on it. This time the lit LED goes all the way to the 20th position before coming back to the start.

Myself I think V1x0r is wrong but that is what he appears to be saying.
He does say:-
Quote
i've monitored  voltage draw with my own setup

now there is no such thing as a voltage draw, only a current draw which gives some room to some doubt him / her.
@V1x0r - is this a true reflection as to what you are saying? If so can you post the code that does this please.
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: jasmine2501 on Dec 17, 2013, 06:06 am

I think what V1x0r is saying is that he has a strip of 10 LEDs where just the first led is lit. That lit LED is the "moved" to the second position after a second. This repeats until the lit LED reaches the 10th position and after a one second gap that lit LED appears on the first position again.
Now with the same code you attach a 20 LED strip on it. This time the lit LED goes all the way to the 20th position before coming back to the start.


Yeah I know, that's a chasing effect... you do need to know how many LEDs are on the string if you don't want there to be a delay between the last one and the re-start. If he has a controller where you can have that kind of chasing effect (where all the lights are unique) and it will "fix" the sequence when you just chop off the end of the LED strip, then I really would love to see the code, and the wiring on it. As far as I know, there is no way to determine how many LEDs are on the strip, unless you bring the last data line back in to the controller. THEN, you could listen, just as the WS2812 does, to see when you start to see bits, because that pin would see nothing until you sent enough bits for all the WS2812s on the line. But, that would require re-wiring if you wanted to change the length of the string.

To do a chasing effect, lets say you could turn LEDs on and off with one bit instead of 24... this is what you would do...

1000000000
0100000000
0010000000
0001000000
etc...

So, if you change the number of lights, you have to change the number of blocks of data you send out with each frame. Rainbow chasing effects are visually confusing and it may appear fine when you cut things short even if you aren't seeing the whole pattern.

Oh BTW, you can't measure the current draw and do some kind of calculation because the different colors are produced by sending different current amounts to each LED. I suppose you could be sure if you lighted up the whole strand with full strength white, then each WS2812 should draw 60mA, but I don't know how accurate that would be.

Quote


@V1x0r - is this a true reflection as to what you are saying? If so can you post the code that does this please.



I don't think it's easy to pull the code off the product he's using. A lot of companies sell products like it though, and there is plenty of code for it out there. One company that sells them has code here...

https://github.com/pololu/pololu-led-strip-arduino

But, that's just the library to drive it, you still need to write code. I show how it all works in this video... (It's about the TM1803 but they work the same)

http://www.youtube.com/watch?v=h_GXhJeCDD0
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: V1x0r on Dec 17, 2013, 11:07 pm
I did mean current draw, my apologies.  I'm measuring overall wattage.  Suffice it to say I was pretty tired when I wrote my last posting.
I also understand how the lighting is sent through each led on the strand.
I'm going to flat out say that you are wrong.  The device is determining the length of the strand.  It is not using the poorly written Pololu library.  (my opinion on the library).  I am very impressed with how this device functions.  You are used to having to put code down to define length.  This is (in my opinion) bad form overall.  Being able to determine the length logically is very impressive to me.  And the lighting affect and outcome that grumpy mike stated is correct.  If you do a very basic "Chasing" affect illuminating two leds at a time down the strip until the final end is reached and then start back at the beginning of the strip immediately after completion then you have the general idea of what this does.  YOU and I have to write down the number of LEDs for this affect to work properly between different sizes of strips.  THIS device that I originally posted DOESN'T do that as the effect is exactly the same without delay between the different sizes.  If you would like I can post a youtube video to prove my point.
I may be relatively new to the addressable LED side of things, but in regards to electronics and coding I am FAR from new.  I understand these forums are usually started by novices in all fields but please do give understand and respect to the fact that I am not a complete fool.  Clearly you all are just as confused as how this would function as I am.  I greatly appreciate the support when support is given, but I do not care to be spoken down to because you assume I am wrong because I must be new.    Thank you again for your time on this and I do hope we can go further on this as it clearly would be beneficial for all of us to know how this works as a hobbyist.  I am tempted to pull the code from the chips themselves as they are essentially an attiny25 or 45 for the smaller device.  Problem is converting from machine code to understandable code. 

Something else to consider, is that these were likely designed with a different avr designer not using the standard libraries available to arduino users.  so a custom library would likely have been used for this.  something liked Edit2012/ Edit2013 could have been used also.    As for the LEDs holding the light color...take two arduinos.  externally power your led strip, (ws2811 ic based, so ws2811, ws2812, and ws2812B) and connect the grounds between the two arduinos and the lighting strip as well as the power source (which should be the same connection to your led strip), usb power your arduinos....one arduino send a color light segment to your strip...varying colors and so forth), disconnect your data pin from arduino 1 and connect it to arduino 2..on arduino 2 have a get color code (ONLY GET COLOR) code...and see what data you get back from your leds.    I do want to try this myself personally...I have a few arduino's at home (one is devoted to being an ISP for attiny but can still use to check)...if the second arduino receives information from the leds that the first arduino sent then that would make sense why my RF version of this adapter has two microcontrollers connected in parallel.  I thought it was for double the code...but the second could be a check segment...I still think parallel'd for double the code.

Anyway...thanks again everyone.  ^_^  @Fungus...where are you?  you know more than any of us do on here.  :)
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: jasmine2501 on Dec 18, 2013, 01:57 am
I'm sorry but I'm not confused, I know how the WS2812 operates. I also know how that strip is wired up, but I am not sure about the connections to the controller. If it has a return data line, it could easily count the LEDs, and I can now think of a couple ways to calculate it or figure it out by measuring the current draw. The thing is, you can not send the same data to a different length of lights. You must adjust the number of bits you send in the frame before the refresh, or you will either fail to light up all the lights, or you will light up extra lights that don't exist. That why I chose to enter this discussion, because I think it's a very good question. The thing is, if we can't see the code or the wiring, we can't know what method your controller might be using. And, I apologize and realize it isn't helpful to tell you the ways it won't work. So, here's how it could work...

I can suggest a way to sort of quickly measure the length of the strand by current measurements. Simply send zeros down the line until you get to the 500th light, then send 24 ones to make a full white display. If you detect no current, try again with 499 - eventually you will get to the point where you light up exactly one light at the end of the strand, your current sensor will be non-zero, and you will know that's the last one. I suppose you could do that dynamically during the effect as well.

OH BTW... you found this, right?
https://github.com/DannyHavenith/ws2811/blob/master/src/water_torture.hpp

Title: Re: Dynamically determine length of WS2812B LED strands
Post by: jasmine2501 on Dec 18, 2013, 02:22 am
Maybe this will help. I am actually working on something with this stuff right now so I had it in Fritzing anyway. This image is a little confusing but it's basically what you describe, with a second controller at the end of the data line. In this example, there's only one WS2812, and its "Dout" pin is connected by the highlighted wire to the digital pin on the controller on the right. Data comes from the controller on the left.

(http://farm6.staticflickr.com/5504/11427599796_830f808441_o.png)

What will happen here is, if you send 24 bits and then the EOF signal, the Arduino on the right will never see anything. The line will remain low the whole time. If you send 48 bits, enough data for two lights, the WS2812 eats the first 24 bits while leaving "Dout" low, then when it sees the 25th bit it passes that bit to the Arduino in our case, in most cases, to the next WS2812. So, we could send 24 bits for a test, get nothing, try 48 bits, see data, and know we only have one WS2812. The important thing to remember is that each WS2812 sees nothing until the previous chip has seen 24 bits of data. Once it sees 24 bits, it passes all the subsequent data on the "Dout" line.
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: V1x0r on Dec 18, 2013, 03:19 am
I must apologize...that small adapter only does 50 light sequences.  so every 50 lights it runs the same code.  however, it still functions the same where it will instantly adapt from the smaller 30 led strip and re-cycle the affect instantly upon reaching the end of the strand.  with the 5m strip it will restarts as soon as it reaches the 50th led on the strand OR the final led on the strand.  I say OR because on one of the settings it doesn't wait for the 50th light to be lit but instead it finishes once the final LED is lit.  naturally 5meters of this isn't 50 leds a meter, it is 30 a meter so the strip gets restarted much sooner.   The remote control version is the one that goes to the end completely.  (it is also advertised for more leds however).  I ordered another small inline adapter that has all the affects as the large remote adapter so I'm waiting for that to come in.  maybe it will do the same as the remote.  it is newer after all.  still, i'm very impressed with the fact that it knows once the end of the strip has been reach. 

your image is intriguing.  but it would require a loop of some form.  there is nothing attached at the end of the strand.  and only utilizes three pins. 
The attached image displays four pins, the two center pins are grounds.  I'm a bit upset that they scraped off the info of the chips, but the first chip is an atmel chip for the RF receiver.  the other two are essentially attiny components.  (not actually attiny...but essentially the same thing).
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: V1x0r on Dec 18, 2013, 03:40 am
The small remote looks like this.

Hopefully this site doesn't downgrade the image quality...if it did then the chip is

STC
15F104E
HAH388.A

Alibaba and ebay sells these like crazy
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: jasmine2501 on Dec 18, 2013, 06:02 am
I think a video of these effects might be helpful. I think maybe I can figure out what's going on. The adapter units seem to only have three wires, so I really don't think they are determining the length of the strand. It just doesn't seem possible.

In the image I posted, notice that there are four things connected to the WS2812 - power and ground, data in and data out... data in is connected to the left controller, data out to the right controller. This setup would work, and the right Arduino could see the data, except for the first 24 bits in each frame in this case. The LED strips would be the same circuit, but more WS2812s in between.
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: V1x0r on Dec 18, 2013, 06:36 am
I completely agree!!!  this does NOT seem possible.  which is why I posted on here.  this concept seemed dumbfounding to me. 

The leds maintain a memory though...if you are sending a signal to the leds then disconnect the signal they do not simply turn off.  they instead hold to the last bit of signal that they had before.  which means they have a value written to them temporarily.  and to pull this value only seems like the next logical thing one could do.  instead of a send request you create a get request.  as for forming this get request I wouldn't know how to build it.   but I would assume that the great minds of china have probably already figured this out...especially since they are the once who mass product these things. 

I will have to upload a video tomorrow of these affects.  I gave my a 1m strip and an arduino so he could play around with it (his code is absolutely beautiful compared to what i'm used to seeing.  it's much smaller and more capable.  I will definitely have to share his stuff when he is comfortable with me sharing it.    Anyway...I'll have to cut a strip a to show you what i mean.  :)  i'm off to bed now though.
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: arduinodlb on Dec 18, 2013, 06:48 am
At the end of the day, it's not magic. Not even Chinese magic.

WS2812B chips do not remember their state. If you eliminate the impossible, what remains must be the truth (paraphrased from Sherlock Holmes).

If what you are saying is true, and I understand it correctly, when you plug the leds back in the controller chip must re-send the LED data. It is a test setup, so it's plausible they may have done this.
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: V1x0r on Dec 18, 2013, 05:26 pm

At the end of the day, it's not magic. Not even Chinese magic.

WS2812B chips do not remember their state. If you eliminate the impossible, what remains must be the truth (paraphrased from Sherlock Holmes).

If what you are saying is true, and I understand it correctly, when you plug the leds back in the controller chip must re-send the LED data. It is a test setup, so it's plausible they may have done this.


^^  well said.  a test setup would make sense to check each led and verify if one exists.  I am impressed that they have done this, and being that each chip was setup to function a certain way I don't doubt that a return line is impossible from them.  I still have yet to test the octows2811 stuff yet...maybe that will help.  :/  I dunno.
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: jasmine2501 on Dec 18, 2013, 05:59 pm

^^  well said.  a test setup would make sense to check each led and verify if one exists.  I am impressed that they have done this, and being that each chip was setup to function a certain way I don't doubt that a return line is impossible from them.  I still have yet to test the octows2811 stuff yet...maybe that will help.  :/  I dunno.


Well that's what I'm basically saying to do. Yes, the WS2812 "remembers" whatever the last block of data was, but it can't send that back out again. It will hold that color forever though, until power cycles and then it forgets. I plan to take advantage of that to reduce the need to do updates, so my Arduino can handle some other stuff while it runs the lights. If the controller can measure the current draw even in a simple on/off way, it could easily run a test on the currently connected light strip - when you turn it on, is there any visible flashing or anything before it starts the pattern?

The only data that ever comes 'out' of a WS2812 is the 'extra' data that it passes on after it eats 24 bits for itself - that 'out' signal is just the input signal, re-transmitted - there is no logic on that line, just an amplifier. The WS2812 never transmits the color it lighted up with, it eats that and keeps it.

It makes sense that these don't have a 'read' function, because theoretically, you're the one who sent the data in the first place, and there's no other way to change the values unless you send them. It's not functional as any kind of input device, so there's no reason to read it. Since these are intended to be used in large arrays, the component itself must be cheap - so they aren't gonna add some redundant feature like "give me the numbers I just sent you" which would just increase the cost and nobody would use that feature - it would be hard to compete with other chips that don't have that feature and thus, are cheaper.

BTW - you said you didn't like Pololu library - can you say why and give me some links to better ones then? To me, it's a one-function library, how much better can it be?
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: V1x0r on Dec 18, 2013, 07:20 pm
http://waitingforbigo.com/  (http://waitingforbigo.com/) FastSpi2 is one of my favorites, along with https://github.com/adafruit/Adafruit_NeoPixel (https://github.com/adafruit/Adafruit_NeoPixel). 

I hope those are helpful and fun for you.  I haven't tested the recent additions of the Adafruit NeoPixel library yet but those should be pretty awesome!  faster pwm for multiple strips at once.  (for Teensy...but w/e)

as for being able to read...if you are sending the data as an array then you naturally wouldn't need to know the color of the strip.  unless your code tells the strips what to do more mathematically. 

Code: [Select]
#include "Adafruit_NeoPixel.h"
#include <avr/power.h>
#define PIN 6
#define NUM_PIXELS 45
#define HALF_PIXELS (NUM_PIXELS/2)

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_PIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
    if(F_CPU == 16000000) clock_prescale_set(clock_div_1);
    strip.begin();
    strip.show();
}

void loop() {int i = 0;
  int nexti = 0;
  int spacing = 3;
  int colorcount = 0;
   int color = 0x00FF00;
  while (1) {
   nexti++;
   if (nexti >= spacing) {
     nexti = 0;
   }
   int variance = 8;
   colorcount += variance;
   if (colorcount >= 253) {
     colorcount = 0;
   }
   int numlight = 1;
   while (i < NUM_PIXELS) {
     int tmpcolor = colorcount + ( numlight * variance);
     while (tmpcolor > 255) {
       tmpcolor -= 255;
     }
     color = colorWheel(tmpcolor);
   strip.setPixelColor(i, color); strip.show();
   i += spacing;
   numlight++;
   }
   delay (90);
   i = nexti;
  strip.setBrightness(0);
  strip.setBrightness(255);
  }
}

uint32_t colorWheel(byte WheelPos) {
  byte state = WheelPos / 21;
  switch(state) {
    case 0: return strip.Color(255, 0, 255 - ((((WheelPos % 21) + 1) * 6) + 127)); break;
    case 1: return strip.Color(255, ((WheelPos % 21) + 1) * 6, 0); break;
    case 2: return strip.Color(255, (((WheelPos % 21) + 1) * 6) + 127, 0); break;
    case 3: return strip.Color(255 - (((WheelPos % 21) + 1) * 6), 255, 0); break;
    case 4: return strip.Color(255 - (((WheelPos % 21) + 1) * 6) + 127, 255, 0); break;
    case 5: return strip.Color(0, 255, ((WheelPos % 21) + 1) * 6); break;
    case 6: return strip.Color(0, 255, (((WheelPos % 21) + 1) * 6) + 127); break;
    case 7: return strip.Color(0, 255 - (((WheelPos % 21) + 1) * 6), 255); break;
    case 8: return strip.Color(0, 255 - ((((WheelPos % 21) + 1) * 6) + 127), 255); break;
    case 9: return strip.Color(((WheelPos % 21) + 1) * 6, 0, 255); break;
    case 10: return strip.Color((((WheelPos % 21) + 1) * 6) + 127, 0, 255); break;
    case 11: return strip.Color(255, 0, 255 - (((WheelPos % 21) + 1) * 6)); break;
    default: break;
  }
}
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: V1x0r on Dec 18, 2013, 07:50 pm
That example is very choppy I know...it needs a faded appearance on the empty colors.  colorwheel is a pain to work with for that so I will probably just use rgb values.  :)
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: jasmine2501 on Dec 18, 2013, 07:56 pm
Yeah, this is the code for the GetPixelColor function... it's just reading an array. That seems to be what the library does - maintains an array of colors and pumps them out to the strip on request.

Code: [Select]

uint32_t Adafruit_NeoPixel::getPixelColor(uint16_t n) const {

 if(n < numLEDs) {
   uint16_t ofs = n * 3;
   return (uint32_t)(pixels[ofs + 2]) |
#ifdef NEO_RGB
     (((type & NEO_COLMASK) == NEO_GRB) ?
#endif
   ((uint32_t)(pixels[ofs    ]) <<  8) |
     ((uint32_t)(pixels[ofs + 1]) << 16)
#ifdef NEO_RGB
     :
   ((uint32_t)(pixels[ofs    ]) << 16) |
     ((uint32_t)(pixels[ofs + 1]) <<  8) )
#endif
     ;
 }

 return 0; // Pixel # is out of bounds
}
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: V1x0r on Dec 18, 2013, 08:15 pm
yup.  hence my post earlier not working.  it fed back the array color and not the registered color on the led.  :(  hence why I want to try out
http://www.pjrc.com/teensy/td_libs_OctoWS2811.html (http://www.pjrc.com/teensy/td_libs_OctoWS2811.html)    though, I haven't looked at it's definitions just yet so it may be doing the exact same thing.  :/
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: jasmine2501 on Dec 18, 2013, 08:47 pm

http://www.pjrc.com/teensy/td_libs_OctoWS2811.html (http://www.pjrc.com/teensy/td_libs_OctoWS2811.html)    though, I haven't looked at it's definitions just yet so it may be doing the exact same thing.  :/


If it has any kind of GetColor() function, it has to be reading an internally maintained array, because there is no way to get information out of the WS2812, it is input-only.
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: V1x0r on Dec 18, 2013, 08:50 pm
that is why this stupid thing is so confusing!  how do they do this!!  >_<
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: Grumpy_Mike on Dec 18, 2013, 10:06 pm

how do they do this!!  >_<


Well if you could monitor the presence / absence of current draw, you could send a single lit LED along the row and when the current drops to zero you know you have shifted it off the end. This could be one on start up so fast that you would not see it flicker.
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: V1x0r on Dec 18, 2013, 10:30 pm
That is an excellent point!  and an astute yet very simple thing to do!  simply "pin 4" would be used as a check pin gathering use information.   I haven't searched this up yet to test...any ideas on monitoring current draw via arduino?  I'll go search this after I send this out too.  :)
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: fungus on Dec 18, 2013, 10:52 pm

Well if you could monitor the presence / absence of current draw, you could send a single lit LED along the row and when the current drops to zero you know you have shifted it off the end. This could be one on start up so fast that you would not see it flicker.


I think you'd notice that...can somebody watch the LEDs very carefully on power up and report back? (especially the last LED in the strip)

With the controllers in those photos there's really only one way they can be doing it - measure the current.

Title: Re: Dynamically determine length of WS2812B LED strands
Post by: fungus on Dec 18, 2013, 10:57 pm

any ideas on monitoring current draw via arduino?


You could put a resistor in the circuit and measure voltage drop across it while you search for the end.

When you're happy you've found it, bypass the resistor with a MOSFET.
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: jasmine2501 on Dec 19, 2013, 12:00 am


how do they do this!!  >_<


Well if you could monitor the presence / absence of current draw, you could send a single lit LED along the row and when the current drops to zero you know you have shifted it off the end. This could be one on start up so fast that you would not see it flicker.


Yeah that's why I basically suggested to do that same thing but 'backwards' starting beyond the end of the string and lighting up one light at the end until see some current flow. That way you would only see one LED blink real fast on the end. Starting at the beginning, I think you would see all the LEDs blink, so that's why I'm wondering if there's any flickering or anything right after startup. I agree that with three wires that's probably the only way. With four wires, that fourth wire could be either a data line returning from the end, or it could be a current sensor, and that would give a way to measure the string. I don't think there's any other way really.
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: Grumpy_Mike on Dec 19, 2013, 12:12 am
Quote
any ideas on monitoring current draw via arduino?

A small resistor in the ground with an analogue input on the other side. You are only looking for a few mV so the resistor can be very small indeed. In normal operation you would not notice it.
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: jasmine2501 on Dec 19, 2013, 12:35 am

Quote
any ideas on monitoring current draw via arduino?

A small resistor in the ground with an analogue input on the other side. You are only looking for a few mV so the resistor can be very small indeed. In normal operation you would not notice it.


Wouldn't that measure the current used by the Arduino? Doesn't that fluctuate a lot?
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: Grumpy_Mike on Dec 19, 2013, 12:38 am
Quote
Wouldn't that measure the current used by the Arduino?

No you misunderstand.
The ground return from the LED strip has a 2R2 ( or so ) resistor before it get to the arduino ground, Then you measure on the LED side of this resistor.
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: V1x0r on Dec 19, 2013, 01:15 am
So, i can't see under the chip for what pin goes where and I'm not at home to test points...but it appears as though they are using multiple pins...granted, three of them would have to be devoted to push pin.  it does look like the pins are devoted to the blatantly obvious components.  Unless they are treating the din pin as both input and output.  (possible?)  if it is an input then the current draw check would be logical from there.  anyway...It would be cool to pull current draw.  :)

the rf version has dual grounds...I should look at that closer again and see if that second ground goes elsewhere.  on the small adapter it has a large ground connection so maybe that is going to a resistor on one of the input pins.  Great idea to check!  I did post the images for both boards...but a better image is of the small one (which is the one mostly in question)   it does have three resistors
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: V1x0r on Dec 19, 2013, 01:16 am
I don't have a fast enough camera to catch if a pixel illuminates  or not.  mind you, some of the leds will also flicker once power is applied to the strip anyway.
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: jasmine2501 on Dec 19, 2013, 06:49 am

So, i can't see under the chip for what pin goes where and I'm not at home to test points...but it appears as though they are using multiple pins...granted, three of them would have to be devoted to push pin.  it does look like the pins are devoted to the blatantly obvious components.  Unless they are treating the din pin as both input and output.  (possible?)  if it is an input then the current draw check would be logical from there.  anyway...It would be cool to pull current draw.  :)


No it's not possible to use that pin as any kind of output. The chip just doesn't have that function. It would be documented in the data sheet, and there would be some method of triggering the function to output data, and there's nothing like that.

I think you would need to measure current draw on the power pins, not the signal line, because that's just carrying binary data, that you are sending, so anything you measure there would be a result of what you sent, not what's happening on the light string, and that's if reading the current of a data line was meaningful anyway. It would be interesting to know if the resistors are connected to some kind of current sensor. Can you take a high quality photo of the boards? I couldn't really tell anything from the previous photos.
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: fungus on Dec 19, 2013, 10:56 am

Quote
any ideas on monitoring current draw via arduino?

A small resistor in the ground with an analogue input on the other side. You are only looking for a few mV so the resistor can be very small indeed. In normal operation you would not notice it.


You have to be very careful with that. Those strips can draw a LOT of amps - a 5m strip with 60 LEDs/m and all the LEDs turned on needs over 18 amps. That's why I suggested including a MOSFET to bypass the resistor when you finish measuring.


The ground return from the LED strip has a 2R2 ( or so ) resistor before it get to the arduino ground, Then you measure on the LED side of this resistor.


A 2R2 resistor at 18 amps will drop 40 volts... :-)

(Or catch fire in the attempt)
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: Grumpy_Mike on Dec 19, 2013, 04:01 pm
@fungus
Please keep things in perspective.

Quote
those strips can draw a LOT of amps - a 5m strip with 60 LEDs/m and all the LEDs turned on needs over 18 amps.

Well durr! My grandmother can suck eggs as well. Well are discussing the techniques by which this can be done we are not talking about a universal solution. Why stop at 18A?

Quote
A 2R2 resistor at 18 amps will drop 40 volts

You know what, I can do ohms law as well.
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: fungus on Dec 19, 2013, 04:26 pm

Why stop at 18A?


They usually sell these strips in 5m lengths, OP mentioned 5m strips in message #4 of this thread.

It seemed like a number that will happen in real life.

Title: Re: Dynamically determine length of WS2812B LED strands
Post by: fungus on Dec 19, 2013, 04:54 pm

Well are discussing the techniques by which this can be done we are not talking about a universal solution.


If we stick with the 18A figure and limit ourselves to 1/2W power dissipation over the sensing resistor, the voltage drop at that power will be 0.027V.

Plug that value into Ohm's law we get a 1.5 milliohm resistor.

Assuming we can find one of those, the voltage drop across it for each LED you light up would be 0.00009V - far too small for an Arduino to measure directly.

Workable technique...?

Title: Re: Dynamically determine length of WS2812B LED strands
Post by: Grumpy_Mike on Dec 19, 2013, 05:21 pm
Hey lets all make up stupid figures and have a bigger argument.
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: fungus on Dec 19, 2013, 06:02 pm

Hey lets all make up stupid figures and have a bigger argument.


Why is it stupid?

OK, I just looked up the actual LED current for the [img=https://www.adafruit.com/datasheets/WS2811.pdf]http://WS2811[/img] and it's only 18.5mA, not 20mA per LED.

In that light I'll concede that A 5m strip has a maximum of 16.6A, not 18, but 5M strips are common so that's the number to design for.

If it's a closed system then you could design your patterns to not switch on all the LEDs simultaneously, that saves a few more amps. It's still going to be massive though, let's call it 10A. I still don't think just putting in a resistor is going to be a realistic option.
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: jasmine2501 on Dec 19, 2013, 07:09 pm
There's no reason to consider blowing out your Arduino trying something as simple as current sensing. I agree that it's not going to be possible to run all the current for the lights through the Arduino and a simple resistor wouldn't be safe. I'm thinking you just use something like this to sense current: http://www.ti.com/product/ina169

For this purpose, you don't need actual current values, you just need to know when it goes from zero to non-zero.

On page 4 of the data sheet: http://www.adafruit.com/datasheets/WS2812.pdf

It says that each of the 3 LEDs can use 20mA - for a total of 60mA per unit. There's 60 LEDs per meter, so 5 meters is 300 lights total... giving a maximum current draw of 18 Amps - (0.060 * 300) - that's pretty serious current draw - 216 watts on 12V. Of course that only happens when you light up the whole string with full brightness white. Colors will always be something less than that.

Title: Re: Dynamically determine length of WS2812B LED strands
Post by: fungus on Dec 19, 2013, 07:27 pm

There's no reason to consider blowing out your Arduino trying something as simple as current sensing. I agree that it's not going to be possible to run all the current for the lights through the Arduino and a simple resistor wouldn't be safe. I'm thinking you just use something like this to sense current: http://www.ti.com/product/ina169


That solves the measurement problem but it still runs all the current through a single resistor.

I'm still thinking that the only way to do it is use a decent size resistor for the detection phase then bypass it with a MOSFET (or two) when you want to show the patterns.


...that only happens when you light up the whole string with full brightness white. Colors will always be something less than that.


Not necessarily.

Brightness is done with PWM so if all PWM pulse of the LEDs coincides you still get peaks at maximum draw.

OK, the chances are that they won't all line up and the built-in decoupling on each LED should help, but half-bright doesn't necessarily mean half-current.

Title: Re: Dynamically determine length of WS2812B LED strands
Post by: jasmine2501 on Dec 19, 2013, 07:41 pm

OK, the chances are that they won't all line up and the built-in decoupling on each LED should help, but half-bright doesn't necessarily mean half-current.


In my experience it's roughly inverse-square - half brightness is about 1/4 current level. These things are ridiculously bright - I can't even look at them at numbers greater than 50/255. A (50,50,50) white is tolerable to look at.
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: fungus on Dec 19, 2013, 07:50 pm

In my experience it's roughly inverse-square - half brightness is about 1/4 current level. These things are ridiculously bright - I can't even look at them at numbers greater than 50/255. A (50,50,50) white is tolerable to look at.


Oh, I see. "Half brightness" is less than "half power", yes....  :)

Not everybody looks at them directly though. A lot of people view them indirectly (put them behind things), they usually need full power.
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: V1x0r on Dec 19, 2013, 09:04 pm
Apparently I have missed a lot in the last little bit.  lol.  I'm really digging this suggestive input!  Thanks guys!  :)   
With the components in the image I posted of the smaller device they are capable of doing something like what we are talking about...But i'm not sure if it is doing a current draw check.  that just seems dangerous to the components.   Now, for your guys' mathematical input and some ease, these 5m strands are 30 leds per meter.  so not very large of a current draw compared to the 60/m strips.  :)    do any of you have the ws2812B strands?

http://www.aliexpress.com/item/BLACK-PCB-5m-DC5V-WS2812B-led-pixel-srip-IP68-30pcs-WS2812B-M-with-30pixels-reverse-protection/926778326.html (http://www.aliexpress.com/item/BLACK-PCB-5m-DC5V-WS2812B-led-pixel-srip-IP68-30pcs-WS2812B-M-with-30pixels-reverse-protection/926778326.html)

This is who i purchased my current strands from.  If you purchase multiple 5m packages then the price is worth it.  :) (since shipping barely goes up unless you order a lot of them at one order...but you can always make multiple orders).  :)
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: jasmine2501 on Dec 19, 2013, 10:25 pm

Apparently I have missed a lot in the last little bit.  lol.  I'm really digging this suggestive input!  Thanks guys!  :)  
With the components in the image I posted of the smaller device they are capable of doing something like what we are talking about...But i'm not sure if it is doing a current draw check.  that just seems dangerous to the components.   Now, for your guys' mathematical input and some ease, these 5m strands are 30 leds per meter.  so not very large of a current draw compared to the 60/m strips.  :)    do any of you have the ws2812B strands?


I wouldn't say it's "not very large" it's exactly half the current draw we calculated based on 60 instead of 30 - so, 9 amps - that's still kind of a high current draw. Relative term of course, but I'm saying it's high relative to things you drive with the Arduino directly, which are 100 times lower.

I have the WS2812 lights, some TM1803 lights, and some 'loose' LEDs I use for all kinds of different stuff, mostly aircraft lighting for night flying. There is no difference between the WS2812 and the WS2812b except that they removed the unused pins - there was six pins on the WS2812, and two of them were unconnected. There's only 4 pins on the WS2812B - Power (Vcc), Ground (Vss), Data In (Din) and Data Out (D0). The whole thing is smaller and lighter weight than the WS2812 original, and it has better efficiency overall. Electrically and data-wise, it looks the same as the old ones.

I don't think there is anything special about the way the strip itself is built - it looks like a 'normal' LED strip - basically just everything parallelled up. There is a capacitor on there which I'm not sure about, but it's probably just for the power supply. It should be pretty much the same as these which I get from Sparkfun... (they also have a capacitor but I can't tell how it's wired up, it's probably not important to our issue)
https://www.sparkfun.com/products/12027
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: V1x0r on Dec 20, 2013, 12:23 am
that's used for reverse protection.  it's connected to the ground.

The ws2812B leds are more superior to the WS2812 leds.  They are brighter, more efficient, and are better capable.  :)  I don't like using adafruit for the documentation on the leds though.    Also, you pay way too much for only 1 meter of an older led.
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: V1x0r on Dec 20, 2013, 12:33 am
here you go.  :)

http://www.aliexpress.com/item/Black-PCB-DC5V-5m-WS2811-built-in-the-5050-RGB-150-LED-digital-strip-light/969633185.html (http://www.aliexpress.com/item/Black-PCB-DC5V-5m-WS2811-built-in-the-5050-RGB-150-LED-digital-strip-light/969633185.html)
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: jasmine2501 on Dec 20, 2013, 12:55 am

here you go.  :)

http://www.aliexpress.com/item/Black-PCB-DC5V-5m-WS2811-built-in-the-5050-RGB-150-LED-digital-strip-light/969633185.html (http://www.aliexpress.com/item/Black-PCB-DC5V-5m-WS2811-built-in-the-5050-RGB-150-LED-digital-strip-light/969633185.html)


Those have half as many LEDs! Those are approximately $55 for 5 meters, cuz there's gonna be some shipping charges - it works out to about 33 cents per light.

https://www.sparkfun.com/products/12028

Those from Sparkfun have twice as many LEDs, and the price is just over twice as much ($120),  I don't pay any shipping because I can just go to Sparkfun and pick it up if I have to, but on something this price, they will ship for free. So, the Sparkfun lights are 40 cents per light. That's a difference of 17% and it supports a local business. Some people don't consider those kind of things but for me, supporting a local business and getting a slightly better quality level are important.

Everyone decides those things for themselves, but that's why I buy from Sparkfun for a lot of stuff, which you can get cheaper somewhere else - because 'cheap' isn't my only criterion.
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: jasmine2501 on Dec 20, 2013, 12:57 am
Oh also, on the "not liking Adafruit" - that is immaterial, the data sheets come from the company that makes the chip - there isn't anything to not like, that's the data sheet, there isn't another one.
Title: Re: Dynamically determine length of WS2812B LED strands
Post by: V1x0r on Dec 20, 2013, 12:58 am
apologies...here is a ws2812 (non b still)
http://www.aliexpress.com/item/High-Quality-Dream-Magic-Color-WS2812-LED-Strips-Flexible-Light-60-LEDs-m-240-led-4m/1492093395.html (http://www.aliexpress.com/item/High-Quality-Dream-Magic-Color-WS2812-LED-Strips-Flexible-Light-60-LEDs-m-240-led-4m/1492093395.html)

free shipping.  :)  (and insulated)