I'm looking to control 3x Nema 17 stepper motors via the Reyes_CNC shield (clone?).
I need to activate and stop each of the steppers (1,2,3 in series, not parallel) wait 4-hours, then activate and stop each of the steppers in opposite direction and order (3,2,1 again in series, not parallel). This sequence needs to run once per power on of the Arduino. I will be controlling power with a wifi outlet.
Can anyone point me in a direction to get started, please? I direct connected one of the steppers to an Uno R3 and it just buzzed instead of turning. Hence the CNC shield for ease of connecting additional power.
I have tried the stepper.h example and can get the small stepper and driver board that comes with the ultimate kits to work, but the Nema 17 won't budge.
If you are using a step/dir type driver, the Stepper library will not work.
For a modern bipolar stepper you need a current controlled step/dir driver like the A4988 (up to 1A coil current) or DRV8825 (up to 1.5A coil current).
I have basic connections right now. I have verified I have the drivers installed correctly in the shield (pots over jumpers), Nema 17's connected to the pin headers. I have not added any additional power yet, but can add a 5v 2A to the shield or put it on my bench power supply.
This is the code I'm trying to get working so I can learn how it all works so I can bend it to my will.
// MultiStepper
// -*- mode: C++ -*-
//
// Control both Stepper motors at the same time with different speeds
// and accelerations.
// Requires the AFMotor library (https://github.com/adafruit/Adafruit-Motor-Shield-library)
// And AccelStepper with AFMotor support (https://github.com/adafruit/AccelStepper)
// Public domain!
#include <AccelStepper.h>
#include <AFMotor.h>
// two stepper motors one on each port
AF_Stepper motor1(200, 1);
AF_Stepper motor2(200, 2);
// you can change these to DOUBLE or INTERLEAVE or MICROSTEP!
// wrappers for the first motor!
void forwardstep1() {
motor1.onestep(FORWARD, SINGLE);
}
void backwardstep1() {
motor1.onestep(BACKWARD, SINGLE);
}
// wrappers for the second motor!
void forwardstep2() {
motor2.onestep(FORWARD, SINGLE);
}
void backwardstep2() {
motor2.onestep(BACKWARD, SINGLE);
}
// Motor shield has two motor ports, now we'll wrap them in an AccelStepper object
AccelStepper stepper1(forwardstep1, backwardstep1);
AccelStepper stepper2(forwardstep2, backwardstep2);
void setup()
{
stepper1.setMaxSpeed(200.0);
stepper1.setAcceleration(100.0);
stepper1.moveTo(24);
stepper2.setMaxSpeed(300.0);
stepper2.setAcceleration(100.0);
stepper2.moveTo(1000000);
}
void loop()
{
// Change direction at the limits
if (stepper1.distanceToGo() == 0)
stepper1.moveTo(-stepper1.currentPosition());
stepper1.run();
stepper2.run();
}```
Get rid of all that. It is not going to work. You are not using an AFMotor shield.
You are using the wrong AccelStepper constructors for the A4988 stepper drivers. Those drivers do not use the AFMotor class.
The right constructor is like: AccelStepper stepper(AccelStepper::DRIVER, stepPin, dirPin);
The DRIVER is for the step/dir type (A4988) driver.
This is how the Nano pins are mapped to the CNC shield.
The A4988 drivers need a minimum of 8V. Higher voltage (up to the 35V max of the driver) will give increased speed and torque.
It is absolutely necessary that you adjust the drivers coil current limits properly.
Here is a very simple test program using the CNC shield. Tested. The X axis motor should rotate one way then the other, indefinitely. Like the Stepper library bounce example. Change the step and dir pin numbers to test the other axes.
#include <AccelStepper.h>
const byte enablePin = 8; // for CNC shield
// Define a stepper and the pins it will use
AccelStepper stepper(AccelStepper::DRIVER, 2, 5);
void setup()
{
pinMode(enablePin, OUTPUT); // for CNC shield
digitalWrite(enablePin, LOW); // enable steppers
// Change these to suit your stepper if you want
stepper.setMaxSpeed(500);
stepper.setAcceleration(1000);
stepper.moveTo(1000);
}
void loop()
{
// If at the end of travel go to the other end
if (stepper.run()== LOW) // if the stepper has stopped
{
stepper.moveTo(-stepper.currentPosition()); // toggle the motor direction
}
}
Um, what does the above quoted statement mean? lol Would this have anything to do with the tiny pots on the drivers?
I apologize for my ignorance, I am new to controlling stepper motors outside of a 3D printer, and even then I run smoothie boards for ease of configuration. On the other hand, I do hacve quite a bit of experience working with servos, servo shields, and LEDs. This is just all new to me.
Also, the nema 17s state 1.5A per phase and they are bipolar. So, I'm figuring I will need to push at least 4A into the shield since I will only be running 1 stepper at a time, correct?
Yes. You must set the coil current limit on the motor drivers or risk damage to the motors and/or drivers. The Pololu A4988 page has instructions for making the adjustment. The Rsense resistors on many clone board are 0.1 Ohms, but you need to check what is actually installed on your boards.
0.1Ω sense resistors (Rcs) are marked R100
The A4988 drivers are good for 1A coil current without heat sink and forced air cooling (fan). They can handle 1.5A with a heat sink and fan. The DRV8825 drivers are good for 1.5A without heat sink and 2.0A with heat sink and fan.
2A per running motor is enough and gives bit of margin. More is always better since the power supply will be less stressed.