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

Hi All,

Firstly - I am fairly new to the Arduino but have experience in C.

I have successfully combined the Arduino Mega with LED's, Thermistors, LDR's ECT and started to look at some bigger things. I first looked at working with servo's, I used a cheap servo that I had lying around that originally came out of a RC toy car (HPI Minizilla). I wired everything up and used the 'sweep' example from the Arduino website to try it out but it wouldn't work - the servo did power up but didn't move. I attached an LED to pin 13 and programmed a 'blink' at the end of every loop to check it was cycling and it was, but I found no reason as to why the servo didn't move.

My second task was to use a Sparkfun LIS3LV02DQ Triple Axis Accelerometer with my Mega so I used the suggested method found on the cool components website

I soldered and wired up everything perfectly but again - nothing. So this time I used the Serial.println at various stages in the code to detect what was happening. I found that everything works until the Arduino starts to talk to the sensor - at this point the code stops running altogether???

My question is this - have I done something wrong as the examples are written for Duemilanove and not the Mega? If so - what do I need to change?

Or - Am I doing something completley wrong?

Please put me out my misery!

Thanks in advance,

James

a cheap servo ... that...came out of a RC toy car (HPI Minizilla

Depending on how much the toy originally cost, I wouldn't necessarily expect it to work like a hobbyist servo. Depending on production volumes, it could have a completely proprietary control protocol.
I'd try to examine the toy using an oscilloscope to see what controls it expected.

Try finding an R/C model shop, and buy a cheap Futaba 3003.
Make sure you read the servo library documentation carefully.

Make sure you join the grounds between your separate power supplies.

I soldered and wired up everything perfectly

How do you know this?
Again, an oscilloscope is great help.

Thanks for your quick reply!

With regards to the servo - I used to work for the UK Futaba distribution company so I will get one through them and try that out first. I dont have an oscilloscope so I can't check it that way.

Make sure you join the grounds between your separate power supplies.

What do you mean by seperate power supplys? I was using the 5v and ground from the Mega - is that not right - Do I need to power the servo separatley?

How do you know this?

I used my multimeter to check the connections from one side (header pins) to the other side (solder) - I felt that was a quick and easy test? Is it not?

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