I need some help with values for driving my stepper motors using the Adafruit Motor Shield (V2). The motor is running but it isn't turning as much as I expect, and I don't understand the speed control. I have set the motor for 48 steps per rev, and then asked for 48 steps - so I expect one revolution - but I only get about 1/4 of a rev. Also, the speeed control appears to make no difference if set to either 20 or 200.
The motor commands are being send via bluetooth on an HC-06 device; that section of code is working fine.
// Bluetooth connection to HC-05
#include <SoftwareSerial.h> // use the software uart
SoftwareSerial bluetooth(6,7); // RX, TX
// use the Adafruit Motor Library ver 2
#include <Wire.h>
#include <Adafruit_MotorShield.h>
// Create the motor shield object with the default I2C address, for x/y coordinate ontrol
Adafruit_MotorShield AFMSpen = Adafruit_MotorShield(0x60);
// Connect stepper motors with 48 steps per revolution (8 degree)
Adafruit_StepperMotor *stepper_pen1 = AFMSpen.getStepper(48, 1);
Adafruit_StepperMotor *stepper_pen2 = AFMSpen.getStepper(48, 2);
void setup() {
Serial.begin(115200);
Serial.print("Sketch: "); Serial.println(__FILE__);
Serial.print("Uploaded: "); Serial.println(__DATE__);
Serial.println(" ");
pinMode(13, OUTPUT); // for LED status
bluetooth.begin(9600); // start the bluetooth uart at 9600 which is its default
delay(200); // wait for voltage stabilize
bluetooth.print("AT+NAMEquilkin.com");
delay(3000); // wait for settings to take affect.
AFMSpen.begin(); // create with the default frequency 1.6KHz
stepper_pen1->setSpeed(20);
stepper_pen2->setSpeed(20);
}
void moveMotors(int instr)
{
int stepType = DOUBLE;
// note: may need to reverse the sense of these commands depending on wiring of motors
if (instr == 2) {
stepper_pen1->step(48, FORWARD,stepType);
}
if (instr == 1) {
stepper_pen1->step(48,BACKWARD,stepType);
}
}
void loop()
{
if (bluetooth.available()) { // check if anything in UART buffer
char action = bluetooth.read(); // action value is text character
if (action == 53) { // '5'
stepper_pen1->release();
stepper_pen2->release();
}
else {
moveMotors(action - 48);
digitalWrite(13,!digitalRead(13)); // toggle the onboard LED
}
}
}
You have linked to a low impedance (2.8V/1.68A) stepper motor.
This is no match for an Adafruit brushed DC motor shield.
You will either burn the supply or the shield, and maybe the motor.
This motor requires a current controlled driver, like the DRV8825. And a 12volt or higher supply. If you want performance (torque at higher speeds), then use a TB6600 (or similar) driver and a 24volt supply.
Leo..
Thanks. The Adafruit Motor Shield is designed for stepper motors - It has TB6612 drivers. But it's quite possible that I have purchased incompatible motors (although I am driving them with a 3V supply which has current limiting)
I need to continue using the Adafruit Motor Shields, so it's easier (and cheaper!) to buy different motors. I have found these on eBay - rated at 12-24V, 1.7A - would they be a better choice?
No, it's not. It's a common brushed DC motor H-bridge, and can only drive certain (old-school) high-impedance steppers. Adafruit has a special 12volt/350mA stepper motor for this shield. I think that shield is falsely advertised as a stepper motor driver, because most modern motors are low-impedance, requiring current controlled drivers.
Leo..
Note that with this shield, and the right motors, performance will suffer.
If you only need relative low speed, than this won't matter.
If you need torque at higher speeds, then a different driver is the only solution.
You posted a link to multiple motors. Why?
There is a "CNC shield" available that can accommodate four DRV8825 driver modules.
Leo..
Thanks Leo. I think I'm out of ny depth here. I chose the Adafruit shield because it has ready-written library for the Arduino, wih simple high-level commands for running the motors (as per my posted code). I could use the CNC shield but cannot find any software library for it. Seems I need to learn about 'GRBL' - I have no idea what that is. I simply want to drive four steppers for use in model building - e.g a remote-control model car. I would have thought that this was quite a common requirement!
Are you sure you want to use a stepper motor for a RC car? A stepper motor draws max current all the time, even more when it's not turning. Not good for battery life.
A (geared) brushed DC motor could be a much better solution. The shield you have is only suitable for small motors anyway, the yellow ones being most popular.
Leo..
In my posted code, I have the command stepper_pen1->release(); - when I send the appropriate control signal, the current on my PS drops from 2 amps to zero. So they don't take current all the time (not using this Shield and its software library anyway).
And yes I do want stepper control because it's not a simple RC car, I want to control steering and distance moved accurately.
Whilst you'e pointed out that my motors aren't suitable for my Adafruit shield (thanks!), the motors aren't getting hot running on 3V (they're only active for a few seconds at a time). I'm not convinced that an incorrect-voltage motor is the reason for it not behaving as the software dictates, but I will try with the 'Yellow ones' - can you post a link please?
Well, the incorrect motor for your driver is not the only problem with your setup:
You cannot set the steps/rev via software. This is a HW feature of your stepper. The motor you linked needs 200 steps per rev in full step. That cannot be changed. You can increase this by using 'microstepping', but I don't know if this really works with you poorly suited combination of driver and motor.
As @Wawa already pointed out, the CNC shield can be equipped with 4 DRV8825 stepper drivers. These are current controlling drivers with step and dir input. There are many libraries that can be used together with such a step/dir driver.
Absolute minimum motor voltage for the TB6612 is 4.5volt. See datasheet.
The FETs of the H-bridges could get out of saturation below that, and that's bad.
Make sure you have a spare shield.
There are geared brushed DC motors with encoders, if you want accurate positioning.
Study the Pololu website.
Leo..
OK, I have now switched to using a CDC shield with drivers which are clones of the Pololu ones. I am getting on much better.
This was after I found (and read through) this post which I hadn't seen before, and only arrived at very indirectly.
The odd thing is, that even if I search for the title 'Stepper Motor Basics' in this forum, the article is not found (until I also know the author and do an advanced search!)
Make sure you set the reference voltage on these stepper drivers before you connect the stepper motor. That also depends on the value of the current sense resistors that are fitted on the clone boards. The Pololu site can help you with the calculations.
The driver/motor supply must be at least 8volt, but 12-24volt is much better.
You will see on your lab supply that current will go down with increased voltage. Normal, because these drivers work like buck converters.
Leo..