Motor Shield v2 kills Mega 2560
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- jndipworm
- Posts: 46
- Joined: Mon Apr 29, 2013 1:06 pm
Re: Motor Shield v2 kills Mega 2560
I checked the micro switch and it does have continuity when it is released, I also checked the button and it has continuity when pressed. I noticed that the serial monitor shows constant 1 on the button, when I push it I do not get a 0, the serial monitor pauses, I get the text Motor Released and then the 1's start streaming again
- adafruit_support_bill
- Posts: 88154
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor Shield v2 kills Mega 2560
So that is a normally closed switch.I checked the micro switch and it does have continuity when it is released
So that is a normally open switch.I also checked the button and it has continuity when pressed
Please post your code.I noticed that the serial monitor shows constant 1 on the button, when I push it I do not get a 0, the serial monitor pauses, I get the text Motor Released and then the 1's start streaming again
And a photo showing all of your connections.
- jndipworm
- Posts: 46
- Joined: Mon Apr 29, 2013 1:06 pm
Re: Motor Shield v2 kills Mega 2560
Here's the code for my V1 motor shield that works perfectly.
Here's the code for my V2.3 motor shield that ignores the while statement.
Here's some pictures.
Code: Select all
//Connect a dc motor to motor port #1 (M1)
#include <AFMotor.h>
#include <Bounce.h>
int TtableButton = 39; //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
pinMode(TtableSwitch, INPUT_PULLUP); //declares turntable switch as an input
TtableMotor.setSpeed(65); //
Serial.begin(9600);// initialize the serial port:
}
void loop() {
Serial.print("TtableSwitch State: ");
Serial.println(digitalRead(TtableSwitch)); // Read the pin and display the value
delay(500);
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
{
TtableMotor.run(FORWARD);
delay(750);
while(digitalRead(TtableSwitch)==LOW)
{ //waiting for switch
}
TtableMotor.run(RELEASE); //releases motor
}
}
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 = 39; //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_PULLUP); //declares pushbutton as input
pinMode(TtableSwitch, INPUT_PULLUP); //declares tutntable switch 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("TtableButton State: ");
Serial.println(digitalRead(TtableButton)); // Read the pin and display the value
delay(250);
bouncer.update ( );// Update the debouncer
int value = bouncer.read();// Get the update value
TtableVal = digitalRead(TtableButton); //reads value of input
if (TtableVal == LOW) //check if the input is LOW
{
// Serial.println("Button was pushed");
TtableMotor->run(FORWARD);
delay(750);
//Serial.println("Waiting...");
while(digitalRead(TtableSwitch)==LOW)
{ //waiting for switch
}
TtableMotor->run(RELEASE); //releases motor
Serial.println("Motor released");
}
}
- Attachments
-
- DSCF0027.jpg (45.23 KiB) Viewed 316 times
-
- DSCF0024.jpg (43.51 KiB) Viewed 316 times
-
- DSCF0015.jpg (37.72 KiB) Viewed 316 times
- jndipworm
- Posts: 46
- Joined: Mon Apr 29, 2013 1:06 pm
Re: Motor Shield v2 kills Mega 2560
Here's the micro switch
- Attachments
-
- DSCF0029.jpg (28.57 KiB) Viewed 316 times
- adafruit_support_bill
- Posts: 88154
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor Shield v2 kills Mega 2560
What kind of switch are you using? Usually the center terminal is the common terminal. Your logic only makes sense if you have it wired as normally closed.
- jndipworm
- Posts: 46
- Joined: Mon Apr 29, 2013 1:06 pm
Re: Motor Shield v2 kills Mega 2560
The micro switch is a Honeywell bz-2rw82-a2. The common post is on the left in the picture and the normally closed post is on the right. The center post is normally open. It is wired normally closed.
- adafruit_support_bill
- Posts: 88154
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor Shield v2 kills Mega 2560
Can't really see where all the wires go. Make sure you have a solid ground for the switch.
What is printed to the Serial Monitor when you run it?
What is printed to the Serial Monitor when you run it?
- jndipworm
- Posts: 46
- Joined: Mon Apr 29, 2013 1:06 pm
Re: Motor Shield v2 kills Mega 2560
I've checked several times that all the connections are tight. I've moved all the gnd connections to screw terminals to make sure they are making good connections. When I have the serial monitor printing out the state of the switch, it streams 1 when the switch is in the position shown. When I spin the table by hand and release the switch it streams 0 until I spin the table back to the position shown, then it streams 1 again. When I have the serial monitor printing the state of the button, it streams 1 until I push the button, there's a delay, I get Motor released, and then it streams 1 again.
- adafruit_support_bill
- Posts: 88154
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor Shield v2 kills Mega 2560
No idea what the issue is. Maybe try a different pin for the switch input. Choose one further away from the SDA and SCL pins to avoid any interference with i2c communication.
- ppsieradzki
- Posts: 41
- Joined: Tue May 27, 2014 3:17 pm
Re: Motor Shield v2 kills Mega 2560
Hello!
Figured I'd post to this thread rather than starting a new one, even though it's old.
I have a Mega 2560 and an Adafruit Motor Shield v2. I previously used the motor shield with an Uno, and it worked flawlessly. To make it work with the Mega 2560, I removed the SCL and SDA pins and the IOr pins, and now everything aligns. It hasn't fried my Mega 2560, since I can give it commands through the Arduino serial monitor and it "responds" (as per my code (I'll paste that below)), but the motor never actually turns.
I'm using a stepper motor which is a 6-wire motor that I have tested before and works if wired correctly.
Thanks in advance!
Figured I'd post to this thread rather than starting a new one, even though it's old.
I have a Mega 2560 and an Adafruit Motor Shield v2. I previously used the motor shield with an Uno, and it worked flawlessly. To make it work with the Mega 2560, I removed the SCL and SDA pins and the IOr pins, and now everything aligns. It hasn't fried my Mega 2560, since I can give it commands through the Arduino serial monitor and it "responds" (as per my code (I'll paste that below)), but the motor never actually turns.
I'm using a stepper motor which is a 6-wire motor that I have tested before and works if wired correctly.
Thanks in advance!
Code: Select all
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); //Create the motor shield object with the default I2C address
//Or, create it with a different I2C address (say for stacking): Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2); // Connect a stepper motor with 200 steps per revolution (1.8 degree) to motor port #2 (M3 and M4)
//Wiring: Red, Yellow, skip ground, Green, Gray
int serialData = 0;
int serialDataNumeric= 0;
int Priming= 0;
/*
Sending 0= Priming: single coil steps until '0' is sent again
Sending 1= Dosing: microstep steps for X steps
*/
void setup()
{
Serial.begin(9600);
Serial.println("Program Started");
//AFMS.begin(); // create with the default frequency 1.6KHz
//OR with a different frequency, say 1KHz: AFMS.begin(1000);
}
void loop()
{
serialData = 0;
serialDataNumeric= 0;
if (Serial.available() > 0)
{
serialData = Serial.read();
serialDataNumeric= (serialData - '0'); //ASCII value converted to numeric value
if(serialDataNumeric==0)
{
//Priming
Priming= 1;
Serial.println("Priming: send 0 again to stop");
AFMS.begin();
do
{
myMotor->setSpeed(40); //Speed of revolution in RPM
myMotor->step(10, BACKWARD, SINGLE); //Can change to "BACKWARD"
serialData = Serial.read();
serialDataNumeric= (serialData - '0');
if(serialDataNumeric==0)
{
Priming= 0;
Serial.println("Priming stopped.");
}
} while(Priming==1);
}
if(serialDataNumeric==1)
{
//Dosing
Serial.println("Dosing");
AFMS.begin();
myMotor->setSpeed(5); //Speed of revolution in RPM
myMotor->step(20, FORWARD, MICROSTEP); //Can change to "BACKWARD"
}
}
}
//-----------------------------------------END OF PROGRAM-----------------------------------------
- adafruit_support_bill
- Posts: 88154
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor Shield v2 kills Mega 2560
@ppsieradzki - This is a long and rather complex thread. To avoid confusion, please start a new one. Be sure to include details like your motor specifications and power supply. Photos are often helpful as well.
- ppsieradzki
- Posts: 41
- Joined: Tue May 27, 2014 3:17 pm
Re: Motor Shield v2 kills Mega 2560
I actually found the answer :) For those interested: https://learn.adafruit.com/adafruit-shi ... -shield-v2
Add jumper wire from SDA on shield to pin 20 on Mega board.
Add jumper wire from SCL on shield to pin 21 on Mega board.
Solves the problem.
Add jumper wire from SDA on shield to pin 20 on Mega board.
Add jumper wire from SCL on shield to pin 21 on Mega board.
Solves the problem.
Please be positive and constructive with your questions and comments.