Help, stepper arduino code on motor shield v2.0

This is a special forum devoted to educators using Adafruit and Arduino products for teaching.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
HafizMATIL
 
Posts: 9
Joined: Tue Apr 29, 2014 12:09 pm

Help, stepper arduino code on motor shield v2.0

Post by HafizMATIL »

Hi there, I'm new in arduino and stepper motor . Basically i setup a bipolar stepper motor on to an arduino uno stack with motor shield kit v2.0 with the help on the tutorial . Can anyone help me on writing a code so that my stepper motor can rotate from 45degree to 90 degree and stop for 5 seconds and then go back to original position ( 45 degree) ?

Thank you

User avatar
Franklin97355
 
Posts: 23911
Joined: Mon Apr 21, 2008 2:33 pm

Re: Help, stepper arduino code on motor shield v2.0

Post by Franklin97355 »

Have you worked with the example code in the motor library? What code do you have now and what does it do? How will you know where the motor is when the program starts?

HafizMATIL
 
Posts: 9
Joined: Tue Apr 29, 2014 12:09 pm

Re: Help, stepper arduino code on motor shield v2.0

Post by HafizMATIL »

I've written this code:

#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

Adafruit_MotorShield AFMS = Adafruit_MotorShield();

Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);


void setup() {
Serial.begin(9600);


AFMS.begin();


}

void loop() {
Serial.println("Single coil steps");
myMotor->step(50, FORWARD, SINGLE);

}


but somehow there some problem occurred on my stepper motor.
I've attached a video on a forum , somehow i don't know why i can attached in here.
here it is :
http://forum.arduino.cc/index.php?topic=236745.0

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Help, stepper arduino code on motor shield v2.0

Post by adafruit_support_bill »

What motor are you using? Please post a link to the electrical specifications.

Also, you do not set the speed anywhere in your code. Try running the example code from the library. This code is known to work.

HafizMATIL
 
Posts: 9
Joined: Tue Apr 29, 2014 12:09 pm

Re: Help, stepper arduino code on motor shield v2.0

Post by HafizMATIL »

heres the spec of my motor :
http://www.oriental-motor.co.uk/Product ... &dwn=artnr

i did , it's still the same ( with and without setting the speed ) on the this example code :

#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

// 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 AFMS = Adafruit_MotorShield(0x61);

// Connect a stepper motor with 200 steps per revolution (1.8 degree)
// to motor port #2 (M3 and M4)
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);


void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Stepper test!");

AFMS.begin(); // create with the default frequency 1.6KHz
//AFMS.begin(1000); // OR with a different frequency, say 1KHz

myMotor->setSpeed(10); // 10 rpm
}

void loop() {
Serial.println("Single coil steps");
myMotor->step(100, FORWARD, SINGLE);
myMotor->step(100, BACKWARD, SINGLE);

Serial.println("Double coil steps");
myMotor->step(100, FORWARD, DOUBLE);
myMotor->step(100, BACKWARD, DOUBLE);

Serial.println("Interleave coil steps");
myMotor->step(100, FORWARD, INTERLEAVE);
myMotor->step(100, BACKWARD, INTERLEAVE);

Serial.println("Microstep steps");
myMotor->step(50, FORWARD, MICROSTEP);
myMotor->step(50, BACKWARD, MICROSTEP);
}

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Help, stepper arduino code on motor shield v2.0

Post by adafruit_support_bill »

There are two problems there:

1) You are trying to run a 2.3v motor on 5v.
2) Even at the rated voltage, the motor will draw too much current for the shield.

The shield is rated for 1.2A/Phase. The motor is rated at 1.5A/Phase @ 2.32 volts. Running it at 5volts, the motor will be trying to pull more than 3A from the shield.

This motor is better suited to a chopper type constant-current motor controller such as the gSheild - https://www.adafruit.com/products/1750

HafizMATIL
 
Posts: 9
Joined: Tue Apr 29, 2014 12:09 pm

Re: Help, stepper arduino code on motor shield v2.0

Post by HafizMATIL »

so what can i do besides purchasing a new shield ? cause i'm kinda in need the motor to run smoothly asap , as my fyp due in less than 48 hours. all i want is to make the motor to turn 45 degree and back .

HafizMATIL
 
Posts: 9
Joined: Tue Apr 29, 2014 12:09 pm

Re: Help, stepper arduino code on motor shield v2.0

Post by HafizMATIL »

if i've tried using lesser voltage supply , let's say 2AA which is a total of 3V will it work ?

HafizMATIL
 
Posts: 9
Joined: Tue Apr 29, 2014 12:09 pm

Re: Help, stepper arduino code on motor shield v2.0

Post by HafizMATIL »

1.2A/phase & 1.5A/phase , the difference is 0.3A , is it a big difference ?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Help, stepper arduino code on motor shield v2.0

Post by adafruit_support_bill »

At 3v, the current will be over 1.9A. That is more than 50% over spec. You either need to find a shield compatible with the motor, or a motor compatible with the shield. https://www.adafruit.com/products/324

HafizMATIL
 
Posts: 9
Joined: Tue Apr 29, 2014 12:09 pm

Re: Help, stepper arduino code on motor shield v2.0

Post by HafizMATIL »

do u know where can i find a motor with frame size less than 35mm?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Help, stepper arduino code on motor shield v2.0

Post by adafruit_support_bill »

Pololu has a few. Here's one:
http://www.pololu.com/product/1205

HafizMATIL
 
Posts: 9
Joined: Tue Apr 29, 2014 12:09 pm

Re: Help, stepper arduino code on motor shield v2.0

Post by HafizMATIL »

hi there, i manage to sort my motor. so here my currently code:
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

Adafruit_MotorShield AFMS = Adafruit_MotorShield();

Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);


void setup() {
Serial.begin(9600);


AFMS.begin();

myMotor->setSpeed(10); // 10 rpm
}

void loop() {
Serial.println("Single coil steps");
myMotor->step(50, FORWARD, SINGLE);
myMotor->step(50, BACKWARD, SINGLE);
}

the motor will turn back and fort since the code is written forward and backward , so if i want it to turn 50 steps and pause for 5 seconds , what code should i add into ?

thanks

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Help, stepper arduino code on motor shield v2.0

Post by adafruit_support_bill »

Looks like you already have the 50 forward and 50 reverse. To delay for 5 seconds, add a

Code: Select all

delay(5000);

HafizMATIL
 
Posts: 9
Joined: Tue Apr 29, 2014 12:09 pm

Re: Help, stepper arduino code on motor shield v2.0

Post by HafizMATIL »

thank you, really appreciate it .

Locked
Please be positive and constructive with your questions and comments.

Return to “For Educators”