Pin conflict - servos/easyVR

Hi! :slight_smile:

I got a problem with the easyVR!

Im using a Arduino Mega, EasyVR shield and a Bluetooth shield on top of that.

In my code i have the following lines:

 #if defined(ARDUINO) && ARDUINO >= 100
  #include "Arduino.h"
  #include "SoftwareSerial.h"
  SoftwareSerial port(12,13);
#else // Arduino 0022 - use modified NewSoftSerial
  #include "WProgram.h"
  #include "NewSoftSerial.h"
  NewSoftSerial port(12,13);
#endif

   if (bridge.check())
    {
    cli();
    bridge.loop(0, 1, 12, 13);
    }

This works fine, but i got a modular robot with 14 servos who needs the PWM-signal. So when i move the generated code from the easyVR commander into my code for all of the servos it bugs.
This is because the servos are using pins 2-13, 45 and 46 on the Mega(Mega have 14 PWM's and all are used for my servos).

So i get a conflict between the servos connected on pin 12 and 13 with the easyVR and the bridge.

So my question is, how can i solve this problem? Which source code needs to be changed so the easyVR can use other pins? Pin 0 and 1 RX/TX are not in use, but they're only for the HW mode ?

Another solution might be to make an ordinary DI to and PWM, so i can move my servos there, and keep the easyVR at 12 and 13? If this works, how is it done ?

Here's is some of the code, i had to remove alot cause the forum only allows 9500 characters, where i both have the code for my servo's and the code which is made with easyVR commander.

#if defined(ARDUINO) && ARDUINO >= 100
  #include "Arduino.h"
  #include "SoftwareSerial.h"
  SoftwareSerial port(12,13);
#else // Arduino 0022 - use modified NewSoftSerial
  #include "WProgram.h"
  #include "NewSoftSerial.h"
  NewSoftSerial port(12,13);
#endif

#include "EasyVR.h"
EasyVR easyvr(port);

//Groups and Commands
enum Groups
{
  GROUP_0  = 0,
  GROUP_1  = 1,
};

enum Group0 
{
  G0_ROBOT = 0,
};

enum Group1 
{
  G1_SIT = 0,
  G1_STAA_PENT = 1,
  G1_GAA = 2,
  G1_DEKK = 3,
  G1_VENSTRE = 4,
  G1_HOYRE = 5,
  G1_AUTOMATISK = 6,
  G1_RESET = 7,
};

EasyVRBridge bridge;

int8_t group, idx;

#include <Servo.h> 

Servo LeftWrist;       // determines the first servo
Servo LeftElbow;       // determines the second servo
Servo LeftShoulder;    // determines the third servo

Servo RightShoulder;   // determines the fourth servo
Servo RightElbow;      // determines the fifth servo
Servo RightWrist;      // determines the sixth servo

Servo Back;            // determines the senventh servo
Servo Stomach;         // determines the eighth servo
Servo Hip;             // determines the nineth servo

Servo LeftAnkle;       // determines the tenth servo
Servo LeftCalf;        // determines the eleventh servo
Servo LeftThigh;       // determines the twelveth servo

Servo RightThigh;      // determines the thirtheenth servo
Servo RightCalf;       // determines the fourteenth servo
Servo RightAnkle;      // determines the fifteenth servo

//-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. Variables .-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-

int t; 
int fQ = 2000; // frequency

//-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-

void setup() { 
  
      // bridge mode
    if (bridge.check())
    {
    cli();
    bridge.loop(0, 1, 12, 13);
    }
  
    Serial.begin(9600);
    port.begin(9600);
    
    
    
    if (!easyvr.detect())
    {
    Serial.println("EasyVR not detected!");
    for (;;);
    }

    easyvr.setPinOutput(EasyVR::IO1, LOW);
    Serial.println("EasyVR detected!");
    easyvr.setTimeout(5);
    easyvr.setLanguage(0);

    group = EasyVR::TRIGGER;
    
    
    RightShoulder.attach(2);  // attaches the servo on pin 3 to the servo object
    RightElbow.attach(3);     // attaches the servo on pin 3 to the servo object
    RightWrist.attach(4);     // attaches the servo on pin 3 to the servo object
  
    LeftShoulder.attach(5);   // attaches the servo on pin 3 to the servo object
    LeftElbow.attach(6);      // attaches the servo on pin 3 to the servo object
    LeftWrist.attach(7);      // attaches the servo on pin 3 to the servo object

    Back.attach(45);          // attaches the servo on pin 3 to the servo object
    Hip.attach(46);           // attaches the servo on pin 3 to the servo object

    LeftAnkle.attach(8);      // attaches the servo on pin 3 to the servo object
    LeftCalf.attach(9);       // attaches the servo on pin 3 to the servo object
    LeftThigh.attach(10);     // attaches the servo on pin 3 to the servo object

    RightThigh.attach(11);    // attaches the servo on pin 3 to the servo object
    //RightCalf.attach(12);     // attaches the servo on pin 3 to the servo object
    //RightAnkle.attach(13);    // attaches the servo on pin 3 to the servo object
    
}

Here's a few picture of my school project, it is suppose to be a H-shaped modular robot with possibility to move in different patterns (Dog, reptile etc..) It is also controlled with an application on a phone, communication true bluetooth. And now im trying to get the easyVR to work.

Here's a pictures of it.

![](http://

// Oyvind_Olsen)

The Servo library supports up to 12 motors on most Arduino boards and 48 on the Arduino Mega. On boards other than the Mega, use of the library disables analogWrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on those pins. On the Mega, up to 12 servos can be used without interfering with PWM functionality; use of 12 to 23 motors will disable PWM on pins 11 and 12.

You can put the servos on whatever pins you want...

Pin 0 and 1 RX/TX are not in use, but they're only for the HW mode ?

I believe these are used for the serial port for uploading your code to the Arduino. Do not use these if you don't need to.

i had to remove alot cause the forum only allows 9500 characters

You can attached the ino file from the "Additional Options.." link at the bottom of the post thread page.

This works fine, but i got a modular robot with 14 servos who needs the PWM-signal.

Your code has 15 servos..

I've had one servo removed, but im not finished cleaning up my code so its kinda messy. So its 15 servos which is determined and only 14 attached to pins. And all of the servos are attached to the pins which got the PWM signal.

The Arduino Mega It has 54 digital input/output pins (of which 14 can be used as PWM outputs), that's why i had one servo removed. The pins which have PWM is pin 2,3,4,5,6,7,8,9,10,11,12,13, 45 and 46. These are the ones im using.

I need too either move the servo's from pin 12 and 13 to some other pins, and modify those pins to PWM's. Or ill need to do something so i can use pin 0 and 1, but how this is done is unknown for me.

I've contacted the developer in the meanwhile, but if there's anyone that gets my question who got answears. I would be pleased.

Thanks :slight_smile:

// Oyvind_Olsen

While the servos are controlled using PWM, it is not the same kind of PWM that the ~ pins output. The servos can be attached to ANY pins. So, why are you hung up on connecting them to the ~ pins?

I've tried to connect the 15th servo to a regular Digital output but i couldnt move the servo and I burned it somehow, that's why i'm hung up on using only ~ pins. This is my first robot ever, so im new to everything here.

What you are saying is that i can move the signal wire for those two servos which is connected at pin 12 and 13 to any of the other digital output? For instance 22 and 23 without ~ pins ? I'm afraid this might burn them.

:slight_smile:

// Oyvind_Olsen

Actually, the problem is that PWM pins use timers and servos use timers. Adding one servo takes one timer out of commission, disabling PWM on some pins. Each timer can service some number of servos. Add more servos than that, and another timer is needed, disabling PWM on some more pins.

http://arduino.cc/en/Reference/Servo is essential reading for anyone using servos.

I've tried to connect the 15th servo to a regular Digital output but i couldnt move the servo and I burned it somehow, that's why i'm hung up on using only ~ pins.

I got bad gas one time, too. That doesn't stop me from buying more. The fact that something other than the Arduino wasted one of your servos is not the Arduino's fault and was not related to the fact that it was not connected to a PWM pin.

I am curious of how you have the servos powered. You say that moving the signal wire to another pin, burnt the servo. I don't see how that could happen unless you mixed the wires up from the supply.

I have an extarnal power supply who can supply up to 30ampere's for the servos. This is only temporary solution, because im planning on using a battery. :slight_smile:

So the solution to my problem should be just to move the servos wired to pin 12 and 13 over to 22 and 23, and change the code where i attach them to the pins, and it should be ok ? It doesnt need the PWM ~ thing ?

Im also having trouble with alot of shaking on the servos, like they're having a solid parkinson :stuck_out_tongue: This is only when the servos are being set to an offset for instance 90 degrees. If i set them in a locomotion movement they're not shaking, i've tried to google it, and many people says its normal. Even tho i find it annoying.

Anyways, thanks for all the help so far. Ill try to do these suggestions you've given me on tuesday :slight_smile:

The shaking could be from multiple things. Like, interference, load on the servo, or a part of the code that is interfering with the timing of the signals.