Go Down

Topic: Connecting a motor to a Arduino motor shield (Read 2789 times) previous topic - next topic

997_1

I have hours of research into this and have all the parts I need and almost all my code written. Pretty simple project: on and off switch, Pen., 12V 1.5 Amps power, Arduino Mega, Arduino motor shield, and stepper motor. I need a little assistance on the physical connection and the order in which to put connections (Stepper mystepper(200, #, #, #, #, #, #);  //# of steps and connections) I have a 2 phase 1.8 degree stepper motor from orientalmotor, it has six connections see 2 phase 6-lead wire type:
http://catalog.orientalmotor.com/browser?cid=1002&plpver=11&prodid=3001048&itemid=12006&assetid=26061&qlty=100&size=150&mode=50

My motor shield has a L298P driver my available connections that I believe I will use are PWM A , PWM B, Dir A, Dir B, I do not know how to physically hook this up though. Any help appreciated here. Also if there will need to be resistors not on the board please let me know.

Chagrin

You're going to leave two wires disconnected and use the wires per the "4 leads connection" diagram on your linked doc. In this bipolar configuration you do not need any resistors.

The two pairs of wires will then go to the M+ and M- connections on your shield. If it doesn't run right then you might have one of the pairs backwards.

If you need more specific help then please provide a link to the exact motor driver shield you are using.

997_1

Thank you Chargrin. I am throwing in the towel on this project. My hope is this post will help someone else out there.

To those who want a high speed (1500 RPM) stepping motor configuration: here is what I experienced.

I purchased the Arduino Mega 2560, Arduino Motor shield, and a few switches and pot. The motor selection took a couple of days but ended up with

http://catalog.orientalmotor.com/item/stepping-motors--1068/pk-series-stepping-motors/pk258-02a?&plpver=11&origin=advsrch&by=prod&filter=0&categid=1068&prodid=3001048

This matches very closely to what the L298P on the motor shield is capable of, unipolar, and should have provided the RPMs I required.

Connect the motor shield to Mega, connect the motor to the motor shield (via Tom at Arduino) by installing two center taps together in the Vin screw connector. Plug A,-A, B,-B into the other four connectors in the order of the diagram on the motor. Don't worry if you get it wrong, it will let you know but no permanant damage. I used a 12VDC 1.5 Amp power supply, this is a little under what you will need I suggest going up on amps, but not too far. Also do not hook up bipolar, the L298P will get hot very quickly, this is done by not connecting the two center taps to the Vin. The Amps you would have to supply the motor is more then the L298P can handle (by my understanding). Ok now DL your code. I will attach two. One is from Tom at Arduino it spins the motor one direction one revolution, then the other. 

#include <Stepper.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
                          // for your motor

// initialize the stepper library on the motor shield
Stepper myStepper(stepsPerRevolution, 12,13);     

// give the motor control pins names:
const int pwmA = 3;
const int pwmB = 11;
const int brakeA = 9;
const int brakeB = 8;
const int dirA = 12;
const int dirB = 13;

int x = 0;
void setup() {
Serial.begin(9600);
// set the PWM and brake pins so that the direction pins  // can be used to control the motor:
pinMode(pwmA, OUTPUT);
pinMode(pwmB, OUTPUT);
pinMode(brakeA, OUTPUT);
pinMode(brakeB, OUTPUT);
digitalWrite(pwmA, HIGH);
digitalWrite(pwmB, HIGH);
digitalWrite(brakeA, LOW);
digitalWrite(brakeB, LOW);

// initialize the serial port:
Serial.begin(9600);
// set the motor speed (for multiple steps only):
myStepper.setSpeed(200);
}


void loop() {
Serial.println("one direction");

for (int steps = 0; steps < stepsPerRevolution; steps++) {
   myStepper.step(1);
  delay(10);
}

// wait one second:
delay(1000);
Serial.println("the other direction"); for (int steps = 0; steps <
stepsPerRevolution; steps++) {
   myStepper.step(-1);
delay(10);
}
// wait one second:
delay(1000);
}
 
The other is one I built to vary the motor depending on a pot input, it is incomplete as I came to a conclusion.

#include <Stepper.h>
   
Stepper mystepper(200,12,13);  //# of steps and connections
int motorPin= 0; // the potentiometer
const int pwmA = 3;
const int pwmB = 11;
//const int brakeA = 9;
//const int brakeB = 8;
const int dirA = 12;
const int dirB = 13;
//int pushButton= 7;
//int PFB= 1; // the Switch
void setup()
{
  Serial.begin(9600);
pinMode(pwmA, OUTPUT);
pinMode(pwmB, OUTPUT);
//pinMode(brakeA, OUTPUT);
//pinMode(brakeB, OUTPUT);
digitalWrite(pwmA, HIGH);
digitalWrite(pwmB, HIGH);
//TCCR2B = _BV(CS21); /// this is will change the pwm from a divide by 64 scale
}
void loop()
{
//PFB =digitalRead(pushButton);
//digitalWrite(PFB, pushButton);
//Serial.println(pushButton);
motorPin= analogRead (0);
motorPin= motorPin/4;
Serial.println(motorPin);
if (motorPin > 100) // if the value of the Pin is >100
{
mystepper. setSpeed (255);
mystepper.step(1);
//delay (1);
}}

Both sketches will turn the motor as described in the sketch.

So why stop?

I have a limited time and budget, this is for work. What happens? The motor only spins at one RPS. Far from the RPM required. This was the max I could get out of it in any configuration I tried. Best results with USB and Power supply plugged in but result in more current then the shield is designed for. Why not go with a smaller motor? The moment of inertia required is high so applications such as printer steppers will not come close.

A note on support: this configuration with the RPM I am needing is limited. If your application requires a high RPM find another way, IMO. I want to give thanks to Grumpy_Mike and Chargin for responding to forum post. I also want to give thanks to Tom at Arduino for answering emails, he is a professor and is a busy man his time is limited but still took time to answer a few emails.

I hope this helps someone in the future as my searches on this subject did not turn up much.

Best of luck to all!


Go Up