ambi-tv icon indicating copy to clipboard operation
ambi-tv copied to clipboard

WS2801 support

Open iLLiac4 opened this issue 11 years ago • 24 comments

Hi! Can you please help me to give some guidance to add support for WS2801 leds. I think a lot of people will love to see that.

iLLiac4 avatar Aug 15 '13 10:08 iLLiac4

afaik the WS2801 requires a far more precise timing than the LPD8806, so I'm not sure if you can drive it directly from the Raspberry Pi's spidev. However, I haven't tried this myself either, so I'm just guessing here. I've also seen this adapter board for the WS2801, which looks as if it works around the timing issue: http://www.hackerspaceshop.com/raspberrypi-ws2801.html

Apart from the hardware issue, adding support shouldn't be too hard: you need to implement another "sink" component pretty much identical to the current lpd8806 sink (the only sink right now), which implements the WS2801's "protocol". then register your new component in registrations.c like all the other components, and finally add the new sink to your ambi-tv configuration file.

You can write your own components for different LED effects ("processors") in this manner, too.

gkaindl avatar Aug 15 '13 13:08 gkaindl

As far as i know the ws2801 is almost the same as lpd8806. The precise timing is required by ws2811 chip and not by ws2801.

iLLiac4 avatar Aug 15 '13 13:08 iLLiac4

All the better, if it's similar to the lpd8806, then it should be all the easier to add support for it. I'd really suggest to have a look at lpd8806-sink-component and hack the support for ws2801 into there (please send a pull request if you do, since you weren't the first to ask for the ws2801, but unfortunately, I don't have such a strip to test with).

gkaindl avatar Aug 15 '13 14:08 gkaindl

The only difference, software-wise, for the ws2801 is that the SPI protocol might be different. I would recommend looking at the manual for the chipset. It shouldn't be difficult to modify the existing driver to work with these. You might even be able to snag a driver from one of adafruits tutorials.

If you haven't bought the ws2801 already, keep in mind you're paying quite a bit more for significantly less LEDs per meter.

Mrjohns42 avatar Aug 20 '13 17:08 Mrjohns42

Hi guys,

I have ws2801 leds, and it seems modifying the lpd8806 sink isn't too difficult. I haven't received the stuff I ordered from Hong Kong yet, so I have only tested my ws2801 sink using the mood light program. As far as I can tell, the only differences are:

  • You can use the whole 8-bit colour, not having to do the map from 8-bit to 7-bit in the "set_output_to_rgb" method. I.e. instead of "lpd8806->grb[3 * ii] = g >> 1 | 0x80;" etc, you can just set "ws2801->grb[3 * ii] = g".
  • You have to change the order the colours are sent to the led strips. I had to use BGR, but you may have to change that according to you led strip.
  • There is no need for the "latch bit". So, basically, everywhere you see grblen+1, replace that with grblen :P You have to change this in the "commit_outputs" and "create" methods.
  • In the "clear_leds" method, don't send "0x80", send 0.

I might have forgotten something, and I have only tested this with the mood light, so I haven't looked at gamma correction. There might be some problems I haven't encountered yet as well. The ws2801 doesn't need a latch bit, but needs the clock signal to be kept low for at least 500 microseconds to latch the data. I don't have any knowledge about SPI so I don't really know if this is going to be a problem. I can put my modified sink up here when I have tested it some more.

gfix avatar Aug 22 '13 19:08 gfix

BTW, great work gkaindl!

gfix avatar Aug 22 '13 19:08 gfix

@gfix thanks!

from your description, it sounds as if the best way to implement this would be to actually rename the lpd8806 sink to something else (like spidev-led-sink or something) and add a component parameter to switch between lpd8806 and ws2801 behavior, since it's so similar.

To keep the clock signal low for 500 microseconds, I think that should be doable by sending the last byte via spidev's ioctl() interface, using the delay parameter (and possibly a lower clock speed).

I can go ahead and implement this, but it'll take me a while, since I'm currently a bit busy. Alternatively, if you do it and send me a pull request, I'll incorporate it.

Regarding the gamma correction: That shouldn't be much of a problem. The gamma is configurable separately for all 3 channels, and it mostly boils down to preference: The settings I'm using in the default conf are basically just what works well for me – I tried the gamma that PAL uses earlier, but that was way too dark for my taste. What I did was mirroring my display on the TV and fill it with a couple of solid color pictures to see if it looks ok, then settled on the gamma that I liked most.

gkaindl avatar Aug 22 '13 22:08 gkaindl

I received my WS2801 LED-strips yesterday (bought via Ebay China). Today I did some testing.

  • Simply output 3 full bytes, Red, Green Blue via SPI. (e.g. 24 bits in total)
  • Wait 900 uS. (I tried with the 500 uS, but that gave me some problems - flickering) 1000 uS is more then sufficient, there are 1000000 uS in one second :-) maybe the delay can also be put in the config-file ?

I'm willing to write the WS2801 component, but I'm leaving on holidays tomorrow night ... When I return by the end of september, and nobody has written the WS2801 support, I will write it :-) (I'm planning on a second ambi-tv for our bedroom, and I will use the WS2801 for it)

sn00zerman avatar Aug 29 '13 13:08 sn00zerman

Hi,

first I'd like to say thank you gkaindl for that great project.

I've completed my setup two hours ago, but the problem is, that I have flickering with my WS2801 leds. Colors, and configuration of my leds is great.

Can someone explain me where to set that delay? I'd like to try it with 900 uS to see if it's the problem with flickering.

I've searched for that delay, but cannot find anything.

Thanks for your help.

YoBnEb avatar Aug 31 '13 16:08 YoBnEb

sn00zerman: ...that would be cool, I also have LED strip WS2801 + boblight, but I would like to use ambi-tv: o)

rcph avatar Sep 01 '13 09:09 rcph

@sn00zerman I'll wait for your tutorial beacause i want too try it too with my WS28001 Led that i already have on my tv with my arduino

blais0u avatar Sep 10 '13 10:09 blais0u

Is there any news on this? Is anyone working on ws2801 support as i am not technical enough to make the changes myself

Dec64 avatar Sep 29 '13 22:09 Dec64

@sn00zerman ...do you have any solutions?

rcph avatar Oct 01 '13 17:10 rcph

I have ws2801 and have made it work. However I haven't had the time to implement it such that you just can set the type of led strip (or chip rather) in the conf-file, as @gkaindl suggested. I can upload the files I have altered (which really isn't much). I didn't have to do anything with the delay. I'm not sure that it is even necessary if you have the 30fps as in the sample conf, since the data will have the time to latch between two frames (I guess the clock signal is set to low after the data is transferred?) I don't experience any flickering.

gfix avatar Oct 01 '13 17:10 gfix

If you could upload them files so i could have a play around and see if i can get it working too, that would be great!

Dec64 avatar Oct 01 '13 17:10 Dec64

I just forked the repo and added my changes in order to make the ws2801 work. I also added my conf file. I did this because I remembered that I experienced some flickering on the left side of the screen, but this was only due to the crappy capture card, so I only needed to add a few more pixels of cropping. If your colours don't match at all, you have to change the order the data is sent to the leds (I'm not talking about gamma correction here): Change the lines 196-198 in the "ws2801-spidev-sink.c" file to the order you need. Then run "make clean" and "make" again. This should also be one of the parameters you should be able to alter in the config file once we fix this for real. Wish you luck!

gfix avatar Oct 01 '13 20:10 gfix

@YoBnEb, did you figure out the flickering? Have you made sure that you have grounded the led-strip to the same ground as the external power supply?

gfix avatar Oct 01 '13 20:10 gfix

@gfix Thank you very much, I will take a look. Cheers for all the work and sharing it.

Dec64 avatar Oct 01 '13 20:10 Dec64

@gfix no, I didn't had time to figure out what the problem is. But I also changed the crop values, and so the flickering is minimal.

I use only one power supply for everything, so I think that couldn't be the problem, but thanks for that idea.

YoBnEb avatar Oct 01 '13 20:10 YoBnEb

@YoBnEb can you upload your config? i have too that flickering and no config values can minize this

My LEDs also working fine with boblight, so hardware setup is working fine

Esylias avatar Oct 28 '13 19:10 Esylias

crop-left 1 crop-top 1 crop-right X < Can't get this to stop flickering crop-bottom 1

Flicker only accrue when there is a black screensaver.

mnorthfield avatar Oct 28 '13 20:10 mnorthfield

@mnorthfield

these are my working crop-values

v4l2-grab-source { name v4l2-video video-device /dev/video0 buffers 8 crop-left 60 crop-top 40 crop-right 60 crop-bottom 40 autocrop-luminance-threshold -20 }

The flickering will be produced, if the grabber get an black pixel

Esylias avatar Oct 28 '13 20:10 Esylias

@Esylias

Tried your settings and my frame went wakoo when I run a pitch black screen. Lights everywhere.

This is the problem I'm stuck with, but I think it has to do with a crappy video-grabber. Pretty annoying when watching Boardwalk Empire. Managed to fix it on the left side by setting it to 1.

The input is black, it's just my 5min burn in on the plasma:

https://dl.dropboxusercontent.com/u/22263213/AmbiTV/2013-10-28%2021.53.54.jpg https://dl.dropboxusercontent.com/u/22263213/AmbiTV/2013-10-28%2021.55.28.jpg

-- Max

mnorthfield avatar Oct 28 '13 21:10 mnorthfield

Changed the video-grabber and the problem is gone.

mnorthfield avatar Nov 19 '13 13:11 mnorthfield