Arduino Forum

Forum 2005-2010 (read only) => Software => Troubleshooting => Topic started by: jparry on Jun 03, 2009, 10:23 pm

Title: 2 tests and 2 failures - what am I doing wrong?
Post by: jparry on Jun 03, 2009, 10:23 pm
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
Title: Re: 2 tests and 2 failures - what am I doing wrong?
Post by: AWOL on Jun 03, 2009, 10:40 pm
Quote
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.

Quote
I soldered and wired up everything perfectly

How do you know this?
Again, an oscilloscope is great help.
Title: Re: 2 tests and 2 failures - what am I doing wrong?
Post by: jparry on Jun 03, 2009, 11:01 pm
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.

Quote
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?

Quote
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?
Title: Re: 2 tests and 2 failures - what am I doing wrong?
Post by: Grumpy_Mike on Jun 03, 2009, 11:16 pm
Quote
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.
Title: Re: 2 tests and 2 failures - what am I doing wrong?
Post by: RuggedCircuits on Jun 03, 2009, 11:49 pm
Also seeing the actual code would be helpful.
Title: Re: 2 tests and 2 failures - what am I doing wrong?
Post by: jparry on Jun 04, 2009, 12:20 am
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  :-[
Title: Re: 2 tests and 2 failures - what am I doing wrong?
Post by: RuggedCircuits on Jun 04, 2009, 12:33 am
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.
Title: Re: 2 tests and 2 failures - what am I doing wrong?
Post by: mem on Jun 04, 2009, 01:18 am
If you use the standard Arduino servo library on the mega you need to use pins 11 and 12
Title: Re: 2 tests and 2 failures - what am I doing wrong?
Post by: jparry on Jun 04, 2009, 09:54 am
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!
Title: Re: 2 tests and 2 failures - what am I doing wrong?
Post by: mem on Jun 04, 2009, 10:09 am
It should be mentioned in the servo reference but it is not.
http://www.arduino.cc/en/Reference/Servo

I have posted a note asking for this to be updated.
Title: Re: 2 tests and 2 failures - what am I doing wrong?
Post by: jparry on Jun 04, 2009, 10:10 am
Good idea - thanks mem! ;)
Title: Re: 2 tests and 2 failures - what am I doing wrong?
Post by: jparry on Jun 04, 2009, 11:19 am
Quote
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?
Title: Re: 2 tests and 2 failures - what am I doing wrong?
Post by: jparry on Jun 04, 2009, 11:30 am
Just tried changing the pin number in the code but still no joy  :-[

I tried to use 11 and 12

Am I forgetting something?
Title: Re: 2 tests and 2 failures - what am I doing wrong?
Post by: mem on Jun 04, 2009, 11:41 am
If you have not already tried it,  run the example Servo code (after changing the pin numbes)
Title: Re: 2 tests and 2 failures - what am I doing wrong?
Post by: jparry on Jun 04, 2009, 11:46 am
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!
Title: Re: 2 tests and 2 failures - what am I doing wrong?
Post by: mem on Jun 04, 2009, 01:33 pm
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
Title: Re: 2 tests and 2 failures - what am I doing wrong?
Post by: RuggedCircuits on Jun 04, 2009, 03:35 pm
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.
Title: Re: 2 tests and 2 failures - what am I doing wrong?
Post by: mem on Jun 04, 2009, 03:49 pm
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.
Title: Re: 2 tests and 2 failures - what am I doing wrong?
Post by: jparry on Jun 04, 2009, 03:53 pm
Sorry to ask a stupid question but I am quite new to this - how do I access that section of the code?
Title: Re: 2 tests and 2 failures - what am I doing wrong?
Post by: mem on Jun 04, 2009, 04:22 pm
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
Title: Re: 2 tests and 2 failures - what am I doing wrong?
Post by: jparry on Jun 04, 2009, 05:11 pm
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?
Title: Re: 2 tests and 2 failures - what am I doing wrong?
Post by: mem on Jun 04, 2009, 05:38 pm
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!