What I read tells me that those speeds are achievable, not that I have ever run a stepper that fast. You will need to implement acceleration though. Whether such speeds can be done with the friction involved and curtain mass is a different question.
Once it's working again, perhaps experiment with accelerating and see if you can get it up to an acceptable speed.
ive simplified my code right down and will add in features one by one and get them working before adding the next.
The code at the moment when loaded starts the motor CCW with out any buttons being pressed, ive made all the input buttons pullup because it was said this is sensible and ive read it stops stray emf effecting the pins. i dont understand why the motor starts moving with no input made?
What do i need to be thinking about to stop the motor moving on start up?
//#include <ESP8266WiFi.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
// Your WiFi credentials.
// Set password to "" for open networks.
//char ssid[] = "";
//char pass[] = "";
//byte limitCW = D0;
//byte limitCCW = D1;
byte directionPin = D2;
byte stepPin = D3;
//byte buttonOnOffpin = D4;
byte buttonCWpin = D5;
byte buttonCCWpin = D6;
byte buttonJogCWpin = D7;
byte buttonJogCCWpin = D8;
boolean buttonCWpressed = false;
boolean buttonCCWpressed = false;
boolean buttonJogCWpressed = false;
boolean buttonJogCCWpressed = false;
unsigned long curMillis;
unsigned long prevStepMillis = 0;
unsigned long millisBetweenSteps = 1; // milliseconds
void setup()
{
//Debug console
Serial.begin(9600);
pinMode(directionPin, OUTPUT);
pinMode(stepPin, OUTPUT);
//pinMode(buttonOnOffpin, OUTPUT);
// pinMode(limitCW, INPUT);
// pinMode(limitCCW, INPUT);
pinMode(buttonCWpin, INPUT_PULLUP);
pinMode(buttonCCWpin, INPUT_PULLUP);
pinMode(buttonJogCWpin, INPUT_PULLUP);
pinMode(buttonJogCCWpin, INPUT_PULLUP);
}
void loop()
{
curMillis = millis();
readButtons();
actOnButtons();
}
void readButtons() {
buttonCCWpressed = false;
buttonCWpressed = false;
buttonJogCCWpressed = false;
buttonJogCWpressed = false;
if (digitalRead(buttonCWpin) == LOW) {
buttonCWpressed = true;
}
if (digitalRead(buttonCCWpin) == LOW) {
buttonCCWpressed = true;
}
if (digitalRead(buttonJogCWpin) == LOW) {
buttonCWpressed = true;
}
if (digitalRead(buttonJogCCWpin) == LOW) {
buttonCCWpressed = true;
}
}
void actOnButtons() {
if (buttonCWpressed == true) {
digitalWrite(directionPin, LOW);
singleStep();
}
if (buttonCCWpressed == true) {
digitalWrite(directionPin, HIGH);
singleStep();
}
if (buttonJogCWpressed == true) {
digitalWrite(directionPin, LOW);
singleStep();
}
if (buttonJogCCWpressed == true) {
digitalWrite(directionPin, HIGH);
singleStep();
}
}
void singleStep() {
if (curMillis - prevStepMillis >= millisBetweenSteps) {
// next 2 lines changed 28 Nov 2018
//prevStepMillis += millisBetweenSteps;
prevStepMillis = curMillis;
digitalWrite(stepPin, HIGH);
digitalWrite(stepPin, LOW);
}
}
The problem seems to happen when i add the second set of buttons that doe the same action so for now i deleted the and looked at it from a different angle.
I have added in 2 hall sensors and managed to get the 2 buttons to act in jog mode that you can only jog the motor if the switch says you can, and it works! ive actually made some progress!
code below. for the next stage i want to press the button once and it continue to move the motor until it makes the switch. Now i understand that a while statement might do what i need but they are bad news. how do i do this? a loop within a loop? any idea where i would find good examples?
im just off to go and read about state machine in the hope that will help.
// testing a stepper motor with a Pololu A4988 driver board or equivalent
// this version uses millis() to manage timing rather than delay()
// and the movement is determined by a pair of momentary push switches
// press one and it turns CW, press the other and it turns CCW
byte limitCCW = D0;
byte limitCW = D1;
byte directionPin = D2;
byte stepPin = D3;
byte buttonCWpin = D5;
byte buttonCCWpin = D6;
boolean buttonCWpressed = false;
boolean buttonCCWpressed = false;
boolean limitCWactive = false;
boolean limitCCWactive = false;
unsigned long curMillis;
unsigned long prevStepMillis = 0;
unsigned long millisBetweenSteps = 1; // milliseconds
void setup() {
Serial.begin(9600);
Serial.println("Starting Stepper Demo with millis()");
pinMode(directionPin, OUTPUT);
pinMode(stepPin, OUTPUT);
pinMode(limitCW, INPUT);
pinMode(limitCCW, INPUT);
pinMode(buttonCWpin, INPUT_PULLUP);
pinMode(buttonCCWpin, INPUT_PULLUP);
}
void loop() {
curMillis = millis();
readButtons();
actOnButtons();
}
void readButtons() {
buttonCCWpressed = false;
buttonCWpressed = false;
limitCWactive = false;
limitCCWactive = false;
if (digitalRead(buttonCWpin) == LOW) {
buttonCWpressed = true;
}
if (digitalRead(buttonCCWpin) == LOW) {
buttonCCWpressed = true;
}
if (digitalRead(limitCW) == HIGH) {
limitCWactive = true;
}
if (digitalRead(limitCCW) == HIGH) {
limitCCWactive = true;
}
}
void actOnButtons() {
if ((buttonCWpressed == true) && (limitCWactive == true)) {
digitalWrite(directionPin, LOW);
singleStep();
}
if ((buttonCCWpressed == true) && (limitCCWactive == true)) {
digitalWrite(directionPin, HIGH);
singleStep();
}
}
void singleStep() {
if (curMillis - prevStepMillis >= millisBetweenSteps) {
// next 2 lines changed 28 Nov 2018
//prevStepMillis += millisBetweenSteps;
prevStepMillis = curMillis;
digitalWrite(stepPin, HIGH);
digitalWrite(stepPin, LOW);
}
}
A state machine solution is a good idea. They're trivially easy to understand and to write, indeed, once you get the idea, it feels like they almost write themselves.
That isn't quite true though the first time you try them. Or the second. Third time doesn't often go well either
I suggest instead, you add a boolean called MoveCCW or some such. When you see a button press of the CCW button, set it true. When the hall sensor says stop, set it false.
In act on buttons, if MoveCCW is true, do a step CCW.
Forget CW for now because you'll have to deal with what to do when you're going CCW and the CW button is pressed.