Hello everyone, I got my servo attached to my Arduino Uno and tested with the following code:
#include <VarSpeedServo.h>
VarSpeedServo MyServo; // servo objects
int servoSpeeds = 1; // sweep speed, 1 is slowest, 255 fastest)
int servoMinPosition = 0; // the minumum servo angle
int servoMaxPosition = 360; // the maximum servo angle
void setup()
{
MyServo.attach(9);
MyServo.slowmove(servoMinPosition,servoSpeeds) ; // start sweeping from min position
}
void loop()
{
// sweep the servos
if( MyServo.read() == servoMinPosition)
{
MyServo.slowmove(servoMaxPosition,servoSpeeds) ;
}
else if( MyServo.read() == servoMaxPosition)
{
MyServo.slowmove(servoMinPosition,servoSpeeds) ;
}
}
unfortunately, Im not clear how to get this servo to slow down. Right now its just spinning with reckless abandon. Ideally, I'd like it to just spin like a lazy susan so I can plop a small resin figurine on top and let it spin. This is all part of a larger project, but i'm trying to get this done bit by bit.
Does anyone have any experience with controlling the speed of a micro-servo? The speed im looking for is exactly like:
A continuous rotation servo does not respond the way it looks like your code, and you, are expecting.
Write 90 to stop.
Values less than 90 will make it go one way, the further away from 90 the faster.
Values greater than 90 will make it go the other way, the further away from 90 the faster.
So 70 might be slow CCW motion, and 110 slow CW motion.
Experiment. Learn.
Lastly, read() only reports what you last wrote. For no kind of cheap servo can it actually report where the servo is. Only tells you what you already know - the last thing you wrote.
I'd like to learn more about what you mean by this? Write 90 to stop? I've been tinkering around with min and max positions. I'm wondering if i could create a "slow effect" by introducing a delay in the loop?
Also, I'm ready to delete that read () function, once i figure out how to extricate it without breaking the code. I actually just took this code from an article on servo examples.
If you make the 5000 larger, it should just go in that direction longer.
If that's what you find, now we should start talking about what you want this to do. Maybe you already siad.
But it you are expecting to be able to turn accurately to a point, or go in exactly a number of degrees like three rotations, I think you'll have to add to the hardware some kind of means to detect when you've arrived.
If you can be happy with 180 degrees end to end, or some servos will do a bit more close to 360, you'll want to switch to a regular "goes where you tell it" servo.
Here's a simple test pgm, you can get better resolution with "servo.write microSeconds":
/*
Try this test sketch with the Servo library to see how your
servo responds to different settings, type a position
(0 to 180) or if you type a number greater than 180 it will be
interpreted as microseconds(544 to 2400), in the top of serial
monitor and hit [ENTER], start at 90 (or 1472) and work your
way toward zero (544) 5 degrees (or 50 micros) at a time, then
toward 180 (2400).
*/
#include <Servo.h>
Servo servo;
void setup() {
// initialize serial:
Serial.begin(9600); //set serial monitor baud rate to match
servo.write(90);
servo.attach(9);
prntIt();
}
void loop() {
// if there's any serial available, read it:
while (Serial.available() > 0) {
// look for the next valid integer in the incoming serial stream:
int pos = Serial.parseInt();
pos = constrain(pos, 0, 2400);
servo.write(pos);
prntIt();
}
}
void prntIt()
{
Serial.print(" degrees = ");
Serial.print(servo.read());
Serial.print("\t");
Serial.print("microseconds = ");
Serial.println(servo.readMicroseconds());
}
Now that you know how to make the motor stop and go, post your attempt to make it go when one thing happens (like pressing a button) and stop when something else happens (like pressing another button, or seeing that a certain time has elapsed).
Sorry, I mean to say I'm still in the dark how to accomplish all this. But thats my ultimate goal with the servo. I should mention, that button I mentioned earlier is going to be doing triple duty (I'm hoping it will trigger that servo, an audio file and some led lights all at once)
I'm beginning to wonder if a stepper motor with a stepper motor driver would be a far easier solution. I was reading more about the pros and cons of using a stepper motor vs a servo motor and the biggest thing that caught my eye was the "In overall performance, servo motors are best for high speed, high torque applications while stepper motors are better suited for lower acceleration". So I think I'll probably just switch gears and control the motor with a driver board.