Sending serial data in one 'chunk'


So i can send serial data to update LEDs from Processing to my Arduino. Currently I'm sending it like this from Processing:


I'm running that code 25 times to refresh all my LEDs. Basically, I've maxed out the baud and i'm not getting the quickness to refresh the LEDs fast enough.

Would it be faster doing something like this?

port.write(str(r)+","+str(g)+","+str(b),str(r)+","+str(g)+","+str(b),str(r)+","+str(g)+","+str(b),str(r)+","+str(g)+","+str(b), etc etc);

Essentially sending all the data i need for one full refresh of the LEDs in one chunk. Then i'd have to split the 'chunk' in arduino using the commas. If this would be faster, is there I way i can shove all the data into an array? So to access the blue value of LED 3, i'd reference ledArray[8]? I know you can do this in Processing using split(), but i've no idea in arduino!

Any suggestions would be awesome!

Your PC and your Arduino are much fatster than the serial connection, so if the serial is the bottleneck then there's not much to do.

Also remember that Arduinos serial buffer is only 128 bytes.

How many LED's do you have, and how often do you want to refresh them ?

I assume they are RGB led's and each needs 3 bytes to define it's color ???

I only have 25 LEDs! :cold_sweat: Ha. Yes, the 3 bytes are to define the colors. I'd like to refresh them... at a guess every 1 ms... The fading in lasts about 250 ms but they don't really fade in, they just get brighter in 3 or 4 stages. So do you think that's as fast as I'll be able to get it? I'm guessing there's no other live methods for communication between Processing and an arduino? Thanks for the reply!

That would be 25 * 3 * 1000 * 8 bits/sec or 600kbs thats a bit fast for the standard serial i think.

This might be interesting:

Thanks for that! After a bit of messing about I've decided I'm going to implement this a different way. Instead of sending serial data constantly to update the LEDs, I'm going to have a bunch of transitions in arduino which can be activated by processing and which are passed data, for example for a pulse effect, fade in time, fade out time, colour and duration. That way I'm sending minimal data and updating the LEDs is lightning quick too! :smiley: Thanks!

Thats sounds a lot smarter