2 tests and 2 failures - what am I doing wrong?

at this point the code stops running altogether???

No code never stops running, it might be running out of control or sulking in a tight loop but it never stops. Remember that and hunt down where it is going to.

Also seeing the actual code would be helpful.

Sorry - my first post on this thread was actually my first post on this site so couldn't post links but can now so here they are:

Servo : http://arduino.cc/en/Tutorial/Sweep

3 Axis sensor : http://www.nearfuturelaboratory.com/2006/09/22/arduino-and-the-lis3lv02dq-triple-axis-accelerometer/

The code was unaltered except for my 'blink' or 'Serial.println' debug lines, which worked but I havent kept the code :-[

Well, I don't have an Arduino Mega but sleuthing through the code reveals a potential problem (maybe somebody can correct me if necessary).

Pin 9 on the Mega is Port H pin 6, which is the OC2B output compare pin for Timer 2, but the Servo library uses Timer 1.

I think you have a similar problem with the accelerometer code. It is currently set to use pin 11 for MOSI, 12 for MISO, etc. etc. but pin 11 on the Mega is PB5 which is not MOSI, pin 12 on the Mega is PB6 which is not MISO, and so on.

If you use the standard Arduino servo library on the mega you need to use pins 11 and 12

That sounds about right! I was thinking it was going to be something like that!

Thanks to Rugged Circuits and mem for pointing those out!

Where do I get that information regarding the types of pins so I can solve myself in future?

I will try the servo pin variation and let you know!

It should be mentioned in the servo reference but it is not.

I have posted a note asking for this to be updated.

Good idea - thanks mem! :wink:

If you use the standard Arduino servo library on the mega you need to use pins 11 and 12

If I just change the pin in the example from 9 to 11 - should that work or do I need to change something else? If so - What?

Just tried changing the pin number in the code but still no joy :-[

I tried to use 11 and 12

Am I forgetting something?

If you have not already tried it, run the example Servo code (after changing the pin numbes)

Sorry - maybe I should have explained better. I am still trying the example 'sweep' servo code using the suggested pin 9, and your sugegsted pins 11 and 12. All variations fail!

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

Well, there is a line in the Servo.cpp, in Servo::attach, that says:

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.

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.

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

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

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?

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!