Go Down

Topic: How to spin motor backwards and where to plug it ? (Read 1 time) previous topic - next topic

adrianTNT

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

Code: [Select]
// 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.

johnwasser

#1
Dec 08, 2011, 11:38 pm Last Edit: Dec 09, 2011, 04:02 pm by johnwasser Reason: 1
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: [Select]

#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);
}
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

adrianTNT

I don't understand how the connectors are grouped.
Which would be the two M1 connectors for example? Because they are grouped by 5  :~

johnwasser

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: [Select]

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

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

adrianTNT

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  :)

adrianTNT

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: [Select]
#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);
}


johnwasser

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.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

kkuula

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.

adrianTNT

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.

Go Up