D5 and D6 behaving badly driving servos

Hi,
I have #include <servo.h> in my code (first line).
I have a Rev.3 Nano. I’m using A0-A5 and D10, D11 for simple toggle switches to ground/not ground.
These pins are all set to INPUT-PULLUP. And it’s A3/A4 that provides the input for D5 and D6.
Then I’m using D2 trough D9 to drive small (G9) servos.
ALL code simply repeats 8 times, identical except the pin number for input and pin number for output.
Going very well EXCEPT D5 and D6 send their servos berserk. Hard against the stop and rattling.
Obviously tried swapping servos etc. but it’s definitely the pins.
Have only a digital multimeter for testing and it shows D2 and D9 as .35 volt (why) and ALL other pins as .42 Volt including D5 and D6.
Now I know that’s not much of a test but it does give some indication.
So basically what I’m saying is that EVERYTHING dupliates except actual pins used and these 2 don’t want to play along.
Unfortunately I don’t have another Nano handy but as this one is pretty much brand new I sort of tuled that out as well.
I tried looking at <servo.h> to see if it does anything different for those pins but it’s beyond me I’m afraid.

Couldn’t find any reference to this particular problem so I’m throwing it over to anyone who wants to help.
If you really want me to I CAN post the code, but it’s just 8 identical loops.

Aussiewill

If you really want me to I CAN post the code,

Post it

What happens if you switch servos between pins ? Does the problem stay on 5 and 6 ?
How are the servo wired ?
What happens if you try the Sweep example on 5 and 6 with nothing else connected ?
How are the servos powered ?

Hi UKHeliBob,
Thanks for the quick interest.
Swapping servos does nothing, whatever I do the problem stays on D6/7.
Wiring: blacks to common ground with Nano. Reds common 5V with Nano (5V powerpack)
Each motors control (Yellowy orange) to D2/3/4/5/6/7/8/9.
Everything is simply duplicated 8 times.
The final 2 pins that are left, D12 and D13 control 2 LEDs depending on switch positions.

I’ll post the code here for you:

//have 8 switches floating/pulled low to change point position

#include <Servo.h>

Servo myservoa, myservob, myservoc, myservod, myservoe, myservof, myservog, myservoh;  // create servo object to control a servo

byte t1;                        //just for general use as a temp variable for switch pos.
byte t2;
byte t3;
byte t4;
byte t5;
byte t6;
byte t7;
byte t8;

byte val1;                  //these represent actual servo positions (either 80 or 100)
byte val2;
byte val3;
byte val4;
byte val5;
byte val6;
byte val7;
byte val8;

byte straight = 80;          //duration of the pulse to be sent if points are straight ahead
byte turn = 100;             //and if turning off

byte switch1 = A0;              //start using some analog pins here for input
byte switch2 = A1;
byte switch3 = A2;
byte switch4 = A3;
byte switch5 = A4;
byte switch6 = A5;
byte switch7 = 10;              //total of 8 switch pins
byte switch8 = 11;
byte led1 = 12;                 //2 LED pins for warning signals
byte led2 = 13;

void setup()
{
  pinMode(switch1, INPUT_PULLUP);    //set input pins to PULL UP so the switch can pull them down.
  pinMode(switch2, INPUT_PULLUP);    //simply earth it for LOW, let it float for HIGH
  pinMode(switch3, INPUT_PULLUP);
  pinMode(switch4, INPUT_PULLUP);
  pinMode(switch5, INPUT_PULLUP);
  pinMode(switch6, INPUT_PULLUP);
  pinMode(switch7, INPUT_PULLUP);
  pinMode(switch8, INPUT_PULLUP);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);

  myservoa.attach(2);                 //attach all servos
  myservob.attach(3);
  myservoc.attach(4);
  myservod.attach(5);
  myservoe.attach(6);
  myservof.attach(7);
  myservog.attach(8);
  myservoh.attach(9);

  val1 = straight;                   //set all points centre for now
  val2 = straight;                   //void loop will read the switches and fix the points position
  val3 = straight;
  val4 = straight;
  val5 = straight;
  val6 = straight;
  val7 = straight;
  val8 = straight;

  myservoa.write(val1);             //set the servos
  myservob.write(val2);
  myservoc.write(val3);
  myservod.write(val4);
  myservoe.write(val5);             //set the servos
  myservof.write(val6);
  myservog.write(val7);
  myservoh.write(val8);
}

void loop()
{
  t1 = digitalRead (switch1);                 //A0 for in D2 for out
  if ((t1 == LOW) && (val1 == straight))
  {
    myservoa.write(turn);
    val1 = turn;                              // if switch doesn't agree with current setting tell servo to go to new position
  }
  if ((t1 == HIGH) && (val1 == turn))
  {
    myservoa.write (straight);
    val1 = straight;                          //and update val
  }

  t2 = digitalRead (switch2);                 //A1 for in D3 out
  if ((t2 == LOW) && (val2 == straight))
  {
    myservob.write(turn);
    val2 = turn;                              // if switch doesn't agree with current setting tell servo to go to new position
  }
  if ((t2 == HIGH) && (val2 == turn))
  {
    myservob.write (straight);
    val2 = straight;
  }

  t3 = digitalRead (switch3);                 //A2 in D4 out
  if ((t3 == LOW) && (val3 == straight))
  {
    myservoc.write(turn);
    val3 = turn;                              // if switch doesn't agree with current setting tell servo to go to new position
  }
  if ((t3 == HIGH) && (val3 == turn))
  {
    myservoc.write (straight);
    val3 = straight;
  }

  t4 = digitalRead (switch4);                 //A3 in D5 out
  if ((t4 == LOW) && (val4 == straight))
  {
    myservod.write(turn);
    val4 = turn;                              // if switch doesn't agree with current setting tell servo to go to new position
  }
  if ((t4 == HIGH) && (val4 == turn))
  {
    myservod.write (straight);
    val4 = straight;
  }

  t5 = digitalRead (switch5);                 //A4 in D6 out
  if ((t5 == LOW) && (val5 == straight))
  {
    myservoe.write(turn);
    val5 = turn;                              // if switch doesn't agree with current setting tell servo to go to new position
  }
  if ((t5 == HIGH) && (val5 == turn))
  {
    myservoe.write (straight);
    val5 = straight;                          //and update val
  }

  t6 = digitalRead (switch6);                 //A5 in D7 out
  if ((t6 == LOW) && (val6 == straight))
  {
    myservof.write(turn);
    val6 = turn;                              // if switch doesn't agree with current setting tell servo to go to new position
  }
  if ((t6 == HIGH) && (val6 == turn))
  {
    myservof.write (straight);
    val6 = straight;                          //and update val
  }
  t7 = digitalRead (switch7);                 //D10 in and D8 out
  if ((t7 == LOW) && (val7 == straight))
  {
    myservog.write(turn);
    val7 = turn;                              // if switch doesn't agree with current setting tell servo to go to new position
  }
  if ((t7 == HIGH) && (val7 == turn))
  {
    myservog.write (straight);
    val7 = straight;                          //and update val
  }

  t8 = digitalRead (switch8);                 //D11 in and D9 out
  if ((t8 == LOW) && (val8 == straight))
  {
    myservoh.write(turn);
    val8 = turn;                              // if switch doesn't agree with current setting tell servo to go to new position
  }
  if ((t8 == HIGH) && (val8 == turn))
  {
    myservoh.write (straight);
    val8 = straight;                          //and update val
  }

  t1 = digitalRead (switch1);
  t2 = digitalRead (switch5);
  if (t1 != t2)              //if the points on this section do NOT match, switch on warning LED
  {
 digitalWrite (led1,HIGH);
  }
  else
  {
 digitalWrite (led1,LOW);
  }

  t1 = digitalRead (switch4);
  t2 = digitalRead (switch8);
  if (t1 != t2)              //if the points on this section do NOT match, switch on warning LED
  {
digitalWrite (led2,HIGH);
  }
  else 
  {
digitalWrite (led2,LOW);
  }

}

As you can see, VERY basic coding.

Aussiewill

aussiewill:
As you can see, VERY basic coding.

Learn how to use arrays and you can reduce the length of your code by 87%

…R

Reds common 5V with Nano (5V powerpack)

Are you powering the servos from a pin on the Nano or directly from the power pack ?

What about the test using the Sweep example ?

Try removing all your motors, setting all the control pins high and testing the levels. I have one Uno (China) that will not output more than 3 volts on D5. Its rare, but it does happen.

Hi everyone,
First things first:
MY APOLOGIES!!
The entire problem turned out to be a short!! on the little breadboard.
Well, a partial short, anyway.
Put pressure on it with a probe and it disappeared.
Finally took everything apart again and discovered it.

Once again, sorry guys and thanks for the input.

Aussiewill