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.
//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() {
Serial.begin(9600);
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: ");
Serial.println(n);
if(readString.indexOf('a') >0) myservoa.writeMicroseconds(n);
}
else
{
Serial.print("writing Angle: ");
Serial.println(n);
if(readString.indexOf('a') >0) myservoa.write(n);
}
readString=""; //clears variable for new input
}
}
else {
readString += c; //makes the string readString
}
}
}
rs232_arduino.v4p (14.1 KB)