Due to high demand expect some shipping delays at this time, orders may not ship for 3-4 business days. On MLK Day no orders will be shipped.
0

stacking 2 moto shields with 4 Nema 17 steppers
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

stacking 2 moto shields with 4 Nema 17 steppers

by mooredesign13 on Thu Nov 25, 2021 2:23 pm

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 | TOGGLE FULL SIZE
/*
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
photo4972160394948880841.jpg
A picture of the hardware set up.
photo4972160394948880841.jpg (171.87 KiB) Viewed 410 times

mooredesign13
 
Posts: 30
Joined: Fri Apr 17, 2020 12:18 pm

Re: stacking 2 moto shields with 4 Nema 17 steppers

by adafruit_support_bill on Thu Nov 25, 2021 3:03 pm

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

adafruit_support_bill
 
Posts: 82874
Joined: Sat Feb 07, 2009 10:11 am

Re: stacking 2 moto shields with 4 Nema 17 steppers

by mooredesign13 on Thu Nov 25, 2021 6:52 pm

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 :)

mooredesign13
 
Posts: 30
Joined: Fri Apr 17, 2020 12:18 pm

Re: stacking 2 moto shields with 4 Nema 17 steppers

by adafruit_support_bill on Thu Nov 25, 2021 8:40 pm

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

adafruit_support_bill
 
Posts: 82874
Joined: Sat Feb 07, 2009 10:11 am

Re: stacking 2 moto shields with 4 Nema 17 steppers

by mooredesign13 on Fri Nov 26, 2021 6:05 pm

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 | TOGGLE FULL SIZE
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!

mooredesign13
 
Posts: 30
Joined: Fri Apr 17, 2020 12:18 pm

Re: stacking 2 moto shields with 4 Nema 17 steppers

by adafruit_support_bill on Fri Nov 26, 2021 6:52 pm

Good to hear. Thanks for the update.

adafruit_support_bill
 
Posts: 82874
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.