I want to stop a stepper motor with Arduino Motor Shield

Hi guys,
I’ve just bought a Arduino Motor Shield and I’d like to connect a bipolar stepper motor (with 4 cables) to that board.
I want to stopand restart stepper motor with the keys of the computer keyboard ( es. a=go, b=stop).
I’ve got just the program, but I can’t continue it.
Thank you

prodottofinale.ino (1.76 KB)

..very confusing names in your program. U dont use PWM with your stepper.
Which motor controller do u use?

Sorry, but I gave the name of the program, I’m Italian.
I also apologize for my English, it isn’t good.

The Stepper Motor is : http://www.lamtechnologies.com/Product.aspx?lng=IT&idp=M1233032

Thank you

..and the controller card ?

Is that : http://www.velleman.eu/downloads/0/modules/usermanual_vma03.pdf

The names you are using for your motor pins are not really appropriate because the specific pins do not control direction and neither do they use PWM. They are just 4 connections to the motor and would probably be less confusing if they were simply called motorPin1, motorPin2, motorPin3 and motorPin4.

Assuming your code works to make the motor move you haven’t got any code for detecting a button press.

In principal all you need is some code that sets a variable to true when one button is pressed and sets it to false when the other button is pressed. Then the code to run the steppers only runs if the value of the variable is true. And instead of running for myStep steps for every iteration of loop your motor should just move 1 step. That way the buttons get tested between each step.

…R

..give me a litte time.. I'll write a start for new code..

Can you take me the correct program please?
I'm new in this application, and I'm not very good.

But i would be by key on the keyboard, and not with button.

Thank you :slight_smile:

take a look at this example

long time,now; 

/* stepmotore sequence 
 "Gray-kode" 
 0-1000 =8
 1-1100 =12
 2-0100 =4
 3-0110 =6
 4-0010 =2
 5-0011 =3
 6-0001 =1
 7-1001 =9
 */
byte sekv[8]={8,12,4,6,2,3,1,9}; 
byte pointer = 0; // remember current position
char key;

#define m1 2 // m1 and m2 => coil A   m3, m4 to coil B !!  CHANGE pins to match
#define m2 3 
#define m3 8
#define m4 9 

//**************************************************************************
void setup()
{
  pinMode(m1,OUTPUT);  
  pinMode(m2,OUTPUT);
  pinMode(m3,OUTPUT);
  pinMode(m4,OUTPUT);

  Serial.begin(115200);  //    need to read command    f=forware,  r=reverse,  any other key =stop
  // 
  motor(0); 
  now=millis(); 
 
}
//**************************************************************************
void loop()
{
  // get a command
  if (Serial.available())  key=Serial.read();  // read 'new' commamd
 
    switch (key)
    {
    case 'f': // take one step forware
      {
        stepforw();
        break;
      }
    case 'r': // take a step backwards
      {
        stepreverse();
        break;
      }

   }  
  // wait just a moment..
  while((millis()-now)<30) {}; 
  now=millis();
}

//**************************************************************************
int motor(int posisjon)
{
  // this part can be written with less code
  byte mm=sekv[posisjon]; 
  // så sjekker vi enkelt de 4 i sekvens..:
  if ((mm & 8)>0) digitalWrite(m1,HIGH); 
  else digitalWrite(m1,LOW);
  if ((mm & 4)>0) digitalWrite(m2,HIGH); 
  else digitalWrite(m2,LOW);
  if ((mm & 2)>0) digitalWrite(m3,HIGH); 
  else digitalWrite(m3,LOW);
  if ((mm & 1)>0) digitalWrite(m4,HIGH); 
  else digitalWrite(m4,LOW);
}
//**************************************************************************
void stepforw() // 
{ 
  pointer++; 
  if (pointer>7) pointer=0; 
  motor(pointer);
}
//**************************************************************************
void stepreverse() 
{ 
  pointer--; 
  if (pointer>7) pointer=7; 
  motor(pointer);
}
//**************************************************************************

You’ve got the wrong controller for that motor, it needs a constant-current chopper
drive capable of 3.5A output really. The L298 can’t deliver the current needed and
that motor will only go very slowly driven from an H-bridge. The windings are
probably something like 0.5 to 1 ohm, so you’ll be wasting most of your power in
the L298 darlington stages…

Low impedance stepper motors need current-control drive, high impedance motors
can be voltage driven.

Thank you, but i don’t understand what i really i have to do.

I did copy and paste from your exercise, but it does not work.
Can you make me all the exercise, so i finish ??

Thank you

I now see that your shield has hardwired inputs to always be different (DIRA = !DIRA2).
They then use the enable line to turn coil on/off (possible with PWM to DC-motors)
...
There is no current control, so even its possible to use your shield, it is be not very smart as the motor will get very hot.
I suggest u buy a stepper controller like
http://www.ebay.com/itm/0-2-5A-Single-Axis-TB6600-CNC-Engraving-Machine-Stepper-Motor-Driver-Controller-/261525880253?pt=LH_DefaultDomain_0&hash=item3ce4283dbd
or
http://www.ebay.com/itm/CNC-Router-1-Axis-Controller-Stepper-Motor-Drivers-TB6560-3A-driver-board-TE-/111290455455?pt=LH_DefaultDomain_2&hash=item19e96d959f
or
http://www.ebay.com/itm/A4988-A4983-StepStick-Stepper-motor-driver-3D-Printer-driver-module-Reprap-PrusM-/271555278373?pt=LH_DefaultDomain_0&hash=item3f39f4b625

The advantage with this kind of controller, is that they allow you to run motor if smaller steps (microstepping)
and You get full control on the current flow.

Thank you so much, but can you make me the program of arduino??

AccelStepper library perhaps?

I have the code changed a little…
Set jumpers to match picture.
Code may be changed to add a ‘relax’ key where enable-lines are set low. (to stop current flowing)
Your motor will get hot. Abort before reaching 70 degs.

long time,now; 

/* stepmotore sequence 
 "Gray-kode" 
 0-00 =0
 1-01 =1
 2-11 =3
 3-10 =2
 */
byte sekv[4]={0,1,3,2}; 
byte pointer = 0; // remember current position
char key;

#define drA 2
#define enA 3 
#define drB 8
#define enB 9 

//**************************************************************************
void setup()
{
  pinMode(drA,OUTPUT);  
  pinMode(drB,OUTPUT);
  pinMode(enA,OUTPUT);
  pinMode(enB,OUTPUT);
  // use theese
  digitalWrite(enA,HIGH);  //enable coil A  and B
  digitalWrite(enB,HIGH);
  /* or this alternative for less current
  analogWrite(enA,150);  //enable coil A  and B
  analogWrite(enB,150);
  */


  Serial.begin(115200);  //    need to read command    f=forware,  r=reverse,  any other key =stop
  // 
  motor(0); 
  now=millis(); 
 
}
//**************************************************************************
void loop()
{
  // get a command
  if (Serial.available())  key=Serial.read();  // read 'new' commamd
 
    switch (key)
    {
    case 'f': // take one step forware
      {
        stepforw();
        break;
      }
    case 'r': // take a step backwards
      {
        stepreverse();
        break;
      }

   }  
  // wait just a moment..
  while((millis()-now)<30) {}; 
  now=millis();
}

//**************************************************************************
int motor(int posisjon)
{
  // this part can be written with less code
  byte mm=sekv[posisjon]; 
  // så sjekker vi enkelt de 4 i sekvens..:
  if ((mm & 2)>0) digitalWrite(drA,HIGH);  
  else digitalWrite(drA,LOW);
  if ((mm & 1)>0) digitalWrite(drB,HIGH); 
  else digitalWrite(drB,LOW);
}
//**************************************************************************
void stepforw() // 
{ 
  pointer++; 
  if (pointer>3) pointer=0; 
  motor(pointer);
}
//**************************************************************************
void stepreverse() 
{ 
  pointer--; 
  if (pointer>3) pointer=3; 
  motor(pointer);
}
//**************************************************************************

jumpers.jpg

thank you very much, I try it tomorrow morning and let you know how it went