[help] serial communication: vvvv > Arduino > APA102 LEDs

Dearest ninjas,

We are working on an interactive installation project where we are using LED strips inside transparent human sculptures to highlight 7 chakras through different light changes. At the moment, we are having some difficulties to make vvvv “fluently” communicate through serial port rs232-(devices) (via Arduino) with LEDs APA102 (“DotStar”).

We tried many things with the patch, code and different Arduino pins, but still didn’t manage to properly send packets of values from vvvv > Arduino Code (buffer) > Array of 360 LEDs (6 strips, 60 LEDs each, serially connected with 4 wires GND, DATA, CLOCK & 5V). DATA wire is currently connected to A9 (analog) pin and CLOCK to A10 (analog) pin on Arduino Mega 2560.

There is probably something wrong with the Arduino code or the vvvv patch. Maybe we are sending wrong values from vvvv or they are correct but the Arudino code doesn’t understand them.

Does anybody have experience with this and is willing to have a quick look at our patch and the code? Any help will be greatly appreciated. Thank you very very much.

If anything is unclear about the hardware or software don’t hesitate to ask.

vvvv patch and two versions of Arudino code (v2 still needs some work) are attached in this post and are also available here https://github.com/sivinjski/AwakeningCircle

AwakeningCircle.zip (vvvv patch + two versions of Arduino Code) (760.9 kB)

hey,

what exactly isn’t working?
does “not fluently” mean it generally works, but not every packet is arriving?

edit: what definetely seems odd, is that it seems you’re using analog INPUT pins for the clock and data pins in your arduino patch - sure it’s not supposed to be pwm (analog) outputs?

Hi soriak,

It seems that LEDs are still not understanding the packets but are shining randomly and noisily, so to say, with no specific order. When testing Arduino libraries, without vvvv, such as FastLED or Adafruit_DotStar, everything works fine - rainbow example shines all colors on all 360 LEDs.

Serial communication exists but pretty undefined, not sure where exactly it should be fixed. When the patch is running, rs232-(devices) enabled and Update Port List refreshed, Arduino board blinks most of the time. When I, for example, pause the LFO or switch some toggles on/off at different points around the patch, LEDs respond with pause (freeze) or change the speed or strangely change the ‘noise form’ a tiny bit.

Thanks for the proposal. I’m not sure about PWM pins. I have tried before and now again (changed on the board and in the code of course), but nothing changed. As I understood, only digital pins can work as PWM pins. In case of Mega 2560 pins which provide 8-bit PWM output with the analogWrite() function are 2 - 13 and 44 - 46.

Something is maybe wrong with the Arduino code or packet from vvvv doesn’t match APA102 LEDs.
Any ideas? What about Baud Rate? Data Bits? Stop Bits? Handshake? etc.

Thanks.

I’m confused by the whole converting to ascii thing, but that just might be me not knowing anything about serial communication…

I’d go either to vvvv native artnet and an ethernet shield on the arduino (worked really well for me with ws2801 led setups with fastLED library + you don’t have usb cable length restrictions)

or maybe try another approach of encoding and decoding your data:

http://stackoverflow.com/questions/22289019/send-long-array-to-arduino-over-serial-from-processing

adapted to your case:

void loop(){
String content = "";
if (Serial.available()) {
  while (Serial.available()) {
    content += Serial.read();
  }
}
int data[1080](1080); //The results will be stored here
for(int i = 0; i < 1080; i++){
  int index = content.indexOf(","); //We find the next comma
  data[i](i) = atol(content.substring(0,index).c_str()); //Extract the number
  content = content.substring(index+1); //Remove the number from the string
}

 for(int i=0; i<NUM_LEDS; i++) // for loop to push values to LEDs
  {
     leds[i](i).setRGB( data[i * 3](i * 3), data[i * 3 + 1](i * 3 + 1), data[i * 3 + 2](i * 3 + 2));
  }


FastLED.show();
}

obviously untested and probably buggy :D

made some slight modifications to your vvvv patch to try to match the arduino code

edit: plugged in an arduino out of curiosity, on my machine the rs232 node takes ages to write all the values to the arduino… same on your side?
never tried so many values via rs232 and at least on my machine it seems like a bad idea… taking a higher baudrate didn’t help much either… I’d go artnet!

AwakeningCircle_mod.v4p (206.2 kB)

I think it would really help you to add some debugging to your code to test for valid data on the Arduino side and use another serial port to print debug msgs or just blink some LEDs to signal different conditions.

Just looking briefly at the Arduino code I’m pretty sure it won’t work like you have it now.

“Serial.readBytes(packetBuffer,1080);// 1080 is the packetsize = 1080 values + ‘<’ and ‘>’”

If I’m not mistaken the serial buffer size on the Arduino is only 64bytes so you won’t be able to read one packet in one go, you can try using your own buffer and filling that in smaller chunks as fast as you can and then update the LED outputs when you have received a whole packet. It might still be a struggle to get it to work if you don’t throttle/pace the data sending from vvvv.

It might be easier if you can change to a teensy 3.x and adapt this contribution that allow much higher data rates: teensy3.0octows2811-led-control

I haven’t used the APA leds but have made a system with 512 neopixel/ws2812 LEDs and code based on the octows2811 contribution.

And also don’t forget to consider to do the animations on the arduino side if you don’t need terrible complex or a huge number of animations. Maybe you can easily do them with arduino code or put animations as data into program memory that you can play.

Maybe you can simplify so you just need to send simplified data like

chakraIndex, intensity, color

or

chakraIndex, animationNumber

@soriak
Thank you for the code and patch update, but it didn’t work and, as in the case with our version of the patch and code, it makes everything slow down when RS232 starts to send values to the Arduino board.

As you and couple of other friends proposed, we are now considering to buy an Ethernet shield & do everything via Art-Net (DMX). Sounds good and should work better for this and probably many future setups. I’ve seen Art-Net examples with WS2801 and WS2812 LEDs but APA102 still feels a bit tricky.

Is there a specific model of the shield that we should look for or it doesn’t matter much?

@beyon
Thanks for your time and proposals. We were also thinking to find a good way to debug and have a closer look at what’s happening.

I think you are right, the packets are too big for the serial buffer, 1080 = 360 LEDs * 3 (R, G & B) and the board may not be able to receive it all at once. Teensy may be a solution, and we had it in mind before deciding on hardware, but because of the short project deadline we choose Arduino because Teensy couldn’t be shipped in time. Will for sure, try it next time.

I also like your proposal to have light changes/animations in code (that is a plan B for now), but we have plenty of them (+ Kinect 2 is involved) and we’d rather go and do almost everything in vvvv and just make Arduino understand and pass data to the strips.

Do you also think we can do this with Ethernet shield and send DMX values from vvvv?

I used two different types of ethernet shields, the original one and one off of ebay, both worked - the original one survived a pretty bad shorted circuit (which was impressive). The chip on it should be w5100, I think.

Have a working implementation of the fastLED library, which you were using anyways, with artnet - it’s really simple, but I’m happy to share my sketch if you want it!

this is what I used for artnet on arduino
https://github.com/natcl/Artnet

Good! Because we need it very quickly, from what can be shipped in one day to our studio, I found one with the HanRun label (looks like the original Arduino Ethernet Shield) with W5100 microchip and one made by Valleman which has an ENC28J60 microchip. I think, W5100 is the choice.

There is a difference between WS28xx LEDs and APA102, plus it seems like the APA102 is not much supported in this scenario, so we will opensource everything to make it easier for others in the future.

Thanks man, it will be helpful to check your example. Kudos!

Not a problem!
I found the FastLED wiki to be very helpful, the apa102 is definitely supported:

void setup() { 
      FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN>(leds, NUM_LEDS);
    }

https://github.com/FastLED/FastLED/wiki/Basic-usage

The arduino sketch is set up right now to work with the WS2811, you just have to change the setup to match apa102 as above and customize your mac and ip address settings. (and download the artnet and ethernet libraries)

good luck!

ArtnetFastLED.7z (1.3 kB)

Big thanks. Will get back to you when we try Ethernet shield tomorrow.

Hi VVVVers, Hi @sivinjski!
Did you solve the problem? Here I’m facing a simpler one:

I would like to send “raw bytes” to APA102 strip led.

According to the datasheet:

the bytes are sending one by one (MSBFIRST).

This video helps a lot:
https://youtu.be/UYvC-hukz-0?t=528

In the arduino code the function is:
shiftOut(dataPin, clockPin, bitOrder, value)

Do you know how can I achive this through VVVV?
Maybe a C# dynamic plugin would be the smartest way.

I’m thinking about a simple plugin that accept a spread of colors, a spreads of led number on each strip and output a live “raw bytes” sequence to rs232 (Arduino)

Is it feasible in some way?

Thanks in advance for reply

hey @robe,

We had a limited time to play, so we ended up coding everything in Arduino and using VVVV just for Kinect triggers… That might not be what you are looking for, but anyway here’s the repo https://github.com/sivinjski/AwakeningCircle

I believe your plugin idea is worth a try. This inspired me to rethink it the VVVV way again, will let you know if something works out. Cheers! ((:

@robe would be a nice VL workout, all the bit operators are now there, you can even type binary into IOBoxes: Integer and Primitive Types in VL

in fact, if i’m not mistaken, creating the required bytesequence is rather trivial even in vvvv directly, see patch attached.

APA102-ByteEncoding.v4p (11.6 kB)

@Joreg:
thank to your patch I made it works.

@Tonfilm:

that VL thing scares me a lot! It seems more intricate than C textual programming… Have I to start from scratch with something totally new and different? Maybe

Anyway Thanks A lot both!

vvvv_Serial_APA102.v4p (42.4 kB)
vvvv_Serial_APA102.txt (390 Bytes)

good to hear!

wow, can we use that as a testimonial?

1 Like

ahhaha, I lovvvve you guys, don’t get me wrong, I’ll give it a try…
I scared because I was moving my first steps in c# programming and the dynamic-auto-compilation-when-saving is THE BEST THING I’ve ever seen in c# world, Also c# could be powerful… and I don’t get the real advantage of programming visually in VL with logic and concept of textual programming in mind… Maybe it’s just me, I’ve to study a lot, I’m not a programmer, I’m a graphic-designer-3d-Animator. VVVV for me is like for playing with new stuff, and I’ll play with VL of course. What I really miss to integrate VVVV in my pipeline is a rocksolid dx11 render engine. I mean… Dx11 nodes are there, big thanks to Vux, but is not that easy to have a good render quality with shadow, specular, reflection, ao, and so on and even harder to non realtime render what’s created.

In the end:
The best thing of VVVV is the community…
… and the devs …
… and the program itself …
… VL could be The icing on the cake…

You can use that as testimonial

Cheers

obviously two things, you are multiple times faster for most problems (especially if you know vvvv) and you see the data while patching. all the real-time stuff really…

so here, for fun and to make some advertising is the vvvv and vl patches that do the bit logic. in principle it would be possible to patch it exacly as in vvvv, but here as a bonus the alpha value of the color will act as the 5-bit brightness value. and what comes for free is that its bin sized by the vl wrapper automatically, so you can handle as many LED stripes as you want:

this is the bin sized vvvv patch:

this builds the sequence for the bits:

this converts a color to RGB frame with the alpha as brightness:

you can test the patch with the alpha download, enjoy:

LEDBits VL.zip (4.2 kB)

@tonfilm:
Hi and thanks a lot for the example patch and for time spent to explaining it. Also the alpha trick is way too smart!

Now I MUST admit the this VL is VVVVery powerful. We could use it for the development of the whole APA102 plugin (and can be used also for all this kind of IC led strip changing the RGB frame inside LEDBits.VL):

My idea of inputs of the plugin is:

ABGR | Number of Strips(spreadable) | Number of Led on each Strip(spreadable)

For the arduino/teensy part I could use a CustomEndFrame to split the sequence. This is the hard part I suppose, the hardest is the VL part I’m sure!! :>

Any hints where to start? Patching with new VL nodes? Documentation etc…
PS: Is VL so LOW level to talk directly to the serial port? The bottleneck of this system could be the RS232 node.

EDIT:
Did someone ever use LedEdit 2014? the Realtime play is made with some kind of Screenshot Node and Pipeting the pixel???

Thanks again
Cheers