I'm experimenting with sending data from an Arduino to Processing.  (I had never used

I’m experimenting with sending data from an Arduino to Processing. (I had never used Processing before so decided this would be a fun way to learn it.) Here’s the test I made:


(This test had a 1000ms delay in the loop which is why it might seem to run a bit slow.)

I continuously sent the data out over a serial connection and Processing kept grabbing 4 bytes at a time and displaying it. The bytes I sent were: Pixel number, and HSV values. It worked, but it’s not /really/ what I would like to be able to do. I’d like to send the actual byte steam that is being sent out of the Arduino to the LED strip’s Data and Clock.
I realize that this byte steam varies for different types of LED strips based on the chip type on the strip, so for now I would like to focus just on the APA102 format.

Is there a way I can grab this byte steam that gets sent out to the Data and Clock pins? I’m fine if things have to be run slower then normal or be sent out in chunks or something. I just couldn’t follow the rabbit hole down through the FastLED code to begin to see how this might be done.

Hey man, excellent work! I posted here just a few days ago asking if anyone had any ideas about visualising FastLED output in processing or something similar, with the aim of being able to prepare sequences on the go without strips needing to be attached.

This looks really promising! I have limited experience with processing but I’d love to help you with anything I can. Would you mind sharing your sketch?

I’m also looking at approaching this problem with touchDesigner instead of processing. I’ll post any progress I make here too.

Very nice!
Anything that helps simplify and speed development is great, and this looks very promising!

Nice! I think it’s most easy to make your own bytestream. You have the leds array (CRGB leds[NUM_LEDS];), so you can send the string with the for-loop. You might add some stop byte (or println) and a start byte with the amount of leds. So you can check if everything is received and store it in an Array or ArrayList (dynamic length).

Sending it at more then 60 fps doesn’t make sense, because that is the standard refresh of Processing. However I think with 25/30 fps it will work as well.

Thanks for pointing out getting the colour information from the leds array! I was just trawling through the show() methods in the chipsets classes trying to find fetch the colours from there. This makes way more sense. Now I just have to figure out how to form this bytestream… :smiley:

ok I’ve got the RGB values for the first pixel in the leds array streaming over serial with the following (called in the loop):

Serial.print(leds[1].r);
Serial.print(’,’);
Serial.print(leds[1].g);
Serial.print(’,’);
Serial.println(leds[1].b);

Just need to make this happen for each pixel in the array and then consume it on the processing end.

Will post whatever I end up with tomorrow! It’s late here now :slight_smile:

Probably you don’t need the comma separation.

I think (from reading the documentation) you can send the whole byte array (buffer) at one with the write command:
http://arduino.cc/en/Serial/write

So: Serial.write(leds, NUM_LEDS);

ReadBytesUntil is your friend in Processing:
https://processing.org/reference/libraries/serial/Serial_readBytesUntil_.html

@Corey_Schneider your post was what inspired me to try this out. :slight_smile:

Thanks for the comments and ideas. I’ve worked on it some more and just posted about a new version and provided the code.
https://plus.google.com/110856759083002287912/posts/5SWYRZuaW8h

Hey Marc, just had a look over your sketches and they are great! I reached a similar point with my hacking but took a slightly different approach with the serial printing from the arduino.

I built strings of data for every pixel in the leds array per frame and printed it on a new line and then triggered a serial event callback for each newline character found on the processing end. I’m using processing’s string split functions to explode the ‘pixel strip string’ into an array of arrays of pixel rgb values which I loop over and draw filled rectangles.

I’m not sure which approach is more or less performant or prone to errors at this point. I imagine that printing each pixel data component separately is much faster on the arduino side than building the entire strip to print out on one line…

I’ve learned a lot from your sketches about initialising the serial connection in a reliable way, and it looks like your approach will be more solid in then end, but I’m still going to refine my version a bit more before posting it up here, it might help someone somehow :slight_smile:

I’ll be watching your repo on github to see how you go with your todo list. If I come up with anything useful I’ll open a pull request :wink:

Thanks for sharing your hard work and ideas!

Corey, that’s great you have something working too. Cool!
I wasn’t sure how error prone the serial connection might be or if it would need feed back (call/response) or some sort of error checking. So I just went the easy route first and so far seems to be working. Every once in a long while when I run the Processing sketch it will give an error and stop running right after it connects, but if I just run it again it’s fine.

I originally was manually saving each pixel’s data as I lit stuff and packing the pixel position and three color data bytes into a single packet per pixel to send. Like this:
unsigned long pixelPacket = ((uint32_t)pixelPos << 24)|((uint32_t)hue << 16)|((uint32_t)sat << 8)|val;
But thanks to Kasper and your post I went with simpler “use the leds array that we already have” approach. :slight_smile:

I’ll ping the G+ post when I have updates.

Btw, I looked at the touchDesigner website. It looks like some really neat software, but then I saw the price tag. I’ll have to skip that and keep learning Processing for now. Cool thing is Processing seems to have a large community and collection of tutorials so that’s a bonus.

Hi there, i’ve seen your post and i’m wondering how you managed to read hsv values from serial to the CRGB array struct. Any tip? as i understand the CRGB struct is for RGB…

In this case the FastLED sketch was not reading serial data, but rather sending serial data out to Processing.