Hi everyone.
I am an beginner in Arduino programming but I have some experience with other microcontroller platforms.
What I want to do is to control 12 Servos on my Arduino mega 2560. And I want to send/receive data over the serial port.
I use Arduino IDE 1.0.1 on Ubuntu 12.04 but I also tried to use version 0023 but the problem was always the same.
I spent quite a long time searching, but i cant get it to work properly. The servo control works, but only when i dont have serial communication enabled.
As far as I know this happens because the serial library disables interrupts. I found a software servo library but it seems to be limited to 2 servos.
I used the sweep sample and modified it for testing. As soon as I call Serial.begin(xxx); (any baudrate) the servo stops moving.
Is there a way to control 12 servos and use serial communication?
#include <Servo.h>
//Servos:
Servo ShoulderVL;
Servo ElbowVL;
Servo WristVL;
Servo ShoulderVR;
Servo ElbowVR;
Servo WristVR;
Servo ShoulderHL;
Servo ElbowHL;
Servo WristHL;
Servo ShoulderHR;
Servo ElbowHR;
Servo WristHR;
int pos; //dummy movement
void setup() {
pinMode(13, OUTPUT);
Serial.begin(19200);
//Serial.print("Test");
servosetup();
//Serial.println();
//Serial.println("Send inputs to execute servo movement");
}
void loop() {
//if(Serial.available() > 0) {
// s1 = Serial.read();
// }
dummymovement();
}
void dummymovement() {
digitalWrite(13, HIGH);
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
//Serial.print(pos);
//Serial.println();
ShoulderVL.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
//Serial.print(pos);
// Serial.println();
ShoulderVL.write(pos); // tell servo to go to position in variable 'pos'
delay(15);
}
ShoulderVL.write(180);
digitalWrite(13, LOW);
}
void servosetup() {
ShoulderVL.attach(0);
ElbowVL.attach(1);
WristVL.attach(2);
ShoulderVR.attach(3);
ElbowVR.attach(4);
WristVR.attach(5);
ShoulderHL.attach(6);
ElbowHL.attach(7);
WristHL.attach(8);
ShoulderHR.attach(9);
ElbowHR.attach(10);
WristHR.attach(11);
}
Many thanks for your help

Kind regards
Alex