Motor Shield v2 kills Mega 2560

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
jndipworm
 
Posts: 46
Joined: Mon Apr 29, 2013 1:06 pm

Motor Shield v2 kills Mega 2560

Post by jndipworm »

Hello all. A few weeks ago I bought a new Arduino Mega 2560 (from Adafruit) and more recently I bought a new Motor Shield v2 (also from Adafruit). I uploaded the blink sketch to the Mega shortly after I got it to make sure it worked properly, all went well. I finally got around to soldering the headers on the Motor Shield and all went well there. When I stack the Motor Shield on the Mega, my computer doesn't see the Mega and the blink sketch stops. When I take the Motor Shield off, I can see the Mega on the computer and the blink sketch starts again.I looked at the headers pins I soldered on and I don't see any places where the solder bridged across to an adjacent pin. Any ideas?

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield v2 kills Mega 2560

Post by adafruit_support_bill »

Please post photos showing all your soldering on the shield.

User avatar
jndipworm
 
Posts: 46
Joined: Mon Apr 29, 2013 1:06 pm

Re: Motor Shield v2 kills Mega 2560

Post by jndipworm »

I have one more photo
Attachments
100_1628.jpg
100_1628.jpg (568.64 KiB) Viewed 569 times
100_1625.jpg
100_1625.jpg (627.36 KiB) Viewed 569 times
100_1624.jpg
100_1624.jpg (767.38 KiB) Viewed 569 times

User avatar
jndipworm
 
Posts: 46
Joined: Mon Apr 29, 2013 1:06 pm

Re: Motor Shield v2 kills Mega 2560

Post by jndipworm »

Last one
Attachments
100_1629.jpg
100_1629.jpg (734.25 KiB) Viewed 569 times

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield v2 kills Mega 2560

Post by adafruit_support_bill »

I don't see anything that should cause a problem on the bottom side. Can you post some clear photos of the top of the board?

User avatar
jndipworm
 
Posts: 46
Joined: Mon Apr 29, 2013 1:06 pm

Re: Motor Shield v2 kills Mega 2560

Post by jndipworm »

Here are the top pics
Attachments
100_1657.jpg
100_1657.jpg (833.6 KiB) Viewed 528 times
100_1655.jpg
100_1655.jpg (812.42 KiB) Viewed 528 times
100_1652.jpg
100_1652.jpg (813.32 KiB) Viewed 528 times

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield v2 kills Mega 2560

Post by adafruit_support_bill »

I don't see any manufacturing issues on that side either. Let's try replacing the board. If you contact [email protected] with a link to this thread we can send one out to you.

User avatar
jndipworm
 
Posts: 46
Joined: Mon Apr 29, 2013 1:06 pm

Re: Motor Shield v2 kills Mega 2560

Post by jndipworm »

I was able to order a new Motor Shield v2 (Thank You) and should have it in a couple of days. I have a question about controlling a 12v DC gear motor using M1 and M2. My dc motor isn't accurate enough to use a delay and get it to stop at a repeatable interval. Every time I power up the arduino and hit the button to turn the motor, the distance it travels is different from the last time the sketch ran. So I was wondering about using M1 to supply power for a 1 sec and then use M2 to supply power until the motor turns and hits a micro switch to kill the power. Since the micro switch kills the power going to the motor I need M1 to supply power long enough for the motor to turn and release the switch to feed power once again. I've attached the sketch I was planning on trying.

Code: Select all

/* 
Connect a dc motor to motor port #1 (M1)
 */
#include <AFMotor.h>
#include <Bounce.h>

int buttonPin = 40;   //choose the input pin for the pushbutton
int buttonVal = 0;   //variable for reading the pushbutton
AF_DCMotor ttableStart(1, MOTOR12_64KHZ); //attaches turn table dc motor to port 1
AF_DCMotor ttableSpin(2, MOTOR12_64KHZ); //attaches turn table dc motor to port 2

// Instantiate a Bounce object with a 500 millisecond debounce time
Bounce bouncer = Bounce( buttonPin,1000 );

void setup() {

  pinMode(buttonPin, INPUT_PULLUP);  //declare pushbutton as input
                            //Pullup inverts logic HIGH=off LOW=on

   ttableStart.setSpeed(60);  //
   ttableSpin.setSpeed(60);
   
  // initialize the serial port:
  Serial.begin(9600);

}

void loop() {

     // Update the debouncer
  bouncer.update ( );
   // Get the update value
  int value = bouncer.read();
  
  buttonVal = digitalRead(buttonPin);  //reads value of input
  if (buttonVal == LOW)        //check if the input is LOW
  {

  ttableStart.run(BACKWARD);//sends power to (M1) motor to bump turn table off switch
  delay(1000);//delays long enough for table to release switch
  ttableStart.run(RELEASE); //releases motor
  ttableSpin.run(BACKWARD);//
   delay(3000);//delay to alow table to hit switch
  ttableSpin.run(RELEASE); //releases motor

 
 } 
}

User avatar
Franklin97355
 
Posts: 23940
Joined: Mon Apr 21, 2008 2:33 pm

Re: Motor Shield v2 kills Mega 2560

Post by Franklin97355 »

Could you draw a picture of your planed motor, button and switches?

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield v2 kills Mega 2560

Post by adafruit_support_bill »

A better way to do it is to connect your limit switches to digital inputs and use those to reverse the motor.

User avatar
jndipworm
 
Posts: 46
Joined: Mon Apr 29, 2013 1:06 pm

Re: Motor Shield v2 kills Mega 2560

Post by jndipworm »

Good call on using the switch as an input, works great. I wrote this sketch for my v1 Motor shield and it works perfect.

Code: Select all

//Connect a dc motor to motor port #1 (M1)
#include <AFMotor.h>
#include <Bounce.h>

int TtableButton = 40;   //choose the input pin for the pushbutton
int TtableVal = 0;   //variable for reading the pushbutton
int TtableSwitch = 23; //declares the table switch on pin 23
AF_DCMotor TtableMotor(1, MOTOR12_64KHZ); //attaches table dc motor to port 1
// Instantiate a Bounce object with a 500 millisecond debounce time
Bounce bouncer = Bounce( TtableButton,1000 );

void setup() {

  pinMode(TtableButton, INPUT);  //declare pushbutton as input

   TtableMotor.setSpeed(65);  //

  Serial.begin(9600);// initialize the serial port:
}

void loop() {
  bouncer.update ( );// Update the debouncer
  int value = bouncer.read();// Get the update value
  
  TtableVal = digitalRead(TtableButton);  //reads value of input
  if (TtableVal == HIGH)        //check if the input is HIGH
  {
    Serial.println("Bag");
  TtableMotor.run(FORWARD);
  delay(750);
  
  while(digitalRead(TtableSwitch)==HIGH)
  { //waiting for switch
  }
  TtableMotor.run(RELEASE); //releases motor
 
 } 
}
When I tried to use my v2.3 Motor shield I changed the code to this:

Code: Select all

/*
For use with the Adafruit Motor Shield v2 
Connects a dc motor to motor port #1 (M1)
*/

#include <Bounce.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

int TtableButton = 40;   //choose the input pin for the pushbutton
int TtableVal = 0;   //variable for reading the pushbutton
int TtableSwitch = 23; //declares the table switch on pin 23

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61); 

// Select which 'port' M1, M2, M3 or M4. In this case, M1
Adafruit_DCMotor *TtableMotor = AFMS.getMotor(1);
// You can also make another motor on port M2
//Adafruit_DCMotor *myOtherMotor = AFMS.getMotor(2);

// Instantiate a Bounce object with a 500 millisecond debounce time
Bounce bouncer = Bounce( TtableButton,1000 );

void setup() {
  
   pinMode(TtableButton, INPUT);  //declare pushbutton as input
  
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Here we go...");

  AFMS.begin();  // create with the default frequency 1.6KHz
  //AFMS.begin(1000);  // OR with a different frequency, say 1KHz
  
  // Set the speed to start, from 0 (off) to 255 (max speed)
  TtableMotor->setSpeed(65);
  TtableMotor->run(FORWARD);
  // turn on motor
  TtableMotor->run(RELEASE);
}

void loop() {
  bouncer.update ( );// Update the debouncer
  int value = bouncer.read();// Get the update value
  
  TtableVal = digitalRead(TtableButton);  //reads value of input
  if (TtableVal == HIGH)        //check if the input is HIGH
  {
    Serial.println("Button was pushed");
  TtableMotor->run(FORWARD);
  delay(750);
  
  Serial.println("Waiting...");
  
  while(digitalRead(TtableSwitch)==HIGH)
  { //waiting for switch
  }
  Serial.println("Motor released");
  TtableMotor->run(RELEASE); //releases motor
 
 }
}
For some reason the while statement is being skipped. The motor runs for what ever the delay is set to and then releases the motor before the switch is hit. I've been looking at this for a couple of days and I'm at a loss for what's causing it.
Also, I don't know why in the sketch Adafruit_MotorShield.h is all black when Wire.h is orange with a black .h. It's like that all thru the sketch. The Adafruit_*** lines of code are all black. I don't know if this correct or if there an issue. When I look at examples online, this code is orange and black.

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield v2 kills Mega 2560

Post by adafruit_support_bill »

The motor runs for what ever the delay is set to and then releases the motor before the switch is hit.
Do you have pullup resistors on your switches? Add some Serial.println statements to print the state of the digitalRead on that pin.
Also, I don't know why in the sketch Adafruit_MotorShield.h is all black when Wire.h is orange with a black .h
That is normal. "Wire" is a recognized Arduino keyword, so it is shown in orange.

User avatar
jndipworm
 
Posts: 46
Joined: Mon Apr 29, 2013 1:06 pm

Re: Motor Shield v2 kills Mega 2560

Post by jndipworm »

I have the button that starts the sketch setup with a pull down resistor. The micro switch is connected to 5v on one side and pin 23 on the other. The 5v runs thru the switch when it's released, goes HIGH, and the connection is broke when the switch is depressed, goes LOW. Do I need a resistor on this circuit? I will try to get Serial.println to show me what's going on with the switch, still learning just where to put this.

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield v2 kills Mega 2560

Post by adafruit_support_bill »

I have the button that starts the sketch setup with a pull down resistor. The micro switch is connected to 5v on one side and pin 23 on the other. The 5v runs thru the switch when it's released, goes HIGH, and the connection is broke when the switch is depressed, goes LOW.
That explanation only makes sense if it is a normally closed switch. Most switches are normally open and would require a pull-up to match the code you posted.

User avatar
jndipworm
 
Posts: 46
Joined: Mon Apr 29, 2013 1:06 pm

Re: Motor Shield v2 kills Mega 2560

Post by jndipworm »

Ok here's what I tried. I found an example of Serial.println that monitored a button in one of my old sketches. I added it in (see code) and had it look at the TtableSwitch which is the micro switch. When I opened the serial monitor and just let it sit, the state would go from 0 to 1 and back to 0. The whole time the switch is depressed (open) and should read 0. I checked the voltage on both sides of the switch and had 5v going in and 0v coming out to pin 23. When I pushed the button it didn't always respond, when it did the dc motor turned until it delayed out and stopped. I checked the voltage again and had 5v going into the switch and 5v coming out to pin 23, the micro switch is now released (closed). When I commented out "//" the Serial.print lines, the button worked every time I pressed it but still delayed out before it hit the switch again.

Code: Select all

/*
For use with the Adafruit Motor Shield v2 
Connects a dc motor to motor port #1 (M1)
*/

#include <Bounce.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

int TtableButton = 40;   //choose the input pin for the pushbutton
int TtableVal = 0;   //variable for reading the pushbutton
int TtableSwitch = 23; //declares the table switch on pin 23

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61); 

// Select which 'port' M1, M2, M3 or M4. In this case, M1
Adafruit_DCMotor *TtableMotor = AFMS.getMotor(1);
// You can also make another motor on port M2
//Adafruit_DCMotor *myOtherMotor = AFMS.getMotor(2);

// Instantiate a Bounce object with a 500 millisecond debounce time
Bounce bouncer = Bounce( TtableButton,500 );

void setup() {
  
   pinMode(TtableButton, INPUT);  //declare pushbutton as input
  
  Serial.begin(9600); // set up Serial library at 9600 bps
    
  AFMS.begin();  // create with the default frequency 1.6KHz
  //AFMS.begin(1000);  // OR with a different frequency, say 1KHz
  
  // Set the speed to start, from 0 (off) to 255 (max speed)
  TtableMotor->setSpeed(65);
  TtableMotor->run(FORWARD);  // turn motor on
  TtableMotor->run(RELEASE);  // turn motor off
}

void loop() {
  Serial.print("TtableSwitch State: ");
  Serial.println(digitalRead(TtableSwitch)); // Read the pin and display the value
   delay(1000);
  bouncer.update ( );// Update the debouncer
  int value = bouncer.read();// Get the update value
  
  TtableVal = digitalRead(TtableButton);  //reads value of input
  if (TtableVal == HIGH)        //check if the input is HIGH
  {
   // Serial.println("Button was pushed");
  TtableMotor->run(FORWARD);
  delay(750);
  
  //Serial.println("Waiting...");
  
  while(digitalRead(TtableSwitch)==HIGH)
  { //waiting for switch
  }
  
  TtableMotor->run(RELEASE); //releases motor
  Serial.println("Motor released");
 
 }
}

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”