Arduino ADK Mega vs. Arduino Leonardo

Hello Guys!
My first post on this Forum!

OK Guys Check this out i need ya really help maybe it was allready discussed but i dont know what to do:

Ive got a Project where i Controll a Servomotor directly connected to a µC.

At first i used the ATmega2560 with an XbeeShield and a bluetooth module. I wrote the Code Connected everything and tested it, it worked. The Servo is moving to the Positions i decide.

Now im putting the same Code on an Leonardo with a bluetooth module. The Servo cant reach any of my positons!!

I dont know what to do i tried on the Leonardo following pins 9,11,3;

Please help me fast :slight_smile: thank you Machete

Now im putting the same Code

, which, rather inconsiderately, you didn't post.

Here the code:

#include <Servo.h>

#define step_1 10
#define step_2 20
#define step_3 30
#define step_4 40
#define step_5 50
#define step_6 60
#define step_7 70
#define step_8 80
#define step_9 90



Servo myservo; //create servo object

int pos = 90;
int pos_A = 165;
int pos_E = 0;
double scale = 0;
int menu_pos = 0;
char input;


void setup(){
  Serial.begin(9600);
  pinMode(led, OUTPUT);   

myservo.attach(3); // attaches the servo on pin 9 to the servo object

  myservo.write(pos); //moving servo to init pos (90)
  delay(10);  //time to move for servo 10 ms

  scale = (165 - 0)/100;

  myservo.write(pos_A); //moving servo to init pos (90)
  delay(100);  //time to move for servo 10 ms


}


void loop(){
  if (Serial.available()){
    input = Serial.read();
    switch (input){

    case 'A': //Go to pos_A
      myservo.write(pos_A); //moving servo to init pos (90)
      delay(50);  //time to move for servo 10 ms
      digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(250);               // wait for a second
      digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
      break;

    case 'E': //Go to pos_E
      myservo.write(pos_E); //moving servo to init pos (90)
      delay(50);  //time to move for servo 10 ms
      digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(250);               // wait for a second
      digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
      break;


    case '9':
      menu_pos = (scale * step_1); //Opening 10%
      myservo.write(menu_pos); //moving servo to menupos
      delay(50);  //time to move for servo 10 ms
      digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(250);               // wait for a second
      digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
      break;


    case '8':
      menu_pos = (scale * step_2); //Opening 20%
      myservo.write(menu_pos); //moving servo to menupos
      delay(50);  //time to move for servo 10 ms
      digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(250);               // wait for a second
      digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
      break;


    case '7':
      menu_pos = (scale *step_3); //Opening 30%
      myservo.write(menu_pos); //moving servo to menupos
      delay(50);  //time to move for servo 10 ms
      digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(250);               // wait for a second
      digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
      break;


    case '6':
      menu_pos = (scale *step_4); //Opening 40%
      myservo.write(menu_pos); //moving servo to menupos
      delay(50);  //time to move for servo 10 ms
      digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(250);               // wait for a second
      digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
      break;


    case '5':
      menu_pos = (scale *step_5); //Opening 50%
      myservo.write(menu_pos); //moving servo to menupos
      delay(50);  //time to move for servo 10 ms
      digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(250);               // wait for a second
      digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
      break;

    case '4':
      menu_pos = (scale *step_6); //Opening 60%
      myservo.write(menu_pos); //moving servo to menupos
      delay(50);  //time to move for servo 10 ms
      digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(250);               // wait for a second
      digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
      break;

    case '3':
      menu_pos = (scale *step_7); //Opening 70%
      myservo.write(menu_pos); //moving servo to menupos
      delay(50);  //time to move for servo 10 ms
      digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(250);               // wait for a second
      digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
      break;

    case '2':
      menu_pos = (scale *step_8); //Opening 80%
      myservo.write(menu_pos); //moving servo to menupos
      delay(50);  //time to move for servo 10 ms
      digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(250);               // wait for a second
      digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
      break;

    case '1':
      menu_pos = (scale *step_9); //Opening 90%
      Serial.println(menu_pos,DEC);
      myservo.write(menu_pos); //moving servo to menupos
      delay(50);  //time to move for servo 10 ms
      digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(250);               // wait for a second
      digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
      break;



    }
  }

Do you see the LED?

(Your code would benefit from using some simple arrays, which would shorten the code considerably, and make it easier to debug)

Yes i see the LED and, the Code is working on the leonardo too, BUT it seems like the Servo is getting to low current or a wrong PWM signal because hes doing wrong positioning

For Information this is the hardware i am using:

-Arduino Atmega ADK form DFRobot

and

-Arduino Leonardo with Xbee Shied

Bests, machete

Looking again, you may not need arrays (though they would add flexibility), some arithmetic may be all that's needed to shorten the code.

How is all this powered?
You have a separate supply for the servo?

Yeah i know i could shorten it...

i am powering with the Arduino's with 6V and 2A.

The Servo is not External powered, its getting his Supply via the Arduino.