Sleep Mode for a Stepper Motor

I have a bipolar stepper motor running on a battery that needs to switch off when the joystick in in the neutral position (to stop over heating and battery life). A DC motor won’t do as I need the small increments to control a laser over large distances (building site) The shield is for a Uno from DF robots
http://www.dfrobot.com/index.php?route=product/product&path=35_124&product_id=69#.V6EqRfl9670
The shield does not have a sleep option
I’ve tried switching the phases LOW and HIGH in the loop but no joy
Here is the basic script

#include <Stepper.h>

const int num_step = 200; // motor steps per revolution
const int pwm_cha = 6;
const int dir_cha = 7;
const int pwm_chb = 4;
const int dir_chb = 5;

int Pot1 = A1;
int val;

Stepper stepper(num_step, dir_cha, dir_chb);

void setup()
{
Serial.begin(9600);
pinMode(pwm_cha, OUTPUT);
pinMode(pwm_chb, OUTPUT);
digitalWrite(pwm_cha, HIGH);
digitalWrite(pwm_chb, HIGH);

}

void loop()
{
int PVal=analogRead(Pot1);
if (PVal >= 507 || PVal <= 517)
{
// This is the neutral bit that needs to turn off the 2 Phases
}
if (PVal > 517 )
{
int K= map (PVal, 518,1023,0,150);
int S=map (K, 0,150,0,num_step);
stepper.setSpeed(K); //this sets the speed of the stepper motor
stepper.step(S); //this sets the direction
Serial.print(“Forward, K=”);
Serial.print(K);
Serial.print(" PVAL=");
Serial.println(PVal);
}
if (PVal < 507 )
{
int K= map (PVal, 0,506,150,0);
int S=map (K, 0,150,0,num_step);
stepper.setSpeed(K); //this sets the speed of the stepper motor
stepper.step(-S); //this sets the direction
Serial.print(“Backward, K=”);
Serial.print(K);
Serial.print(" PVAL=");
Serial.println(PVal);
}

}

// End of file

I’ve tried to slip this bit in but still no joy

// declaration here!
int val = 0;
int prev;

void loop() {

// keep the previous value
prev = val;

// just set the value
val = analogRead(A1); // read the input on analog pin 0:

// compare the previous value
if (val > prev) {
Serial.println(“up”);
} else if (val < prev) {
Serial.println(“down”);
}

// and no need to leave empty an else block

}
Thanks in advance

Laser.ino (1.29 KB)

That's not a stepper motor shield. Use an A4988 or DRV8825 based solution, assuming your (unspecified) motor is 1.2A or less.

While you're waiting for that to arrive, try tuning off the two PWM pins. That should disable the L298 outputs. But I'm not sure because your pin names don't match DFRobot's names.

Thanks MorganS
I stripped out all the range finder, XBee/easy driver, encoders, from the code and stripped the code back to bare minimum just to run the stepper motor. I run an XBee shield on top of the stepper shield. I walk around the site taking measurements with an Uno and LCD that drives the laser range finder via the stepper motor. The laser sits on the stepper and I get angles and info as I follow the laser which I drive via joystick.
The problem is the stepper drains the battery and gets hot and when the volts drop too far and I drive the stepper, the Uno really dies. The gearing of the stepper to laser holds stepper in position so I don’t need the stepper on all the time, as the norm, but the Uno on so the keep the info.
I’ve re-posted the script from the DF Robots manual.
It might help some one else

#include <Stepper.h>

const int num_step = 200; // motor steps per revolution
const int E1 = 6;
const int M1 = 7;
const int E2 = 5;
const int M2 = 4;

int XaxisPot = A1;
int val;

Stepper stepper(num_step, M1, M2);

void setup()
{
Serial.begin(9600);
pinMode(E1, OUTPUT);
pinMode(E2, OUTPUT);
digitalWrite(E1, HIGH);
digitalWrite(E2, HIGH);
}

void loop()
{
int XaxisVal = analogRead(XaxisPot);
if (XaxisVal >= 510 || XaxisVal <= 525)
{
//digitalWrite(M1, LOW);
//digitalWrite(M2, LOW);
//digitalWrite(E1, LOW);
//digitalWrite(E2, LOW);
//Serial.println (“Motor Stopped”);
}
if (XaxisVal > 526 )
{
int K= map (XaxisVal, 526,1023,0,150);
int S=map (K, 0,150,0,num_step);
stepper.setSpeed(K); //this set the speed of the stepper motor
stepper.step(S); //this set the direction
Serial.print("Forward, K = “);
Serial.print(K);
Serial.print(” X Axis Value = ");
Serial.println(XaxisVal);
}
if (XaxisVal < 509 )
{
int K = map (XaxisVal, 0,509,150,0);
int S = map (K, 0,150,0,num_step);
stepper.setSpeed(K); //this set the speed of the stepper motor
stepper.step(-S); //this set the direction
Serial.print(“Backward, K = “);
Serial.print(K);
Serial.print(” X Axis Value =”);
Serial.println(XaxisVal);
}
}

As I suspected, your code flipped pins 4 and 5.

It's really odd stepper code though. Depending on the joystick position, it sets a speed and then (probably) takes one step. Then it checks the joystick again and sets the speed again. I guess that part is working for you.

So what happens when you remove the comments from digitalWrite(E1, LOW) ?

Hi again Any variations of the comments in the center position either lock the motor or do little. I've tried HIGH, LOW, on all of them

Hi Gerry,

first remark: pls use code tags (</>) when posting a code; that makes it easier to copy your code into a text editor (have a look at the forum rules).

Get rid of your current driver and follow @MorganS advice to go with a REAL stepper motor driver.
If a A4988 or DRV8825 are sufficient for your application (which means that they provide enough current), then go with them. If not, then you have to go with a bigger driver (based on TB6560, TB6600 or equivalents).

All the mentioned drivers will come with ENABLE pins which will allow for shutting the motor current off during idle (standstill) times.

If you search for standstill current reduction you will also find drivers (e.g. TMC2100 or the bigger TB6xxx) which let you configure automatic standstill current reduction mode, if you need a little bit torque when the motor doesn’t move.

This will give you enough torque and at the same time it saves a lot of energy. Side effect: the driver won’t get overheated while the motor stands still.

GerryHamilton: Hi again Any variations of the comments in the center position either lock the motor or do little. I've tried HIGH, LOW, on all of them

Then something else is wrong. Taking the enable line on that chip LOW should disable its output.

If you disable the driver you'll risk losing position. Use a stepper driver with the facility to drop current to a fraction of normal whenever the motor is stationary. This is a pretty standard feature, even halving the current reduces power consumption by about 4 times.

Unfortunately most of the cheap little DRV8825 and A4988 modules fix the current setting using an on-board preset-pot, so you can't control it programmatically.

Here's a good one, you can either drop the enable signal or drop standby current to 50 or 20 %, I recently bought one for $9.50 but don't remember where, maybe DFR.

https://www.amazon.com/SainSmart-Router-Single-Stepper-Stepping/dp/B008BGLOTQ/ref=sr_1_6?ie=UTF8&qid=1470317481&sr=8-6&keywords=stepper+driver+board

http://www.sainsmart.com/zen/documents/20-019-200/Tb6560%20stepping%20motor%20driver%20...pdf

If (small) size matters you could go with a SilentStepStick (TMC2100 or TMC2130) from Watterott electronics. These drivers go up to 1.2A/coil and are pin compatible with drv8825 or A4988.

They automatically recognize motor standstill and then lower the current to a third, which then saves 90% energy compared to motor running.