Go Down

Topic: Dynamically determine length of WS2812B LED strands (Read 20407 times) previous topic - next topic

V1x0r

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  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!!!! 

fungus

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...
No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Paul__B

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.

fungus


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.
No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

V1x0r

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.  ^_^

fungus


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.
No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

V1x0r

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. 

fungus


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?

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

jasmine2501


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.)

V1x0r


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.  

jasmine2501

#10
Dec 16, 2013, 10:20 pm Last Edit: Dec 16, 2013, 10:23 pm by jasmine2501 Reason: 1
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.

Grumpy_Mike

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.

jasmine2501

#12
Dec 17, 2013, 06:06 am Last Edit: Dec 17, 2013, 06:24 am by jasmine2501 Reason: 1

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

V1x0r

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.  :)

jasmine2501

#14
Dec 18, 2013, 01:57 am Last Edit: Dec 18, 2013, 02:35 am by jasmine2501 Reason: 1
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


Go Up