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?
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.
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.
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.
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!
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.