If your stepper requires a higher current than the L293 can provide (600 mA for the L293D), you can use the SN754410 chip that handles up to 1 amp. For current up to 2 amps, you can use the L298 chip.A simple way to connect an L298 to Arduino is to use the SparkFun Ardumoto shield (DEV-09213). This plugs on top of an Arduino board and only requires external connection to the motor windings; the motor power comes from the Arduino Vin pin. In1/2 is controlled by pin 12, and ENA is pin 10. In3/4 is connected to pin 13, and ENB is on pin 11. Make the following changes to the code to use the preceding sketch with Ardumoto:
/*
* Stepper_bipolar sketch
* stepper is controlled from the serial port.
* a numeric value followed by '+' or '-' steps the motor
* http://www.arduino.cc/en/Reference/Stepper
*/
#include <Stepper.h>
// change this to the number of steps on your motor
#define STEPS 24
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper(STEPS, 12,13);
int steps = 0;
void setup()
{
pinMode(10, OUTPUT);
digitalWrite(10, LOW); // enable A
// set the speed of the motor to 30 RPMs
stepper.setSpeed(30);
Serial.begin(9600);
pinMode(11, OUTPUT);
digitalWrite(11, LOW); // enable B
}
void loop()
{
if ( Serial.available()) {
char ch = Serial.read();
if(ch >= '0' && ch <= '9'){ // is ch a number?
steps = steps * 10 + ch - '0'; // yes, accumulate the value
}
else if(ch == '+'){
stepper.step(steps);
steps = 0;
}
else if(ch == '-'){
stepper.step(steps * -1);
steps = 0;
}
}
}
No comments:
Post a Comment