When I connect one servo (to pin 9 or 10) using the hardware Servo library, it works exactly as expected. However, when I add another servo it begins to fail. I feel I should explain that one of the servos has been modified for continuous rotation, but either way when 1 is attached it works as expected whether it be to a certain angle or a certain direction. Anyway, when I attach the second servo, it seems that only one of the servos takes commands, and not reliably anyway. Here’s my code:
#define MAXANGLE 90
#define MINANGLE -90
WiiChuck chuck = WiiChuck();
xVal = chuck.readJoyX();
xVal = map(-xVal, -98, 105, 0, 181);
yVal = chuck.readJoyY();
Serial.print(" /|/ ");
yVal = map(yVal,-110,110,0,181);
The idea is to use the read the joystick from the WiiChuck and map the X data to the normal servo and set the Y data to be the direction and speed of the continuous servo. What actually happens is the continuous servo seems to take all the data from both and use the X and the Y input as its parameters. The normal servo just sits there, twitching occasionally. Any ideas?
The Serial.print statements just let me know that the joystick is reliably sending the right data and if it is mapped correctly.
How are you supplying power to the two servos? Trying to operate two servos from the Arduino's internal 5vdc is typically a problem, too much current required.
As lefty says, you probably need an external power supply.
BTW, there is no point sending values greater than 180 degrees to the servo, the library will not drive a servo with a value higher than 180. But if you want to increase the servo range you can set a min and max value with the attach method. See the Servo reference for more on this.
Thanks guys for the responses, heres some of the info you wanted. It doesnt matter what I use to power them (I think). I had a couple of nine volts in parallel going to a 7805 to power them, so I expect thats enough power. If not, I can get a wall wart, let me know what you think. Also, the values from the joystick are from mapped from joy(min max) to (0 180), assuming I read the documentation correctly and map() works as (int tochange, current min, current max, desired min, desired max + 1). Maybe it's -1 and that's the problem?
A 7805 can supply a maximum of one amp and two servos can easily draw more then that during certain situations. I would recommend on having at least one amp of power capacity for each servo you wish to use. If you can research the specific servos you own they might have a data sheet giving the range of power current they can draw.
Yeah, if you happen to have the datasheet that would be good :) I got these from Sparkfun, and unfortunately they have no link to a datasheet and the company appears to have none as well. Here's the Sparkfun page if you would like.