I got some different approaches but it would be nice to be able to get the ULN2003 to properly with just two pins.
I have wired this circuit and are trying with this code (problem: not precise. loosing position and jaggy in one direction)
const int coilA = 2;
const int coilB = 3;
const int ms = 2500;
const int ms1 = 0;
const int ms2 = 0;
int inc = 0;
bool changeDir = false;
void setup() {
Serial.begin(9600);
pinMode(coilA, OUTPUT);
pinMode(coilB, OUTPUT);
digitalWrite(coilA, LOW);
digitalWrite(coilB, LOW);
}
void loop() {
if (inc % 200 == 0) {
changeDir = !changeDir;
if (changeDir == 1) {
Serial.println("CW");
} else if (changeDir == 0) {
Serial.println("CCW");
}
delay(10);
}
if (changeDir == 1) {
cw();
} else if (changeDir == 0) {
ccw();
}
inc++;
}
void cw() {
step1();
step2();
step3();
step4();
}
void ccw() {
step4();
step3();
step2();
step1();
}
void step1 () {
digitalWrite(coilA, LOW);
digitalWrite(coilB, HIGH);
delayMicroseconds(ms);
}
void step2 () {
digitalWrite(coilA, HIGH);
digitalWrite(coilB, HIGH);
delayMicroseconds(ms);
}
void step3 () {
digitalWrite(coilA, HIGH);
digitalWrite(coilB, LOW);
delayMicroseconds(ms);
}
void step4 () {
digitalWrite(coilA, LOW);
digitalWrite(coilB, LOW);
delayMicroseconds(ms);
}
and with stepper library (that one wont turn in both directions)
#include <Stepper.h>
const int stepsPerRevolution = 32; // change this to fit the number of steps per revolution
const int stepperSpeed = 60;
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 2, 3);
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(stepperSpeed);
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(500);
// step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
delay(500);
}