Go Down

Topic: vvvv to arduino using serial (Read 609 times) previous topic - next topic


Im having a very hard time trying to get any usable input over the serial port to arduino from vvvv.  I have included 2 my test patch and some code that zoomkat work on for something else that I thought I could modify.  I get some servo movement but usually as soon as I start my connection from vvvv everything on the screen freezes. I only need to get in a few float values to arduino to control some servos and latter positions of some stepper motors.  Please anyone else who may have dealt with this before and has a a solution then Id be very grateful.
Below is the code so far and attached is the v4 patch to go with it.  Its quite specific to VVVV so I hope Im posting in the right place.

Code: [Select]
//zoomkat 11-22-12 simple delimited ',' string parse
//from serial port input (via serial monitor)
//and print result out serial port
//multi servos added

String readString;
#include <Servo.h>
Servo myservoa;  // create servo object to control a servo

void setup() {

  myservoa.writeMicroseconds(1500); //set initial servo position if desired

  myservoa.attach(9);  //the pin for the servod control
  Serial.println("TESTME"); // so I can keep track of what is loaded

void loop() {

  //expect single strings like 700a, or 1500c, or 2000d,
  //or like 30c, or 90a, or 180d,
  //or combined like 30c,180b,70a,120d,

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == ',') {
      if (readString.length() >1) {
        //Serial.println(readString); //prints string to serial port out

        int n = readString.toInt();  //convert readString into a number

        // auto select appropriate value, copied from someone elses code.
        if(n >= 500)
         Serial.print("writing Microseconds: ");
          if(readString.indexOf('a') >0) myservoa.writeMicroseconds(n);
         Serial.print("writing Angle: ");
          if(readString.indexOf('a') >0) myservoa.write(n);
         readString=""; //clears variable for new input
    else {     
     readString += c; //makes the string readString


It's probably because you're using the String class. Although it's included in the IDE, it's a very bad class for a microcontroller environment (which don't have a memory management unit) and because the IDEs up to at least 1.0.3 have a bug in the free() function of the C library (think of it being part of the compiler) it produces a memory leak. Almost every sketch that uses the class will produce unexpected behavior sooner or later. So get rid of it. Use standard C character arrays instead.


You're not going to get much help from anyone other than zoomkat. S/He is one of the few who recommend using the String object.


as soon as I start my connection from vvvv everything on the screen freezes.

I don't know what vvvv is but presumably it's something that runs on the PC. Is it the PC screen that is freezing?
I only provide help via the forum - please do not contact me for private consultancy.


vvvv is a graphical programming environment like puredata or maxmsp
I got a little further with a new power supply, which seemed to stop the hanging as I guess I was under powering this little servo(micro servo).  Anyway with a simple test program on the arduino I as testing v4 ability to send out us full information over the rs232 and its seems its just not able to send consistent data and therefore I can use it at the moment.  Ill be resorting to using 2 Arduinos and firmata on one and analog to the other for now as I cant fix what ever string sending issues..Could be so easy but its not

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131