Hi guys,
Thanks for the help.
I didn't know about the serial monitor feature. Right now I have connected the servo to the Adafruit and then the Arduino board to the computer via USB. I am trying to send the values you mentioned via the serial monitor, buy I get the error message "port 6 not found".
As mentioned before, due to the Adafruit motor shield I modified the code to ports 9 and 10. The problem is that when I try to change the port from 6 to 9 or 10 at the serial monitor it doesn´t allow me to do it.
This is the code I am using with the modifications:
// zoomkat 12-13-11 serial servo (2) test
// for writeMicroseconds, use a value like 1500
// for IDE 1.0
// Powering a servo from the arduino usually DOES NOT WORK.
// two servo setup with two servo commands
// send eight character string like 15001500 or 14501550
// use serial monitor to test
#include <Servo.h>
String readString, servo1, servo2;
Servo myservo1; // create servo object to control a servo
Servo myservo2;
void setup() {
Serial.begin(9600);
myservo1.attach(9); //the pin for the servo control
myservo2.attach(10);
Serial.println("two-servo-test-1.0"); // so I can keep track of what is loaded
}
void loop() {
while (Serial.available()) {
delay(3); //delay to allow buffer to fill
if (Serial.available() >0) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the string readString
}
}
if (readString.length() >0) {
Serial.println(readString); //see what was received
// expect a string like 07002100 containing the two servo positions
servo1 = readString.substring(0, 4); //get the first four characters
servo2 = readString.substring(4, 8); //get the next four characters
Serial.println(servo1); //print to serial monitor to see parsed results
Serial.println(servo2);
int n1 = servo1.toInt();
int n2 = servo2.toInt();
Serial.println("the numbers are :");
Serial.println(n1); //print to serial monitor to see number results
Serial.println(n2);
myservo1.writeMicroseconds(n1); //set servo position
myservo2.writeMicroseconds(n2);
readString="";
}
}
Any idea on how can I use the serial monitor feature if I am using a motor shield?
Thanks!