Experience is what you get when you don't get what you want.
Madmisha,
Ok, I will take your other code and set that back to what you said and give it a go first.
Switches on driver:ON OFF OFF OFF OFF ON ON ON
First 3 = 2.69A RMS
4th switch = Half Current
5-8 = 400 Microsteps
Thanks,
Voltage
Weird. When I try to verify this code below now I get an error that "dirfor" was not declared in this scope.
Arduino: 1.8.15 (Windows 10), Board: "Arduino Uno"
Oh yeah, I fixed that before by changing the spelling to "dirFor".
Thanks,
Voltage
4th switch = Half Current
That might have been your thump. The LCD took more than 0.4 seconds to update and it cut power. I do not really know much about this setting though.
5-8 = 400 Microsteps
I think that is 2 microsteps = 400 steps/rev, assuming I am looking at the right datasheet. You might want to up that a little. Isn't that the lowest setting?
Weird. When I try to verify this code below now I get an error that "dirfor" was not declared in this scope.
I just verified it on mine and had no problem. I just did a search and all say dirFor although it might have lost case in the debug. I also confirmed that I was on Uno. That is odd. I am running 1.8.13 though.
4th switch = Half Current
That might have been your thump. The LCD took more than 0.4 seconds to update and it cut power. I do not really know much about this setting though.
5-8 = 400 Microsteps
I think that is 2 microsteps = 400 steps/rev, assuming I am looking at the right datasheet. You might want to up that a little. Isn't that the lowest setting?
I believe the half/full current mode is just to keep the stepper from getting too hot when it has power applied but is not running. That is the right datasheet. I had the thumping in all of the settings I tried but thought it would be less work to microstep less per step so I set it to 400 assuming that 200 = a full step and 400 would = 1/2 step and so on.
Thanks,
Voltage
Weird. When I try to verify this code below now I get an error that "dirfor" was not declared in this scope.
I just verified it on mine and had no problem. I just did a search and all say dirFor although it might have lost case in the debug. I also confirmed that I was on Uno. That is odd. I am running 1.8.13 though.
I am running 18.15 so maybe it was a bug. Still getting this error though.
Edit: Adding int before it corrected it. 🙂
Thanks,
Voltage
Its weird, I just updated the IDE and it caught the typos that I don't thin k I checked but would not let the pot go without declaring it as int. Before the update, it would allow that. I thought you were testing the one with the buttons at first. Updated pot one.
//Test of accelstepper #include <AccelStepper.h> //Define pins int LEFT_PIN = 11; int STOP_PIN = 1; int RIGHT_PIN = 0; int driverPUL = 2; // PUL- pin int driverDIR = 3; // DIR- pin int spd = A1; // Potentiometer bool go = false; //Is it running bool dirFor = true; //Direction to go in AccelStepper stepper(1,2,3); // This needs to change in any example(Mode, Pul, Dir) //Interupt Handlers void formotor (){ dirFor = true; go = true; } void bacmotor (){ dirFor = false; go = true; } void stpmotor (){ stepper.stop(); go = false; } void setup() { pinMode(LEFT_PIN, INPUT_PULLUP); pinMode(STOP_PIN, INPUT_PULLUP); pinMode(RIGHT_PIN, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(LEFT_PIN), formotor, FALLING); attachInterrupt(digitalPinToInterrupt(RIGHT_PIN), bacmotor, FALLING); attachInterrupt(digitalPinToInterrupt(STOP_PIN), stpmotor, FALLING); stepper.setMaxSpeed(1000); } void loop() { if(go == true){ int sp_pot = map((analogRead(spd)),0,1023,2000,50); if(dirFor == true){ stepper.setSpeed(sp_pot); } else { stepper.setSpeed((sp_pot*-1)); } stepper.runSpeed(); } else { stepper.stop(); } }
Its weird, I just updated the IDE and it caught the typos that I don't thin k I checked but would not let the pot go without declaring it as int. Before the update, it would allow that. I thought you were testing the one with the buttons at first. Updated pot one.
//Test of accelstepper #include <AccelStepper.h> //Define pins int LEFT_PIN = 11; int STOP_PIN = 1; int RIGHT_PIN = 0; int driverPUL = 2; // PUL- pin int driverDIR = 3; // DIR- pin int spd = A1; // Potentiometer bool go = false; //Is it running bool dirFor = true; //Direction to go in AccelStepper stepper(1,2,3); // This needs to change in any example(Mode, Pul, Dir) //Interupt Handlers void formotor (){ dirFor = true; go = true; } void bacmotor (){ dirFor = false; go = true; } void stpmotor (){ stepper.stop(); go = false; } void setup() { pinMode(LEFT_PIN, INPUT_PULLUP); pinMode(STOP_PIN, INPUT_PULLUP); pinMode(RIGHT_PIN, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(LEFT_PIN), formotor, FALLING); attachInterrupt(digitalPinToInterrupt(RIGHT_PIN), bacmotor, FALLING); attachInterrupt(digitalPinToInterrupt(STOP_PIN), stpmotor, FALLING); stepper.setMaxSpeed(1000); } void loop() { if(go == true){ int sp_pot = map((analogRead(spd)),0,1023,2000,50); if(dirFor == true){ stepper.setSpeed(sp_pot); } else { stepper.setSpeed((sp_pot*-1)); } stepper.runSpeed(); } else { stepper.stop(); } }
I just reran the sketch after I fixed it and still no go. I did already change pins 0,1 to 12,13 so I will take the sketch here on this page and edit the 2 pin numbers and give it another go so at least we know what sketch and where we are at. Be right back.
Ok, I'm back. Still a no go. I still have the shield plugged in but that shouldn't matter. I have a Left, Stop, and Right button and a potentiometer connected.
Thanks,
Voltage
I set max speed to 1000 because that is what their example used, but:
int sp_pot = map((analogRead(spd)),0,1023,2000,50);
Try changing the 2000 to 1000. It might be going over and stopping on an error.
Has anybody noticed yet that you're setting the speed and telling the stepper to run but you've never given it a target position ?
It may be standing still, not out of truculence, but simply because it hasn't been told where to go 🙂
Experience is what you get when you don't get what you want.
Constant speed example didn't do that. You are pulsing for move and setting the direction. Between those 2 things, it should know where to go.
I just noticed that you have the buttons connected to ground. The interrupts won't trigger. That is the problem. I was combining Bills sketch and that's where I went wrong. He has his connected with a resistor to 5V and no pin mode because the interrupt is doing that.
Constant speed example didn't do that. You are pulsing for move and setting the direction. Between those 2 things, it should know where to go.
◆ runSpeed()
boolean AccelStepper::runSpeed | ( | ) |
Poll the motor and step it if a step is due, implementing a constant speed as set by the most recent call to setSpeed(). You must call this as frequently as possible, but at least once per step interval,
- Returns
- true if the motor was stepped.
References _direction, DIRECTION_CW, and step().
Referenced by MultiStepper::run(), run(), and runSpeedToPosition().
Note: ... if a step is due ...
Experience is what you get when you don't get what you want.
Can you please give us an idea of what speed range (in RPM) you will require ?
Experience is what you get when you don't get what you want.
I might have fixed my stupidity:
//Test of accelstepper #include <AccelStepper.h> //Define pins int LEFT_PIN = 11; int STOP_PIN = 1; int RIGHT_PIN = 0; int driverPUL = 2; // PUL- pin int driverDIR = 3; // DIR- pin int spd = A1; // Potentiometer bool go = false; //Is it running bool dirFor = true; //Direction to go in AccelStepper stepper(1,2,3); // This needs to change in any example(Mode, Pul, Dir) //Interupt Handlers void formotor (){ dirFor = true; go = true; } void bacmotor (){ dirFor = false; go = true; } void stpmotor (){ stepper.stop(); go = false; } void setup() { pinMode(LEFT_PIN, INPUT_PULLUP); pinMode(STOP_PIN, INPUT_PULLUP); pinMode(RIGHT_PIN, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(LEFT_PIN), formotor, CHANGE); attachInterrupt(digitalPinToInterrupt(RIGHT_PIN), bacmotor, CHANGE); attachInterrupt(digitalPinToInterrupt(STOP_PIN), stpmotor, CHANGE); stepper.setMaxSpeed(1000); } void loop() { if(go == true){ int sp_pot = map((analogRead(spd)),0,1023,1000,50); if(dirFor == true){ stepper.setSpeed(sp_pot); } else { stepper.setSpeed((sp_pot*-1)); } stepper.runSpeed(); } else { stepper.stop(); } }