Motors spinning while uploading code - Motor Shield

Hello,

I have the official Arduino Motor Shield which I am using to drive two DC motors with an Arduino Due.
The problem I have is that while the code is uploading, the motors are spinning. As soon as it's uploaded, they stop spinning as it should be because the brake of them is set up to HIGH. I believe it happens because the pin controlling the brakes are LOW during the upload process. But it's a problem for me because due to the nature of my project, if the motors spin more than one revolution, the cables get tangled. Currently, I need to disconnect the motors each time I need to upload the code, which is quite annoying. Is there any way to solve this?

It happens with any code, since it occurs while uploading, but I'm posting an example below.

int dirA = 12;     // HIGH is CW, LOW is CCW
int PWMA = 3;
int brakeA = 9;
int dirB = 13;
int PWMB = 11;
int brakeB = 8;


void setup() {
  pinMode(dirA, OUTPUT);
  pinMode(dirB, OUTPUT);
  pinMode(brakeA, OUTPUT);
  pinMode(brakeB, OUTPUT);
  pinMode(PWMA, OUTPUT);
  pinMode(PWMB, OUTPUT);
  digitalWrite(brakeA, HIGH);
  digitalWrite(brakeB, HIGH);
}

void loop() {
}

Thank you very much for your help!

The pins are floating as the Arduino boots up. Add pull-downs or pull-ups (here a pull-up on the brake?)
if you want to control any of the pins during this period.

Thank you for your reply. As I understand, I can add a pull-up resistor to an input pin by connecting a 10K resistor to +5V. However, as soon as the code is uploaded, this pin will be configured as OUTPUT, and therefore the connection to +5V will be bad for it.
Could you give me more information about how to do it? Thank you

Try it like this:

int dirA = 12;     // HIGH is CW, LOW is CCW
int PWMA = 3;
int brakeA = 9;
int dirB = 13;
int PWMB = 11;
int brakeB = 8;


void setup() {
  pinMode(dirA, OUTPUT);
  pinMode(dirB, OUTPUT);
  digitalWrite(brakeA, HIGH);
  digitalWrite(brakeB, HIGH);
  pinMode(brakeA, OUTPUT);
  pinMode(brakeB, OUTPUT);
  pinMode(PWMA, OUTPUT);
  pinMode(PWMB, OUTPUT);
  
}

Thank you outsider, but that doesn't change anything, since the problem takes place while uploading, so the setup has not occured yet.

I don't see as how an external pullup of say, 10k would cause a problem, the current drawn when the output pin is LOW would only be 0.5 mA.

Acrozynk:
Thank you for your reply. As I understand, I can add a pull-up resistor to an input pin by connecting a 10K resistor to +5V. However, as soon as the code is uploaded, this pin will be configured as OUTPUT, and therefore the connection to +5V will be bad for it.

No, you just use a sensible value like 10k which won't cause anything bad.

A dumb question but are the Brake Enable or Motor pins also the RX/TX pins? Could it be as simple as the motors are being pulsed as the program transfers?.

Kiwi_Bloke:
A dumb question but are the Brake Enable or Motor pins also the RX/TX pins? Could it be as simple as the motors are being pulsed as the program transfers?.

Well I don't see pins 0 and 1 being used in the code snippet, so unlikely here don't you think?

Kiwi_Bloke:
A dumb question but are the Brake Enable or Motor pins also the RX/TX pins? Could it be as simple as the motors are being pulsed as the program transfers?.

Thank you but no, the brake enable are pins 8 and 9, respectively for each motor.

MarkT:
No, you just use a sensible value like 10k which won't cause anything bad.

Thank you for your reply, I will test it as soon as I have access to the shield, which I don't right now temporarily.