» 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

16:56, 10.09.10

16:53, 10.09.10

sunep: I believe I remember a contrast shader somewhere but I can't find it, someone with better shaderfinding skills than me?

12:59, 10.09.10

12:41, 10.09.10

vvvvebmaster: Spamfilter seems to block a lot of legitimate content, so it is deactivated as of now. Sorry for the inconvenience.

00:08, 10.09.10

skyliner: amazing schedule! i am pretty excited!!!

22:12, 09.09.10

22:12, 09.09.10

karistouf: hi ! i m spamed by IP !

21:21, 09.09.10

matka: this weekend I'm moving to Barcelona, would be cool to catch up with some vvvv users if you're up give me a touch

17:58, 09.09.10

rrrr: fresh vvvv,after splash screen i get 'application error','exception EintOverflow in module vvvv.exe at 00300F3D.Integer overflow.halp!

14:51, 09.09.10

stephan_grosse8: we are looking for someone interested in an internship for getting in contact with v4 ?