I am a bit stumped on something and have been using the Servo Sweep example to try to figure something out.
Like all servos, the servos I have start in a neutral position and can go 90 degrees left or 90 degrees right.
In the Sweep example, it does as it should, goes back and forth thru 180 degrees of motion.
I have the servo attached to a linkage I want to move back and forth. It can't go all the way to the left or right due to physical limitations of what I want moved.
As such, I am trying to figure out what the "numbers" would be for that far left and far right position.
I don't see any way to have a message box (or the sort) display, while moving, what "position" the Arduino is sending/reading from the servo potentiometer.
Asides removing the servo horn and manipulating the location manually...I can't think of any other way to do this?
Servo test code you can use to determine the servo limit values in your setup.
// zoomkat 10-22-11 serial servo test
// type servo position 0 to 180 in serial monitor
// or for writeMicroseconds, use a value like 1500
// for IDE 0022 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.
String readString;
#include <Servo.h>
Servo myservo; // create servo object to control a servo
void setup() {
Serial.begin(9600);
myservo.writeMicroseconds(1500); //set initial servo position if desired
myservo.attach(7); //the pin for the servo control
Serial.println("servo-test-22-dual-input"); // so I can keep track of what is loaded
}
void loop() {
while (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the string readString
delay(2); //slow looping to allow buffer to fill with next character
}
if (readString.length() >0) {
Serial.println(readString); //so you can see the captured string
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);
myservo.writeMicroseconds(n);
}
else
{
Serial.print("writing Angle: ");
Serial.println(n);
myservo.write(n);
}
readString=""; //empty for next input
}
}
I don't see any way to have a message box (or the sort) display, while moving, what "position" the Arduino is sending/reading from the servo potentiometer.
That is because it is not reading the pot. A servo has self contained electronics that do this. All it does is respond to a signal the arduino generates.
You can put a pot on yourself to monitor the real movement or use a rotory encoder.