I recently made a soda can crusher that requires 24,000 steps in each direction to crush the can. When I use a number greater then 20,000 steps it goes in the wrong direction. Is there a way to fix this? Here is the code. Also I want the motor to turn off after each use.
/* Can Crusher code #2 */ #include <Stepper.h> // NEMA-23 Motor with DM542T Controller const int STEPS_PER_ROTATION= 800; //800 Steps per full rotation // DM542T Stepper Controller pinouts const int INPUT1 =2; //PUL+ To Digital pin 2 const int INPUT2 =3; //PUL- To Digital pin 3 const int INPUT3 =4; //DIR+ To Digital pin 4 const int INPUT4 =5; //DIR- To Digital pin 5 const int INPUT5 = 6; //ENA- To Digital pin 6 const int Input6 = 7; //ENA+ To Digital pin 7 //Initialize the stepper library to stepper motor controller Stepper myStepper(STEPS_PER_ROTATION, INPUT1, INPUT2, INPUT3, INPUT4); void setup() { // put your setup code here, to run once: myStepper.setSpeed(300); // Default speed 300 RPM // Set the rotation myStepper.step(20000); //Set Delay for 2 Second // delay(2000); // put your setup code here, to run once: myStepper.setSpeed(300); // Default speed 300 RPM // Set the rotation myStepper.step(4000); delay(2000); // Set return on motor myStepper.setSpeed(300); // Default speed 300 RPM // Set the rotation myStepper.step(-20000); // Set return on motor myStepper.setSpeed(300); // Default speed 300 RPM // Set the rotation myStepper.step(-4000); delay(2000); pinMode(6,OUTPUT); pinMode(7,OUTPUT); digitalWrite(6,LOW); //Turn off Motor digitalWrite(7,HIGH); //Turn off Motor while(1){} } void loop() { // put your main code here, to run repeatedly: // put your setup code here, to run once: //myStepper.setSpeed(20); // Default speed 20 RPM // Set the rotation //myStepper.step(500); //Set Delay for 1 Second // delay(2000); }
It's great to tip your server unless you work in the Server Room!
Just a quick look at your code and I see you setting 20,000 steps, thats why I guess.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
@zander If I set the code to 24000 it still only goes 20000 steps in the wrong direction. I repeated the code twice, once going 20,000 steps and then an additional 4,000 steps in the next step and used a negative number to make it go in reverse. It works except I want to know if there is a better way to code it.
It's great to tip your server unless you work in the Server Room!
@clark77494 The answer will be in the specs somewhere, I would search any documents internally for 20,000 or 20000.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
I'm real new with steppers myself and am using them in the Analog to Digital Converters Overload??? thread. So, I'm going to take a stab at your problem... only because I happen to have just studied Bill's video and am using it.
I'm unable to see your video, so I can't how you're wiring it... but, Bill made a significant point of showing that the pin order on the Stepper constructor is NOT in order. You might want to take a look at his video and confirm that you have it wired correctly.
IOW... I think, but please confirm for yourself that your constructor should be:
Stepper myStepper(STEPS_PER_ROTATION, INPUT1, INPUT3, INPUT2, INPUT4);
Hope that helps.
VBR,
Inq
3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide