Glad to hear it!!
Hi everyone
I'm totally new to robotics and would like to know how to use VarSpeedServo when using Wire library, as my servos will be connected to servo control board.
Below is a simple sketch, can someone add to this sketch the varspeedservo example so I can use it as a template please?
Thanks for any help
#include <Wire.h>
#define ADDRESS 0x61 // The address of the SD21
#define SERVO 0x43
void setup(){
Wire.begin();
}
void loop(){
Wire.beginTransmission(ADDRESS);
Wire.write(SERVO);
Wire.write(255);
Wire.endTransmission();
delay(1000);
}
Hi, i'm new to the Arduino world and need some help understanding this library. i've the done the LED and Servo examples that come standard with the software. My project involves controlling 2 servos with a PS2 controller. i got it working using a modified version of Bill Porter's example sketch that came with his library. but now i'd like to control the speed of the servos. i'm very new to this and wondered if anyone can help me and explain how to use the VarSpeedServo library in layman's terms.
Here's what i have so far, but i get a lot of errors:
#include <VarSpeedServo.h>
#include <PS2X_lib.h> //for v1.6
PS2X ps2x; // create PS2 Controller Class
//right now, the library does NOT support hot pluggable controllers, meaning
//you must always either restart your Arduino after you conect the controller,
//or call config_gamepad(pins) again after connecting the controller.
int error = 0;
byte type = 0;
byte vibrate = 0;
int LX;
int LY;
VarSpeedServo myservo; // create servo object to control a servo
VarSpeedServo myservo2;
void setup(){
Serial.begin(57600);
//CHANGES for v1.6 HERE!!! **************PAY ATTENTION*************
error = ps2x.config_gamepad(13,11,10,12, true, true); //setup pins and settings: GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error
{
myservo.attach(5,0,180); // attaches the servo on pin 9 to the servo object
myservo2.attach(6,0,180);
}
if(error == 0){
Serial.println("Found Controller, configured successful");
Serial.println("Try out all the buttons, X will vibrate the controller, faster as you press harder;");
Serial.println("holding L1 or R1 will print out the analog stick values.");
Serial.println("Go to www.billporter.info for updates and to report bugs.");
}
else if(error == 1)
Serial.println("No controller found, check wiring, see readme.txt to enable debug. visit www.billporter.info for troubleshooting tips");
else if(error == 2)
Serial.println("Controller found but not accepting commands. see readme.txt to enable debug. Visit www.billporter.info for troubleshooting tips");
else if(error == 3)
Serial.println("Controller refusing to enter Pressures mode, may not support it. ");
//Serial.print(ps2x.Analog(1), HEX);
type = ps2x.readType();
switch(type) {
case 0:
Serial.println("Unknown Controller type");
break;
case 1:
Serial.println("DualShock Controller Found");
break;
case 2:
Serial.println("GuitarHero Controller Found");
break;
}
}
void loop(){
/* You must Read Gamepad to get new values
Read GamePad and set vibration values
ps2x.read_gamepad(small motor on/off, larger motor strenght from 0-255)
if you don't enable the rumble, use ps2x.read_gamepad(); with no values
you should call this at least once a second
*/
if(error == 1) //skip loop if no controller found
return;
if(type == 2){ //Guitar Hero Controller
ps2x.read_gamepad(); //read controller
if(ps2x.ButtonPressed(GREEN_FRET))
Serial.println("Green Fret Pressed");
if(ps2x.ButtonPressed(RED_FRET))
Serial.println("Red Fret Pressed");
if(ps2x.ButtonPressed(YELLOW_FRET))
Serial.println("Yellow Fret Pressed");
if(ps2x.ButtonPressed(BLUE_FRET))
Serial.println("Blue Fret Pressed");
if(ps2x.ButtonPressed(ORANGE_FRET))
Serial.println("Orange Fret Pressed");
if(ps2x.ButtonPressed(STAR_POWER))
Serial.println("Star Power Command");
if(ps2x.Button(UP_STRUM)) //will be TRUE as long as button is pressed
Serial.println("Up Strum");
if(ps2x.Button(DOWN_STRUM))
Serial.println("DOWN Strum");
if(ps2x.Button(PSB_START)) //will be TRUE as long as button is pressed
Serial.println("Start is being held");
if(ps2x.Button(PSB_SELECT))
Serial.println("Select is being held");
if(ps2x.Button(ORANGE_FRET)) // print stick value IF TRUE
{
Serial.print("Wammy Bar Position:");
Serial.println(ps2x.Analog(WHAMMY_BAR), DEC);
}
}
else { //DualShock Controller
ps2x.read_gamepad(false, vibrate); //read controller and set large motor to spin at 'vibrate' speed
if(ps2x.Button(PSS_LY))
LY = ps2x.Button(PSS_LY);
{
LY = map(ps2x.Analog(PSS_LY), 0, 255, 0, 180); // scale it to use it with the servo (value between 0 and 180)
myservo.slowmove(LY,0);
delay(15); // waits for the servo to get there
}
if(ps2x.Button(PSS_LX))
LX = ps2x.Button(PSS_LX); // reads the value of the potentiometer (value between 0 and 1023)
{
LX = map(ps2x.Analog(PSS_LX), 0, 255, 0, 180); // scale it to use it with the servo (value between 0 and 180)
myservo2.slowmove(LX,0);
delay(15);
}
}
delay(50);
}
i get a lot of errors
Sadly, no members of the Arduino forum that I know are trained in Telepathy so unless you post what the errors are we really can't be of much help ![]()
Your code complied fine on my computer (I have the library's installed). My guess, would be that you installed one of your library's wrong or you need to update them to make them compatible with the new version of Arduino IDE (assuming your running it).
my bad. here's the errors i get. ill try to reinstall the library.
ps2x_varspeed_test:16: error: 'Servo' does not name a type
ps2x_varspeed_test:17: error: 'Servo' does not name a type
ps2x_varspeed_test.ino: In function 'void setup()':
ps2x_varspeed_test:27: error: 'myservo' was not declared in this scope
ps2x_varspeed_test:28: error: 'myservo2' was not declared in this scope
ps2x_varspeed_test.ino: In function 'void loop()':
ps2x_varspeed_test:126: error: 'myservo' was not declared in this scope
ps2x_varspeed_test:134: error: 'myservo2' was not declared in this scope
Hi there, first of all - thanks for this great lib.
it is working nicely in my project.
i controll 3 servos to adjust 3 pots of an amp with an arduino nano.
the only issue i am having (same as with the original servo lib) is that attaching a servo causes it to go to middle position with full speed.
i really cant have that
the servos have to stay in the position they where when switched off.
otherwise the movement is too fast for the pots and could do some damage.
so is there a way to prevent that middle position when attaching a servo or at least do it in slow speed ?
i am really new to all this... so,
any help appreciated.
cheers
-------> EDIT:
kinda solved it, when i figured only writeMicroseconds can override the middle position after attach,
slowmove cant and write probably cant too...
so i can store the position of the servos after each move to eeprom and write it back in void setup before attaching the servos.
Sketches with the library compile under Arduino UNO, but won't as Arduino DUE...
zilch:
kinda solved it, when i figured only writeMicroseconds can override the middle position after attach,
slowmove cant and write probably cant too...
so i can store the position of the servos after each move to eeprom and write it back in void setup before attaching the servos.
That would have been my suggestion, too. Note that the eeprom is not infinitly rewritable ("The EEPROM has an endurance of at least 100,000 write/erase cycles" in the spec), so add in a some "filtering" so you only store when there has been a great enough move from previous stored value if you do this many times a second. (one million seconds is 11+ days)
hi trying to use this code to move a servo with a remote control, an i want the speed to be slower, can you see any problems please,
#include <Servo.h>
#include <IRremote.h>
#include <VarSpeedServo.h>
unsigned long Value2 = 0xFFE01F; // where XXXXXXXX is on our your remote's values. We will call this Value 1
unsigned long Value1 = 0xFF609F; // where XXXXXXXX is another button on your remote
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
VarSpeedServo myServo;
// the setup routine runs once when you press reset:
void setup() {
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
// initialize the digital pin as an output.
myServo.attach (10, 1, 179); // attack servo to digital pin 10 min 1 max 180
}
// the loop routine runs over and over again forever:
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
if(results.value == Value1) {
myServo.slowmove (180, 30); //pos 180 speed 30
}
if(results.value == Value2) {
myServo.slowmove (1, 40);
}
}
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Arduino: 1.0.6 (Windows 7), Board: "Arduino Uno"
In file included from servoIRmove.ino:4:
C:\Program Files\Arduino\libraries\VarSpeedServo/VarSpeedServo.h:96: error: conflicting declaration '_timer1'
C:\Program Files\Arduino\libraries\Servo/Servo.h:83: error: '_timer1' has a previous declaration as 'timer16_Sequence_t _timer1'
C:\Program Files\Arduino\libraries\VarSpeedServo/VarSpeedServo.h:96: error: conflicting declaration '_Nbr_16timers'
C:\Program Files\Arduino\libraries\Servo/Servo.h:83: error: '_Nbr_16timers' has a previous declaration as 'timer16_Sequence_t _Nbr_16timers'
C:\Program Files\Arduino\libraries\VarSpeedServo/VarSpeedServo.h:96: error: conflicting declaration 'typedef enum timer16_Sequence_t timer16_Sequence_t'
C:\Program Files\Arduino\libraries\Servo/Servo.h:83: error: 'timer16_Sequence_t' has a previous declaration as 'typedef enum timer16_Sequence_t timer16_Sequence_t'
C:\Program Files\Arduino\libraries\VarSpeedServo/VarSpeedServo.h:114: error: conflicting declaration 'typedef struct ServoPin_t ServoPin_t'
C:\Program Files\Arduino\libraries\Servo/Servo.h:101: error: 'ServoPin_t' has a previous declaration as 'typedef struct ServoPin_t ServoPin_t'
C:\Program Files\Arduino\libraries\VarSpeedServo/VarSpeedServo.h:121: error: conflicting declaration 'typedef struct servo_t servo_t'
C:\Program Files\Arduino\libraries\Servo/Servo.h:106: error: 'servo_t' has a previous declaration as 'typedef struct servo_t servo_t'
DON'T include Servo.h - It causes this issue.
Thank you for building this lib file.
When I compile the file, this massage occur:
D:\arduino-1.5.2\libraries\VarSpeedServoMaster\VarSpeedServo.cpp:71: fatal error: avr/interrupt.h: No such file or directory
But the interrupt.h is in the "D:\arduino-1.5.2\hardware\tools\avr\avr\include\avr" , is there any advise?
Thank you
Hello Korman ,
Nice job first off all
!
Can you tell me what will happen if we use false as third parameter in write function, and then without much delay will overwrite something else on the same servo pin of arduino, will the first one will complete before start of second or will skip that and start second ??
Thanking you in anticipation
This is useful.
This is cool and versatile.
Is there a way that I can use <virtualwire.h> and <varspeedservo.h> libraries simultaneously as both use timer1
Currently I use <servotimer2.h> library but it has no speed control
Is there any <varspeedservo.h> library which use timer2
Thanks
Just so I don't end up with an out-of-date version, is that one attached to the opening post, still current? Or did I miss a newer one attached somewhere in the 4 pages of posts? Or maybe there's an update on github or somewhere?
Hi all,
New person to the Arduino and software here.
I noticed the command has a function to let the servo finish to the end, before continueing.
I cannot find what the feedback is to the 'Finished servo'.
will the function continue reading the remainder of the loop or will the next item interfere?
Having some trouble understanding the inner functional working.
annybody can shine a light on this?
as background, after one run, i need to wait a moment, before the next run.
so i need the servo feedback, as the speed of the servo may vary (and thus the time it takes).
regards,
Vincent
![]()
so i need the servo feedback,
What servo are you using that provides feedback?
not from the servo.
![]()
Hi, I'm trying to run this code with the VarSpeedServo.h:
#include <VarSpeedServo.h>
VarSpeedServo myservo; // create servo object to control a servo
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
myservo.write(180, 30, true); // move to 180 degrees, use a speed of 30, wait until move is complete
myservo.write(0, 30, true); // move to 0 degrees, use a speed of 30, wait until move is complete
}
===>but is giving the following error:
Arduino: 1.6.5 (Windows 7), Placa:"Arduino/Genuino Uno"
sketch_sep19g.ino: In function 'void loop()':
sketch_sep19g:10: error: no matching function for call to 'VarSpeedServo::write(int, int, bool)'
sketch_sep19g.ino:10:30: note: candidate is:
In file included from sketch_sep19g.ino:1:0:
C:\Users\usuario\Documents\Arduino\libraries\VarSpeedServo/VarSpeedServo.h:130:8: note: void VarSpeedServo::write(int)
void write(int value); // if value is < 200 its treated as an angle, otherwise as pulse width in microseconds
^
C:\Users\usuario\Documents\Arduino\libraries\VarSpeedServo/VarSpeedServo.h:130:8: note: candidate expects 1 argument, 3 provided
sketch_sep19g:11: error: no matching function for call to 'VarSpeedServo::write(int, int, bool)'
sketch_sep19g.ino:11:28: note: candidate is:
In file included from sketch_sep19g.ino:1:0:
C:\Users\usuario\Documents\Arduino\libraries\VarSpeedServo/VarSpeedServo.h:130:8: note: void VarSpeedServo::write(int)
void write(int value); // if value is < 200 its treated as an angle, otherwise as pulse width in microseconds
^
C:\Users\usuario\Documents\Arduino\libraries\VarSpeedServo/VarSpeedServo.h:130:8: note: candidate expects 1 argument, 3 provided
Multiple libraries were found for "VarSpeedServo.h"
Used: C:\Users\usuario\Documents\Arduino\libraries\VarSpeedServo
Not used: C:\Program Files (x86)\Arduino\libraries\VarSpeedServo
no matching function for call to 'VarSpeedServo::write(int, int, bool)'
====>someone could help me, please!