Pages: [1]   Go Down
Author Topic: How to spin motor backwards and where to plug it ?  (Read 1318 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 27
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello.
I have this motor shield "41468" http://emartee.com/product/41468/
And I tried this code:

Code:
// ConstantSpeed.pde
// -*- mode: C++ -*-
//
// Shows how to run AccelStepper in the simplest,
// fixed speed mode with no accelerations
// Requires the AFMotor library (https://github.com/adafruit/Adafruit-Motor-Shield-library)
// And AccelStepper with AFMotor support (https://github.com/adafruit/AccelStepper)
// Public domain!

#include <AccelStepper.h>
#include <AFMotor.h>

AF_Stepper motor1(200, 1);


// you can change these to DOUBLE or INTERLEAVE or MICROSTEP!
void forwardstep() {  
  motor1.onestep(FORWARD, SINGLE);
}
void backwardstep() {  
  motor1.onestep(BACKWARD, SINGLE);
}

AccelStepper stepper(forwardstep, backwardstep); // use functions to step

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

void loop()
{  
   stepper.runSpeed();
}

Motor spins clockwise if I plug it to black+red wires and black+blue on the shield (image attached).
- I am not sure what are the right connectors on the shield for the 2 wire motors.
- How to make it spin in the other direction? Shield says it has "H bridges" which I understand is what I need.

Thank you.


* 2011-12-08 23.17.41_small.jpg (158.29 KB, 1024x768 - viewed 29 times.)

* mshieldv1-schem.png (42.96 KB, 1485x1121 - viewed 60 times.)
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 202
Posts: 8716
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The motor has only two wires so it isn't a stepper motor.

A DC motor connects to the two M1 (or M2, or M3, or M4) terminals.  The H-bridge will switch those two terminals from +,- to -,+ to change direction.  

See the instructions here for DC Motors: http://www.ladyada.net/make/mshield/use.html

The sample program uses the M3 connector:
Code:
#include <AFMotor.h>

AF_DCMotor motor(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Motor test!");
  
  motor.setSpeed(200);     // set the speed to 200/255
}

void loop() {
  Serial.print("tick");
  
  motor.run(FORWARD);      // turn it on going forward
  delay(1000);

  Serial.print("tock");
  motor.run(BACKWARD);     // the other way
  delay(1000);
  
  Serial.print("tack");
  motor.run(RELEASE);      // stopped
  delay(1000);
}
« Last Edit: December 09, 2011, 10:02:22 am by johnwasser » Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

0
Offline Offline
Newbie
*
Karma: 0
Posts: 27
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't understand how the connectors are grouped.
Which would be the two M1 connectors for example? Because they are grouped by 5  smiley-confuse
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 202
Posts: 8716
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you look at the picture you took of your board, the Red and Blue wires are in the M1 terminals.  Note the label "M1" just above them.  The center terminal is a Ground terminal used for some types of stepper motors.  The bottom two terminals are the M2 terminals.  Note the label "M2" just to the right of them.  The M3 and M4 terminals are on the other end of the board.

Code:
AF_DCMotor motor1(0, MOTOR12_64KHZ); // Control DC motor on M1 terminals. 64KHz pwm
AF_DCMotor motor2(1, MOTOR12_64KHZ); // Control DC motor on M2 terminals. 64KHz pwm
AF_DCMotor motor3(2, MOTOR12_64KHZ); // Control DC motor on M3 terminals. 64KHz pwm
AF_DCMotor motor4(3, MOTOR12_64KHZ); // Control DC motor on M4 terminals. 64KHz pwm
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

0
Offline Offline
Newbie
*
Karma: 0
Posts: 27
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yesterday with your code I kept testing on all pins and it only worked in one direction.
Today I connected the M1 you mentioned (blue+red) from image and replaced
AF_DCMotor motor(2, MOTOR12_64KHZ);
with
AF_DCMotor motor(1, MOTOR12_64KHZ);

And works nicely in both directions. Maybe the M2 is not one of the ones with H bridge, I test more later, M1 works in both directions.
Thanks for all your help  smiley
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 27
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

With this code I am able to make motors 1,3,4 to work but the #2 doesn't move at all. Maybe I burned something when I tested the pins to use (weeks ago)  smiley-red.
Is there some part on the board that I could check/replace? Anything else that might cause M2 not to work when 1,3,4 work?
I used the code below and just edited this number: "AF_DCMotor motor(1"
Thank you.

Code:
#include <AFMotor.h>

AF_DCMotor motor(1, MOTOR12_1KHZ); // create motor #1, 64KHz pwm

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Motor test!");
 
  motor.setSpeed(200);     // set the speed to 200/255
}

void loop() {
  Serial.print("tick");
 
  motor.run(FORWARD);      // turn it on going forward
  delay(1000);

  Serial.print("tock");
  motor.run(BACKWARD);     // the other way
  delay(1000);
 
  Serial.print("tack");
  motor.run(RELEASE);      // stopped
  delay(1000);
}
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 202
Posts: 8716
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If the M2 terminals don't work it is likely the L293D chip at that end of the board is fried.  It's in a socket so it won't be hard to replace.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can determine faulty L293D chip by replacing it between other channel and if only chip itself is faulty then channel 2 should work with chip taken other working channel.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 27
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, I think most probably I burned one of the chips. Yesterday I stopped playing with it for a while, I will test that soon.
Thanks for the suggestions.
Logged

Pages: [1]   Go Up
Jump to: