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

arduino03

French

02 send and receive data from/to arduino

In this example we control an LED (red one in the picture) with a poti - everything via some logic in a VVVV patch.

Very short spoken we do: poti > arduino > vvvv (calculate: is LED on/off?) > arduino > control LED

That means we have to do:

  • connect a poti to the board. middle cable from the poti to analog input pin 5, left and right to GND and 5V. (analog input pins can "read" a voltage between 0-5 volt in resolution of 10bit = 0-1023)
  • send the value to vvvv
  • calculate on/off?
    • if value is below 512 = led is off
    • else = led is on
  • send data back to the board
  • depending on the data from vvvv: switch led on pin 13 on/off

Make sure to upload this code to the arduino board:

/* send/recieve data to/from vvvv
 * -----------
 *
 * poti --> arduino --> vvvv --> arduino --> control LED
 * 17-01-2006
 * copyleft 2006 benedikt gross
 * 
 * Last edit Westbam 20-08-2009, for new Serial. code.
 *
 */
 
int potPin = 5; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int val,serialGet = 0; // variable to store the value coming from the sensor/serial port (from vvvv)
int delaytime = 1; // delay time for the main loop
 
 
void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT
Serial.begin(9600); // use the serial port to send/recieve values to/from the computer
}
 
void loop() {
val = analogRead(potPin); // read the value from the potentiometer
 
Serial.print (val); // print the value to the serial port
//linebreak
Serial.write(10);
Serial.write(13);
 
// read the serial port
serialGet = Serial.read();
 
// if the input is '-1' then there is no data
// at the input, otherwise store it
if (serialGet != -1) {
val = serialGet;
}
 
// if the stored value is 'H' turn the LED on
// if the stored value is 'L' turn the LED off
if (val == 'H') {
digitalWrite(ledPin, HIGH);
}
else if (val == 'L') {
digitalWrite(ledPin, LOW);
}
 
delay(delaytime);
}

See how to connect the poti, middle pin of the poti to analog in 5, the outer pins to GND and 5v. If you reverse, the graph in the patch also reverses.

And here the patch, don't forget to set the correct com in the RS232 node.

back to toc

anonymous user login

Shoutbox

~5h ago

mediadog: Anyone going to SxSW next month?

~1d ago

alg: @elliotwoods ok, thx. I will pull it and check )

~1d ago

elliotwoods: now i've moved i'm pretty happy. a bit more complicated to manage an open source contrib, but easier to build/update/addonpack

~2d ago

alg: @elliot when you planning to push the changes to the repo?

~2d ago

elliotwoods: and we're back. :). @dujoducom - elias + co did an awesome job!

~2d ago

dujoducom: wow, I have been away for awhile and totally missed the plugin development improvements. Mind bogglingly awesome c# integration!!

~2d ago

elliotwoods: p.s. everyone, please dont comment on the opencv contrib for a moment! slow connection from far away :)

~2d ago

elliotwoods: @vvvvebmaster. if someone edits a post whilst i'm uploading a contrib, i have to reupload. also a comment counts as an edit..