Pages: [1]   Go Down
Author Topic: Arduino Micro – Servo on Pin 13; bad idea  (Read 1634 times)
0 Members and 1 Guest are viewing this topic.
Hamburg, Germany
Offline Offline
Newbie
*
Karma: 1
Posts: 5
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It just took me 2 hours to figure out why a Servo connected to Pin 13 wildly sweeps back and forth during startup of the Arduino Micro I am using. The Servo goes 14 times across full 180 degrees, but behaves fine afterwards.
This actually broke my mechanics (I underestimated the servo's torque and wasn't prepared for some of the possible angles) and I couldn't imagine how this could happen -- especially since this never happened in the development phase (where I never powered up the Arduino with the servo connected, I always plugged it in afterwards. I first suspected the servo to be bad (it is a cheap noname brick), but after connecting my scope I actually saw the PWM sweeps.

I then simultaneously saw the Pin13 LED.

And that's the culprit: At least the Arduino Micro (not sure about the Leonardo?) does a fancy pulsing of the Pin 13 LED during bootup! While this looks really great, it makes Pin 13 unusable for Servos.

Glad that I finally found the bug -- I just wonder if nobody else experienced this problem yet? Is there a way to disable this boot-pulsing? (I will use another port now, but that requires re-soldering my PCB...
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17263
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
And that's the culprit: At least the Arduino Micro (not sure about the Leonardo?) does a fancy pulsing of the Pin 13 LED during bootup! While this looks really great, it makes Pin 13 unusable for Serv
os.

Well basically it makes it unusable as an output pin for anything important as the bootloader does use the pin as part of it's 'I'm alive' signalling. It just something you have to be aware of when planning out the pin assignments for a project.

Quote
Glad that I finally found the bug -- I just wonder if nobody else experienced this problem yet? Is there a way to disable this boot-pulsing? (I will use another port pin now, but that requires re-soldering my PCB...
I guess you could modify the bootloader source code, recompile it and then reload it, but that's a lot of learning curve if you haven't done that kind of thing before. An easier method to use pin 13 for a servo and not suffer from the bootloader led signalling is to use a hardware programmer and utilize the "upload sketch using programmer" option in the files menu of the arduino IDE. This will erase the bootloader and load your sketch onto the chip using the ICSP method, so that it starts right up with your sketch on reset or power up condition.

Lefty
« Last Edit: December 27, 2012, 08:51:36 pm by retrolefty » Logged

Offline Offline
Full Member
***
Karma: 3
Posts: 221
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think that pins 0, 1, and 13 should not be used for motors and servos. Are there other pins that should not be used for motors and servos?
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17263
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think that pins 0, 1, and 13 should not be used for motors and servos. Are there other pins that should not be used for motors and servos?

Pins 0 and 1 are usable as input or output pins as long as you are not using any serial commands in your sketch and you have a way to disconnect anything wired to pins 0 and 1 when you want to upload a new sketch to the board. But as a general rule pins 0 and 1 should be avoided unless you are up against it and running out of pins and won't be using serial commands. Keep in mind that the analog input pins are also usable as digital input or output pins.

Lefty
Logged

Hamburg, Germany
Offline Offline
Newbie
*
Karma: 1
Posts: 5
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
is to use a hardware programmer and utilize the "upload sketch using programmer" option in the files menu of the arduino IDE
Thank you. That hardware programmer thing is a good hint -- I am already on pin 9 now with my servo (and still have pin 10 left for whatever might come up) -- but I kinda fancy to start straight into my sketch. Will keep my eyes open. (I guess that would also get rid of the junk I see on my 7-segment display during boot? (wired up via a 4511 BCD Decoder)

Quote
Keep in mind that the analog input pins are also usable as digital input or output pins
Interesting -- I exactly do that (since my project needs no analog ins but plenty of digital out). Somewhere in a manual I read that A0-A5 would have the pin numbers "following pin 13", so I first tried using pin numbers 14-18 to write A0-A5 to HIGH. No luck. Scope and poking than told me that A0-A5 are actually reachable via pin 18 to pin 23! I haven't seen this documented yet, but it works.

Setting pin 14-17 to HIGH actually brought MI, SCK, MOSI, SS to +5V... I haven't actually used them due to their obscure names, but it seems they might be (ab)usable as digital outputs too. (Yes, I am a noob...)
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17263
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I
Quote
nteresting -- I exactly do that (since my project needs no analog ins but plenty of digital out). Somewhere in a manual I read that A0-A5 would have the pin numbers "following pin 13", so I first tried using pin numbers 14-18 to write A0-A5 to HIGH. No luck. Scope and poking than told me that A0-A5 are actually reachable via pin 18 to pin 23! I haven't seen this documented yet, but it works.

Setting pin 14-17 to HIGH actually brought MI, SCK, MOSI, SS to +5V... I haven't actually used them due to their obscure names, but it seems they might be (ab)usable as digital outputs too. (Yes, I am a noob...)

That doesn't make any sense at all, analog pin A0 can be addressed as digital pin 14. But of course you can just use digitalWrite(A0, LOW);

Also
SCK = pin 13
MISO = pin 12
MOSI = pin 11
SS = pin 10
You don't use the pin names with digitalWrite or digitalRead commands you just use the pin numbers.
Perhaps you could post your code where "Setting pin 14-17 to HIGH actually brought MI, SCK, MOSI, SS to +5V" as there is something wrong in your interpretation of something I think.

Lefty
Logged

Hamburg, Germany
Offline Offline
Newbie
*
Karma: 1
Posts: 5
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Perhaps you could post your code where "Setting pin 14-17 to HIGH actually brought MI, SCK, MOSI, SS to +5V" as there is something wrong in your interpretation of something I think.

Unfortunately the Arduino Micro is soldered away already, but this is the code (well, excerpt) that works right now to use A0-A4 as digital outs:

Code:
#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// a maximum of eight servo objects can be created

// Outputs
int PumpenPin = 4;
int LiftPin = 11;
int TellerPin = 2;
int BrushPin = 3;
int BlankPin = 12; // PWM
int ServoPin = 9; // PWM
int Apin = 18; // A0
int Bpin = 19; // A1
int Cpin = 20; // A2
int Dpin = 21; // A3
int DPpin = 22; // A4

// Inputs
int IncSwPin = 5;
int DecSwPin = 6;
int StartstopSwPin = 7;
int AbsaugSwPin = 8;
int TrimmerPin = 23; // A5

// [...]

void setup()
{
  analogWrite(ServoPin, homePos); 

  pinMode(Apin, OUTPUT);     
  pinMode(Bpin, OUTPUT);     
  pinMode(Cpin, OUTPUT);     
  pinMode(Dpin, OUTPUT);     
  pinMode(DPpin, OUTPUT);     
  pinMode(BlankPin, OUTPUT);     
  pinMode(PumpenPin, OUTPUT);     
  pinMode(LiftPin, OUTPUT);     
  pinMode(TellerPin, OUTPUT);   
  pinMode(BrushPin, OUTPUT);
  pinMode(Dpin, OUTPUT);     

  myservo.attach(ServoPin);  // attaches the servo to the servo object

  pinMode(IncSwPin, INPUT);
  digitalWrite(IncSwPin, HIGH); 
  pinMode(DecSwPin, INPUT);     
  digitalWrite(DecSwPin, HIGH);
  pinMode(StartstopSwPin, INPUT);     
  digitalWrite(StartstopSwPin, HIGH);
  pinMode(AbsaugSwPin, INPUT);     
  digitalWrite(AbsaugSwPin, HIGH);

  myservo.write(homePos);

  Serial.begin(9600);

  digitalWrite(BlankPin, HIGH);

  seg7(washMinutesDesired);

}


// Apin, Bpin, Cpin and Dpin are BCD-out and go to a CMOS 4511 to drive a 7-segment-LED-panel.
// Example (not very optimized) sub using this successfully:

void seg7(byte number) {
  switch (number) {
    case 0:
      digitalWrite(Apin, LOW);
      digitalWrite(Bpin, LOW);
      digitalWrite(Cpin, LOW);
      digitalWrite(Dpin, LOW);
      break;
    case 1:
      digitalWrite(Apin, HIGH);
      digitalWrite(Bpin, LOW);
      digitalWrite(Cpin, LOW);
      digitalWrite(Dpin, LOW);
      break;
    case 2:
      digitalWrite(Apin, LOW);
      digitalWrite(Bpin, HIGH);
      digitalWrite(Cpin, LOW);
      digitalWrite(Dpin, LOW);
      break;
    case 3:
      digitalWrite(Apin, HIGH);
      digitalWrite(Bpin, HIGH);
      digitalWrite(Cpin, LOW);
      digitalWrite(Dpin, LOW);
      break;
    case 4:
      digitalWrite(Apin, LOW);
      digitalWrite(Bpin, LOW);
      digitalWrite(Cpin, HIGH);
      digitalWrite(Dpin, LOW);
      break;
    case 5:
      digitalWrite(Apin, HIGH);
      digitalWrite(Bpin, LOW);
      digitalWrite(Cpin, HIGH);
      digitalWrite(Dpin, LOW);
      break;
    case 6:
      digitalWrite(Apin, LOW);
      digitalWrite(Bpin, HIGH);
      digitalWrite(Cpin, HIGH);
      digitalWrite(Dpin, LOW);
      break;
    case 7:
      digitalWrite(Apin, HIGH);
      digitalWrite(Bpin, HIGH);
      digitalWrite(Cpin, HIGH);
      digitalWrite(Dpin, LOW);
      break;
    case 8:
      digitalWrite(Apin, LOW);
      digitalWrite(Bpin, LOW);
      digitalWrite(Cpin, LOW);
      digitalWrite(Dpin, HIGH);
      break;
    case 9:
      digitalWrite(Apin, HIGH);
      digitalWrite(Bpin, LOW);
      digitalWrite(Cpin, LOW);
      digitalWrite(Dpin, HIGH);
      break;
  }
}

I just tried again -- setting Pin 14-17 instead of 18-21 to HIGH actually sets MI, SCK, MOSI and SS to HIGH. All that on a Arduino Micro:

« Last Edit: December 28, 2012, 07:28:23 am by peaceman » Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17263
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok I missed the arduino micro board part altogether and assumed standard arduino uno type pin mapping. I'm not at all familiar with the 32U4 chip pin mapping set up so disregard all I stated and let someone familiar with the micro board help if there is help indeed even needed.


http://arduino.cc/en/Main/ArduinoBoardMicro
Lefty
Logged

Pages: [1]   Go Up
Jump to: