Added stepper motors. |
I've run some tests on controlling the stepper motors with an Arduino Micro and two A4988 Stepper controller breakout boards from Pololu. They are in 16th step mode to reduce the speed of the robot, this is accomplished by tying the 3 MS# pins to +5V, see the datasheet for details.
Test schematic.
Using the above setup and the following code, I was able to make the robot move forward and back for a full rotation continuously.
|
// Define pinout int leftStepPin = 7; int leftDirPin = 8; int rightStepPin = 9; int rightDirPin = 10; int curDir = 0; void setup() { // Start serial coms Serial.begin(9600); // Configure right motor pins pinMode(rightDirPin, OUTPUT); pinMode(rightStepPin, OUTPUT); digitalWrite(rightDirPin, HIGH); // Configure left motor pins pinMode(leftDirPin, OUTPUT); pinMode(leftStepPin, OUTPUT); digitalWrite(leftDirPin, HIGH); } // Loop function void loop() { // Complete single rotation of motor for( int i = 0; i < 3200; i++) { digitalWrite(rightStepPin,LOW); digitalWrite(leftStepPin,LOW); delay(1); digitalWrite(rightStepPin,HIGH); digitalWrite(leftStepPin,HIGH); delay(1); } // Swap direction for each motor if( curDir == 1 ) { digitalWrite(rightDirPin, LOW); digitalWrite(leftDirPin, LOW); curDir = 0; } else { digitalWrite(rightDirPin, HIGH); digitalWrite(leftDirPin, HIGH); curDir = 1; } }
No comments:
Post a Comment