Hi
I'm trying to control a servo with the arduino sweep example code. It has alredy worked but after a while the servo stoped reacting. I've tried different servos and got the same result. I also tried the knob example and with that code it worked perfectly. It still doesn't work with the sweep example.
I'm using arduino duemilanove bord with an atmega328 and arduino 1,0 software.
Try the suggestions in the two links in my signature
Duane B
Didn't work, i tried it with 3 different servos but thank you anyway.
Did you remember to connect the grounds?
Yes I did
I tried it on a different computer and it worked. So I guess there is a problem with the arduino software on my computer.
Simple servo test code that might be useful.
// 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 updated my whole sistem and now it works again.
I had exactly the same thing yesterday. Also solved it by updating and rebooting. It's a shame I cannot reproduce the issue anymore... Would be interesting to know what happened... Maybe the serial driver in the kernel was updated... I've had issues with serial ports between software updates and reboots before. Although in this case the serial appeared to be working (I even uploaded a new sketch, thinking of it now I never verified that the sketch was indeed running correctly... should have put some serial prints in there). Possibly the usb did not provide enough power triggering reboots on the arduino or something like that?