Controlling LED Stripes

Some time ago I ordered a two meter with 120 LEDs. Originally I thought that I can write a small program for the small XMC2go board using Infineons DAVE4.

But it happens that time has gone and I read the MagPi Issue 36. The magazin mentioned an Adafruit article which explains how to control the LED stripes.

Porting to the Raspberry A+

This is a nice small computer. And cheap, ideally suited for this task. The digital outputs are 3.3V only and normally there should a level shifter to 5V to control the input of the LED stripe. Burt fortunately the LEDs I own do not need it.
I directly connected GPIO18 with DI of the LED stripe. And it works.

But first lets start with installing the software.

Installing software

I directly followed the Adafruit article.

apt-get update
sudo apt-get install build-essential python-dev git scons swig

I always have a source ~/src directory on my computers.

cd src
git clone https://github.com/richardghirst/rpi_ws281x.git
cd rpi_ws281x/
scons # build tool, Phyton based
cd python
sudo python setup.py install

Now it is possible to call directly the

 cd~/src/rpi_ws281x
 ./test

it will control 16 LEDS, because the main.c defines:

#define WIDTH                                    3
#define HEIGHT                                   3
#define LED_COUNT                                (WIDTH * HEIGHT)

I changed that easily to

#define WIDTH                                    32
#define HEIGHT                                   1

and again

scons   
./test

More impressive is one of the examples in src/rpi_ws281x/python/examples/strandtest.py

cd ~/src/rpi_ws281x/python/
sudo examples/strandtest.py 

and have fun! I did the following changes in

LED_COUNT      = 16      # Number of LED pixels.
LED_BRIGHTNESS = 200     # Set to 0 for darkest and 255 for brightest
ledstripe_connect

Porting to the PiZero

Late in 2015 the new very low cost PiZero was announced and already available. It was offered for $5. Unfortunately the first 10,000 units were sold very fast. I only got the chance to order one at PiHut and it was delivered in the first week 2016. For nearly 15 € I got the PiZero, an 8G µSDCard with NOOBS pre-installed, the Essential Raspberry Pi Zero Kit (with MiniHDMI > HDMI adapter, MicroUSB > USB adapter, some pin headers).
This little and low cost part should be even more appropriate for controlling the LED RBG stripes. Later on equipped with a USB WIFI dongle, the LEDs can be controlled via WIFI by using the smart phone or whatever.
To get the firmware prepared add a display at HDMI, a bluetooth keyboard and USB WIFI dongle, both via a USB hub. After boot up selecting the Raspian OS and basic configuration is simple. Next steps are the same as above - but wait:

Unfortunately there is a small problem. Since the PiZero comes with kernel 4.1.x installed, libws2811.a does not work out of the box. The mailbox char driver has changed it's major number from 100 to 249. I had to change the code in mailbox.{c,h}.
After these changes, again:

cd ~/src/rpi_ws281x
scons
sudo ./test
^C
cd python
sudo python setup.py build --force
sudo python setup.py install

If all went OK, the python examples will work too.

Porting to the JanzTec emPC-A/RPI

The JanzTec emPC-A/RPI is an versatile controller designed to be used in industrial applications. Basically the computing module is a Raspberry PI 2 Model B. But the emPC has a 24V power supply and industrial opto decoupled IOs. To be used as an industrial controller it comes with a ready to use CAN bus interface to extend the on board IOs with industrial grade CANbus controlled remote IOs. An CANopen implementation is available to, developed by emtas GmbH. Here is a list of the most important features:

empc

Installing software

Software installation is done the same way as for the A+,
The rpi_ws281x library supports all Raspberry models (so far I know.)

Connecting the LED stripe

All Examples are using GPIO18. Fortunately the Janz emPC-A/RPI is using GPIO18 as well for DO4, one of it's four digital outputs. It is available on pin 1 of the multi IO connector.
Before using the digout it has to be set to an GPIO output pin

$ sudo su 
# echo "18" > /sys/class/gpio/export
# echo "out" > /sys/class/gpio/gpio18/direction

The process IOs are galvanically decoupled and need a separate IO voltage. Unfortunately (the first) the used IO switch needs at least 10V as VIO. Connect the pin 5 of the multi IO connector (GNDIO) with the LED stripe power GND and pin 6 (VIO) with tho IO voltage. For controlling the LED stripes the galvanic isolation is not needed. The emPC power can be used. Connect pin 5 with pin 23 (GND) and pin 6 with pin 24 (VIO).
The DO4 and all other DOs are high-side switches. A load resistor to ground is needed in order to get a signal. For a first test connect 1.5 KOhm from pin 1 to GND.

And now it can be tested:

# echo "1" > /sys/class/gpio/gpio18/value
# echo "0" > /sys/class/gpio/gpio18/value

To control the input DI of the LED stripe a high level voltage between 4 and 5 V is needed. But wait. Here comes the next *unfortunately**.
The used ST Microelectronics VN330SP is specified to have long turn-on and turn-off switching times. the first one is in the range of 50µs. This might be a good value to switch industrial loads like relays, but far from being useful to control the WS2812 based LED stripes. The WS2812 expects a bit frequency of 800Khz - 1,25µs / bit - far from being reachable with the used digital output driver in the emPC.

It was my failure !

What I know but what I did not do - reading the manuals first !
If I had read the data sheets, it would have been clear that it can not function. I would have saved a lot of my time.

vim: se spell spelllang=en fileencoding=utf8 wrap :

Controlling LED Stripes
Controlling LED Stripes