Really Simple Servo Questions

Hello! This is my first time working with the Arduino (Duemilanove) and I'm trying to figure out how to wire 16 servos (Futaba S3003) to be controlled individually. I have two Arduino boards, the Arduino 0013 software, and a deadline on March 10.

Thus, a couple questions which may make many of you scoff at my intelligence:

Why is it that I can only control servos with pins 9 and 10?

I have downloaded the servo library to the correct location, but even when I use the code from here (Arduino Playground - HomePage), I get a compiling error which looks a bit like this:

"

In file included from C:\Documents and Settings\US Student\Desktop\arduino-0013\hardware\cores\arduino/WProgram.h:4,

c:/documents and settings/us student/desktop/arduino-0013/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected unqualified-id before 'int'

c:/documents and settings/us student/desktop/arduino-0013/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected `)' before 'int'

c:/documents and settings/us student/desktop/arduino-0013/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected `)' before 'int'

In file included from C:\Documents and Settings\US Student\Desktop\arduino-0013\hardware\cores\arduino/WProgram.h:6,

"

I get a similar error when I use other codes, such as those from here (Hobby Robotics » Controlling Servos with Arduino) and here (http://itp.nyu.edu/physcomp/Labs/Servo)

Why?

I'd appreciate any help (:

I'm having exactly the same problem. I need to drive several servos, and Arduino 0013 + the new servo library doens't work.
I get the same error. Maybe I'll try to downgrade to 0012 and try...

Arduino 0013 includes a library called servo . This can only drive two servos on pins 9 and 10 – you can read about it here: http://www.arduino.cc/en/Reference/Servo

If you want to use the playground software servo code linked in the first post, you need to give the library a different name so it doesn’t conflict with the official servo library.

Create a directory called SoftServo and copy the software servo files.
Rename servo.cpp to SoftServo.cpp and servo.h to SoftServo.h
In SoftServo.cpp change #include <Servo.h> to #include <SoftServo.h>
In SoftServo.h change #include <wiring.h> to #include <WProgram.h>

The example sketch should now compile

Running 16 servos using that code will not leave much time to do anything else. Indeed, I would think that 8 servos would be the most that could be handled and you would still have little if any time available to do any other work.

There is a library discussed in this thread that can drive up to 8 servos in the background: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1230479947

I hope that helps

Ok, I will try reinstalling 0013 and following your directions. I only need to drive 4-6 servos, I hope it works.
Thanks for your quick reply!!
Best regards.
Eduardo

Hi Eduardo, bear in mind that half of the available processing time will be tied up driving servos if you use the software library. If this is not acceptable then you should look at using the ServoTimer2 hardware library I linked at the end of my post.

I am right now reading the ServoTimer2 library you posted. It seems easy to integrate!

Firstly I will try to get everything COMPILING ok, and then I will try to improve the result.

Actually, my sketch does not do much more than listening to serial port and moving servos according to received commands... But any improvement will worth.
Thanks again!
Eduardo

Eduardo, for your application either the software library or ServoTimer2 should be ok.

Have fun!

Mem, I'm having trouble to compile the ServoTimer2 library.
The error is the same in 0012 and 0013:

ServoTimer2.cpp:18: error: 'servo_t' does not name a type
ServoTimer2.cpp: In function 'void __vector_9()':
ServoTimer2.cpp:28: error: 'servos' was not declared in this scope
ServoTimer2.cpp:41: error: 'NBR_CHANNELS' was not declared in this scope
ServoTimer2.cpp: At global scope:
ServoTimer2.cpp:51: error: 'ServoTimer2' has not been declared
ServoTimer2.cpp:51: error: ISO C++ forbids declaration of 'ServoTimer2' with no type
ServoTimer2.cpp: In function 'int ServoTimer2()':
ServoTimer2.cpp:53: error: 'NBR_CHANNELS' was not declared in this scope
ServoTimer2.cpp:54: error: invalid use of 'this' in non-member function
ServoTimer2.cpp:56: error: invalid use of 'this' in non-member function
ServoTimer2.cpp:57: warning: no return statement in function returning non-void
ServoTimer2.cpp: At global scope:
ServoTimer2.cpp:58: error: 'ServoTimer2' is not a class or namespace
ServoTimer2.cpp: In function 'uint8_t attach(int)':
ServoTimer2.cpp:62: error: invalid use of 'this' in non-member function
ServoTimer2.cpp:66: error: 'servos' was not declared in this scope
ServoTimer2.cpp:66: error: invalid use of 'this' in non-member function
ServoTimer2.cpp:67: error: invalid use of 'this' in non-member function
ServoTimer2.cpp:69: error: invalid use of 'this' in non-member function
ServoTimer2.cpp: At global scope:
ServoTimer2.cpp:72: error: 'ServoTimer2' is not a class or namespace
ServoTimer2.cpp: In function 'void detach()':
ServoTimer2.cpp:74: error: 'servos' was not declared in this scope
ServoTimer2.cpp:74: error: invalid use of 'this' in non-member function
ServoTimer2.cpp: At global scope:
ServoTimer2.cpp:77: error: 'ServoTimer2' is not a class or namespace
ServoTimer2.cpp: In function 'void write(int)':
ServoTimer2.cpp:79: error: invalid use of 'this' in non-member function
ServoTimer2.cpp: At global scope:
ServoTimer2.cpp:82: error: 'ServoTimer2' is not a class or namespace
ServoTimer2.cpp: In function 'int read()':
ServoTimer2.cpp:85: error: invalid use of 'this' in non-member function
ServoTimer2.cpp:86: error: 'servos' was not declared in this scope
ServoTimer2.cpp:86: error: invalid use of 'this' in non-member function
ServoTimer2.cpp:86: error: invalid use of 'this' in non-member function
ServoTimer2.cpp: At global scope:
ServoTimer2.cpp:92: error: 'ServoTimer2' is not a class or namespace
ServoTimer2.cpp: In function 'boolean attached()':
ServoTimer2.cpp:94: error: 'servos' was not declared in this scope
ServoTimer2.cpp:94: error: invalid use of 'this' in non-member function
ServoTimer2.cpp: In function 'void writeChan(uint8_t, int)':
ServoTimer2.cpp:100: error: 'NBR_CHANNELS' was not declared in this scope
ServoTimer2.cpp:102: error: 'MIN_PULSE_WIDTH' was not declared in this scope
ServoTimer2.cpp:104: error: 'MAX_PULSE_WIDTH' was not declared in this scope
ServoTimer2.cpp:108: error: 'servos' was not declared in this scope
ServoTimer2.cpp: In function 'void initISR()':
ServoTimer2.cpp:115: error: 'NBR_CHANNELS' was not declared in this scope
ServoTimer2.cpp:116: error: 'DEFAULT_PULSE_WIDTH' was not declared in this scope
ServoTimer2.cpp:118: error: 'servos' was not declared in this scope
ServoTimer2.cpp:118: error: 'NBR_CHANNELS' was not declared in this scope
ServoTimer2.cpp:118: error: 'DEFAULT_PULSE_WIDTH' was not declared in this scope

I corrected the "}" error.

What can be happening?
The arduino installation was absolutely clean both in 0012 and 0013.

Thanks in advance.
Eduardo

The header file is not being found. Did you download and unzip these files: http://www.arduino.cc/playground/uploads/Main/ServoTimer2.zip

It is in a link towards the end of the thread I posted above.

SORRY!!!! The .h file was empty! It was my mistake while cut&copying...
Now it compiled OK bth in 0012 and 0013!!

Thanks!!!
Eduardo

I'm fairly certain I'll be using a different code. I was just testing with that one.

Thanks a ton! (:
I'll sure be trying that tomorrow.

I don't like the new official library. The old one stacked the outputs so that the max it could take is 3ms, with a 30ms gap that leaves plenty of time.

Hi p07gbar, I am not clear what you are saying, I wonder if you could clarify.

Is the 'old' library you are referring to ServoTimer1? If so, it is based on and appears looks functionally identical to the official servo library that distributed with 0012 and later. Or are you refering to another library?

Could you clarify: “The old one stacked the outputs so that the max it could take is 3ms, with a 30ms gap that leaves plenty of time.”

What takes 3ms? The code looks like it has a 20ms frame rate, what is the 30ms gap?