Go Down

Topic: 2 tests and 2 failures - what am I doing wrong? (Read 2041 times) previous topic - next topic

mem

You may want to try the MegaServo library,  you can use the same code but any pin will work.

http://www.arduino.cc/playground/Code/MegaServo

RuggedCircuits

Well, there is a line in the Servo.cpp, in Servo::attach,  that says:
Code: [Select]
if (pinArg != 9 && pinArg != 10) return 0;
So basically the code as written forbids any other pins than 9 or 10.

Maybe it's safe to just take this line out, maybe not. Some library revision might be in order.

mem

That line should have been amended when the Mega chip support was added. It is worth removing it as a temporary fix but the code should check the currently selected board and test for the correct pins.

As mentioned above, the MegaServo library does not have this problem and can use any available pin on any of the Arduino boards.

jparry

Sorry to ask a stupid question but I am quite new to this - how do I access that section of the code?

mem

I wonder if it is easier for you to just to download MegaServo from the playground and copy that into your hardware libraries directory.  
http://www.arduino.cc/playground/Code/MegaServo

In the sketch, change
 #include <Servo.h>
to
#include <MegaServo.h>

The rest of the sketch can remain unchanged

jparry

Thanks a million mem - it works!!!!!  I'm very pleased  ;D

I thought you had to use PWM to drive a servo yet the new MegaServo library can drive it on nealy all the digital pins ... how?

How long has that code been in the playground?  I hadn't seen that before?

Thank you again!  

Now - what do I have to do to make the 3 axis sensor work?

mem

The MegaServo library was written when the Mega board was released, around the beginning of April.

I have not played with that 3 axis board but suggest you google for information on SPI with the Mega board to see what needs to be done to get it working.

Good luck!

Go Up