stacking 2 moto shields with 4 Nema 17 steppers

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

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
mooredesign13
 
Posts: 37
Joined: Fri Apr 17, 2020 12:18 pm

stacking 2 moto shields with 4 Nema 17 steppers

Post by mooredesign13 »

I need help debugging the code for the following set up:

I have two adafruit V2 Motor Shields stacked onto my Arduino Mega
I have two nema 17 steppers per shield

I previously ran this code with only a single motor shield and two motors and it worked great. I was able to have the code ask me for the number of steps I wanted. I would enter my response into the serial monitor and then it would drive the respective motor the number of steps I asked for. It also displays a copy of the information on a 16x2 LCD

Now the issue is twofold:
1. when I enter the number of steps for motor 1, it then drives motors 1 &3 simultaneously.
2.when I enter the number of steps for motor 2, it then drives motors 2 &4 simultaneously.
3. then it asks for the number of steps for motor 3 (which is correct) and when I enter the steps, it responds with a backward "?" symbol, and then resets the program.

I have copied the text from the serial monitor below (My entries are in bold)
~~~~~~~~~~~~~~~~~
Stepper test!
Motor Shield found.
Motor 1 Steps?
200.00
Motor 2 Steps?
200.00
Motor 3 Steps?
200.⸮Stepper test!
Motor Shield found.
Motor 1 Steps?
~~~~~~~~~~~~~~~~~~

here is my code:

Code: Select all

/*
This is a test sketch for the Adafruit assembled Motor Shield for Arduino v2
It won't work with v1.x motor shields! Only for the v2's with built in PWM
control

For use with the Adafruit Motor Shield v2
---->  http://www.adafruit.com/products/1438
*/

#include <Adafruit_MotorShield.h>
#include <LiquidCrystal.h>
//This is the part I may have screwed up...
// 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 AFMS2 = Adafruit_MotorShield(0x61);

// Connect a stepper motor with 200 steps per revolution (1.8 degree)
// to motor port #2 (M3 and M4)
Adafruit_StepperMotor *myMotor1 = AFMS.getStepper(200, 1);
Adafruit_StepperMotor *myMotor2 = AFMS.getStepper(200, 2);
Adafruit_StepperMotor *myMotor3 = AFMS2.getStepper(200, 1);
Adafruit_StepperMotor *myMotor4 = AFMS2.getStepper(200, 2);
int dt=500;
float M1Steps;
float M2Steps;
float M3Steps;
float M4Steps;
int rs=7; //LCD Pins are 7 through 12
int en=8;
int d4=9;
int d5=10;
int d6=11;
int d7=12;
String AskM1="Motor 1 Steps?";
String AskM2="Motor 2 Steps?";
String AskM3="Motor 3 Steps?";
String AskM4="Motor 4 Steps?";
LiquidCrystal lcd(rs,en,d4,d5,d6,d7);

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  lcd.clear();
lcd.begin(16,2);
  while (!Serial);
  Serial.println("Stepper test!");

  if (!AFMS.begin()) {         // create with the default frequency 1.6KHz
  // if (!AFMS.begin(1000)) {  // OR with a different frequency, say 1KHz
    Serial.println("Could not find Motor Shield. Check wiring.");
    while (1);
  }
  Serial.println("Motor Shield found.");

  myMotor1->setSpeed(10);  // 10 rpm
  myMotor2->setSpeed(10);
  myMotor3->setSpeed(10);
  myMotor4->setSpeed(10);
}

void loop() {

//Control of Motor ONE code below

 Serial.println(AskM1); 
  lcd.clear();
  lcd.setCursor(0,0);
lcd.print(AskM1);
while (Serial.available ()==0){
  
}
M1Steps=Serial.parseFloat();
lcd.setCursor(0,1);
lcd.print(M1Steps);
Serial.println(M1Steps);

myMotor1->step(M1Steps, FORWARD, SINGLE);

//Control of Motor TWO code below

lcd.clear();
lcd.begin(16,2);
 Serial.println(AskM2); 
  lcd.setCursor(0,0);
lcd.print(AskM2);
while (Serial.available ()==0){
  
}
M2Steps=Serial.parseFloat();
lcd.setCursor(0,1);
lcd.print(M2Steps);
Serial.println(M2Steps);

myMotor2->step(M2Steps, FORWARD, SINGLE);

//Control of Motor THREE code below

lcd.clear();
lcd.begin(16,2);
 Serial.println(AskM3); 
  lcd.setCursor(0,0);
lcd.print(AskM3);
while (Serial.available ()==0){
  
}
M3Steps=Serial.parseFloat();
lcd.setCursor(0,1);
lcd.print(M3Steps);
Serial.println(M3Steps);

myMotor3->step(M3Steps, FORWARD, SINGLE);

//Control of Motor FOUR code below

lcd.clear();
lcd.begin(16,2);
 Serial.println(AskM4); 
  lcd.setCursor(0,0);
lcd.print(AskM4);
while (Serial.available ()==0){
  
}
M4Steps=Serial.parseFloat();
lcd.setCursor(0,1);
lcd.print(M4Steps);
Serial.println(M4Steps);

myMotor4->step(M4Steps, FORWARD, SINGLE);
  
}
I have included a picture of the setup, however, I do not think it is a hardware issue. I commented in the code where I think the issue is, which is likely how I set up he motor shields and motors in the set up code.

I'm pretty new at this stuff, so be gentle!


Austin
Attachments
A picture of the hardware set up.
A picture of the hardware set up.
photo4972160394948880841.jpg (171.87 KiB) Viewed 528 times

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

Re: stacking 2 moto shields with 4 Nema 17 steppers

Post by adafruit_support_bill »

Have you soldered the jumper to change the address for the second shield?
https://learn.adafruit.com/adafruit-mot ... -2045911-2

User avatar
mooredesign13
 
Posts: 37
Joined: Fri Apr 17, 2020 12:18 pm

Re: stacking 2 moto shields with 4 Nema 17 steppers

Post by mooredesign13 »

Nope. I missed that step. So I have to run a line of solder across the two pads, furthest to the right? (Exactly like the picture, and then that upper board will be 0x61?)
Image

oh, and Happy thanksgiving! I didn't expect a reply today :)

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

Re: stacking 2 moto shields with 4 Nema 17 steppers

Post by adafruit_support_bill »

That should do it. From what I can see you have the code changes in place already.

User avatar
mooredesign13
 
Posts: 37
Joined: Fri Apr 17, 2020 12:18 pm

Re: stacking 2 moto shields with 4 Nema 17 steppers

Post by mooredesign13 »

I soldered the pads.

at first I still could not get motors 3 and 4 to run, then I realized I had not entered the "begin" code for the top shield. after adding the following lines, it now works great!

Code: Select all

if (!AFMS2.begin()) {         // create with the default frequency 1.6KHz
  // if (!AFMS2.begin(1000)) {  // OR with a different frequency, say 1KHz
    Serial.println("Could not find Motor Shield. Check wiring.");
    while (1);
  }
  Serial.println("Motor Shield found.");
Thank you!

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

Re: stacking 2 moto shields with 4 Nema 17 steppers

Post by adafruit_support_bill »

Good to hear. Thanks for the update.

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

Return to “Arduino Shields from Adafruit”