Fadecandy, Neopixels and ofxOPC

ofxOPC is a openFrameworks addon that gives users the ability to send data to LEDs simply by drawing graphics to a screen. The addon uses @scanlime’s amazing Fadecandy unit.

For those who may be unfamiliar with the Fadecandy, its a small USB powered LED driver that is able to control up to 512 individual LEDs through its 8 output pins or 64 channels per pin. Check out @scanlime’s github for more on how the unit itself works.

Fadecandy Unit

How the addon works?
The addon pulls colour information from the screen, which is defined by the user. The addon then sends this data in TCP packets to the Fadecandy server which is decoded by the Fadecandy device and passed to the LEDs.

How to use the addon?
Within the addon repository there are multiple examples and explanations on how the addon interacts with openFrameworks. But for the purpose of this post I’ll give a really quick breakdown of how to use the addon. Before starting you will need to either download or clone both the addon https://github.com/DHaylock/ofxOPC and the Fadecandy server https://github.com/scanlime/fadecandy.

Step 1 – Include the addon
Place the addon in the addons folder of your openFrameworks folder. Make a new project with the project generator adding both ofxOPC and ofxNetwork.

Next declare both an ofxOPC and Neopixel object.

ofxOPC opcClient;
NeoPixelRing12px ring12px;

There are numerous Neopixel objects within the src folder.

Step 2 – Make the Connection
The Fadecandy server as default runs locally at on port 7890. You can alter these but for now we will leave them.
In the .cpp file setup the ofxOPC giving it both variables.

opcClient.setup("", 7890);

Step 3 – Generate what you want the LEDs to display.
For this example we will draw four of these images rotating with different colors.dot

// ofApp.h file 
ofImage dot;

// ofApp.cpp

int size = 70;
ofTranslate(0, 0);
ofSetColor(0, 255,20);
dot.draw(size/4, size/4, size,size);
ofSetColor(255, 0,20);
dot.draw((size/4*3), size/4, size,size);
ofSetColor(0, 0,255);
dot.draw(size/4, (size/4*3), size,size);
ofSetColor(255, 0,255);
dot.draw((size/4*3),(size/4*3), size,size);

Step 4 – Grab the Data
When you are ready to send stuff to the LEDs add the following lines to the update function.
Its important to ensure the Fadecandy is connected and the server is running before running the application, otherwise it will almost certainly crash.

Ensure you have a black background otherwise the addon will pull the background colour.

    // Grab data from the centre of the window

    // If the client is not connected do not try and send information
    if (!opcClient.isConnected())
        // Will continue to try and reconnect to the Pixel Server
        // Write out the first set of data

Step 5 – Draw and Enjoy
Add the following lines to the draw function to visualise the output of the LEDs.

 // Visual Representation of the Grab Area
    ring12px.drawRing(50, 50);

Screen Shot 2014-10-06 at 11.15.20

Fire up the Server by running the fcserver script, which is found in the bin/ directory of fadecandy folder. The server should open a terminal window and display all connected units.
Screen Shot 2014-10-06 at 11.34.17

Run the oF application and hey presto your LEDs should alight.

Check out the other examples in the addon folder.

Maybe try multiple strips to make a video curtain:

Or include Syphon feeds: