» arduino04
This site relies heavily on Javascript. You should enable it if you want the full experience. Learn more.


Reading multiple signals from Arduino serial.

Here I'll show a simple way to extend Mr Benefit's excellent serial reader patch to work with multiple signals, so that if you have a couple of light and proximity sensors and some pots all hooked up in your arduino you can work with all those inputs at once in vvvv.

In a nutshell:

Download the tiki-download_file.php?fileId=955 | the arduino code] and tiki-download_file.php?fileId=954 | the vvvv patch]. Run both and feed something into arduino's analog inputs. Finito.

The circuit:

I'm going to assume you can wire up multiple analog inputs. Look at the arduino tutorials (like this one on reading a potentiometer).

The arduino code:

tiki-download_file.php?fileId=955 | Download the arduino code]

The arduino program looks as follows. Load it into your board.

//Read and send all analog inputs out over serial (e.g. to vvvv).
//Sends a string with the format "an bn cn dn en fn\r\n"
// n is a non-negative decimal number (arbitrary number of digits)
// \r\n is carriage-return and a newline (ascii chars 10, 13)
//example: a812 b20 c3 d1017 e233 f96

void setup()



void loop()

  Serial.print(" ");
  Serial.print(" ");
  Serial.print(" ");
  Serial.print(" ");
  Serial.print(" ");
  Serial.print(" ");
  //print carriage return and newline


Arduino program notes:

  • In contrast with Mr Benefit's code, I have used the new arduino serial library (Serial.begin(baud) and Serial.print()). The older serialWrite() functions are deprecated will eventually be phased out. See the arduino reference
  • Until you have the given system working between arduino and vvvv, don't be tempted to change anything in the code. Debugging this stuff isn't much fun. Once you know you've got a basic program that works, hack away!
  • Key to understanding (but not to using) the pair of programs is the fact that when you call Serial.print() (or the old serialWrite()) and pass it an integer, it generates a string representation of that number, and sends those characters. So Serial.print(203) will send the ascii characters '2', '0', and '3' in 3 consecutive bytes, rather than sending one byte having a literal value of 203. If you wanted to do the latter, you could do Serial.print(203, BYTE). Perhaps a future tutorial will show how do work like that, but not this one.

The vvvv patch:

tiki-download_file.php?fileId=954 | Download the vvvv patch].
I have simply added a regular expression to Mr Benefit's tokenizer-based patch, to split out the various inputs.

Be sure to change the com port on the RS232 (Devices) to match that which your arduino is found on, and the baud rate to 9600 or whatever your arduino code specifies in setup() via Serial.begin(baudRate).

We expect an input string in the format "an bn cn dn en fn\r\n"

  • n is a non-negative decimal number (arbitrary number of digits)
  • \r\n is carriage-return and a newline (ascii chars 10, 13)

An example would be : a34 b200 c1024 d1 e0 f331

One must use an inspector to gain full access to the RegExpr (String). In particular, the pattern itself is only available this way.
The regexp I used was taken almost directly from the vvv regexp faq:

a( \d+ ) \s b( \d+ )\s c( \d+ )\s d( \d+ )\s e( \d+ )\s f( \d+ )

Problems, limitations:

  • In this first version, it is very strict. If it doesn't receive text in the expected format, you will not get ANY of your values from the communication, even if some of them were ok up to a certain point. Be careful when adding or removing inputs.
  • To send less or more, one has to edit the regexp (see regexp faq for a better way)
  • executing a regexp every frame is probably expensive. We could just use a Separate (String) node, and use a separator character, dropping the a, b, c, etc.
  • this is much less efficient than sending values in the bytes. I've

done single-signal comms based on raw values - rather than ascii - from arduino to vvvv but haven't quite figured how to split the signals up again using the available vvvv nodes. If I could just write it in c or whatever, I'd be done already. Using human-readable characters does aid debugging, however.

Update - adding the digital outs

Expanding the communication to include arduino's digital inputs prove to be very simple. I have done this in a naive way, with the upside that it's very easy to follow. Later I have some notes on how it might better be done.

In a nutshell:

get the version 0.2 code -
Here's the arduino sender v0.2] and the tiki-download_file.php?fileId=959 | vvvv receiver v0.2]. Install on arduino and vvvv, adjust your comport as necessary, and start making use of the arduino's digital inputs.

v0.2 Notes

  • The format becomes "an bn cn dn en fn #BBBBBBBBBBBB\r\n" where:
    • n is a non-negative decimal number (arbitrary number of digits)
    • B is a binary digit, 1 or 0
    • \r\n is carriage-return and a newline (ascii chars 10, 13)
    • example:
a812 b20 c3 d1017 e233 f96 #101100100111
  • I naively used a regular expression again where we could instead have split the binary characters with a

Split (String) node, as that section of the string is fixed-width. That would have yielded a spread. There's no need for the '#' character either, other than making it easier for the programmer to tell where the digital stuff starts.

  • having chosen to use RegExpr (String), I hit a limitation of that node - no more than 14 matches. As we have 6 analog inputs and 12 digital inputs (18 signals in the string) it was necessary to take the substring holding the binary inputs, and send it to another regexpr node for splitting. I couldn't find this limitation documented anywhere.
  • we could have the arduino encode the 12 binary values as a single number in decimal from 0 - 2^12 (0-4095) (saving 8 bytes in of comms) and then decode it in vvvv (render the number as a binary string, then split the binary string as normal).
  • I haven't given much thought yet to how you, in the real world, would work with a subset of the arduino's inputs (you'll be using some of the arduino digital pins as outputs, I expect). In the absence of a super-wonderful arduino vvvv node, you can start with this patch and cut out what inputs you don't need, remembering to cut them simultaneously from transmitter (arduino) and receiver (vvvv) to avoid tears.


Some ideas for debugging / understanding these serial-comms patches:

  • Add a 2000ms delay to your arduino loop.
  • Create a MainLoop (VVVV) (unconnected) and set the max foreground fps to something lower. Note that the UI will also become unresponsive as you do this. Note that the rs232 will capture more per frame as you lower the frame rate (given a fixed arduino transmission rate).
  • for more complex regexps, use something like kodos regular expression debugger to develop the regexp, then convert into vvvv's syntax as necessary.


Download tiki-download_file.php?fileId=963 | a zip of all the vvvv-arduino patches] up to this point in this series of tutorials.

Good luck,


back to toc

anonymous user login


~9h ago

joreg: @mediadog: indeed, fixed that!

~9h ago

mediadog: @microdee @joreg Aha! I had glanced at that list, but assignment was lurking beyond the scrollbar. Athankew!

~11h ago

joreg: first-come-first-serve tickets are now sold out except the "delegate" ones. others are still available from here: https://nodeforum.org/journal/node17-tickets/

~11h ago

~13h ago

microdee: @mediadog: default is set via assignment (equal sign)

~22h ago

mediadog: No default for effect parameters, just min and max?

~1d ago

microdee: regular *fcfs tickets for #node17 are already sold out, and non lowered regular ticket isn't available straight from main page

~2d ago

mediadog: @evvvvil Man if that was 10th I want to see 1-9. 4kb, insane!

~2d ago

evvvvil: @sinus, thankx a lot broh! LJ, guy from my group desire, won shader showdown :) couldn't enter as qualifiers were on Friday. Peace

~2d ago

sinus: @evvvvil: great!! nvscene shader live coding 666: https://www.youtube.com/watch?v=O-1zEo7DD8w