Pages: [1]   Go Down
Author Topic: This motor code cant turn the stepper motor in one direction  (Read 540 times)
0 Members and 1 Guest are viewing this topic.
universe
Offline Offline
Sr. Member
****
Karma: 0
Posts: 258
I'm enjoying my Life
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I just bought motor shield like this http://www.cutedigi.com/arduino-shields/motor-driver-shield-for-arduino.html
Then follow the step, till I download the example sketch:

Code:
// Adafruit Motor shield library
// copyright Adafruit Industries LLC, 2009
// this code is public domain, enjoy!

#include <AFMotor.h>

// Connect a stepper motor with 48 steps per revolution (7.5 degree)
// to motor port #2 (M3 and M4)
AF_Stepper motor(48, 2);

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

  motor.setSpeed(10);  // 10 rpm   
 
}

void loop() {
  Serial.println("Single coil steps");
  motor.step(500, FORWARD, SINGLE);
}
 

Is there anyone knows why my stepper just turn back and forth? what is wrong with the code?
Logged

South Texas
Offline Offline
Edison Member
*
Karma: 8
Posts: 1025
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You don't have the motor wired correctly.
Logged

0
Offline Offline
Shannon Member
****
Karma: 216
Posts: 12556
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Stepper motors need the 4 phases energized in the correct order, and with 4 wires there are 3 fundamental ways to
hook it up (ignoring cyclic rotations of the phases or reversing the motor), 2 of which don't work, 1 of which does...

If the phases are marked A+, A-, B+, B- then its easy, just ensure you alternate from A to B:

A+/B+/A-/B-   or  A-/B+/A+/B- will work for instance.  However  anything thats AABB or ABBA or BAAB etc won't work.

However sometimes phases are unmarked or marked "1,2,3,4" which frankly could mean anything - trial and error are
then needed (or using a multimeter to identify A winding from B winding).
Logged

[ I won't respond to messages, use the forum please ]

universe
Offline Offline
Sr. Member
****
Karma: 0
Posts: 258
I'm enjoying my Life
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, you are right, I wire it wrong. Thank you so so much!
Logged

Pages: [1]   Go Up
Jump to: