Notifications
Clear all

Stepper motor with selectable speed and rotation option

9 Posts
4 Users
2 Reactions
2,972 Views
Iclazion
(@iclazion)
Mr
Joined: 4 years ago
Posts: 6
Topic starter  
Please Note - I have included replies from other people who gave me some advice, please also have a look at what they provided me, and please comment if it will not work and why, but below is my original question, with replies. 

I would like to be able to have 3 Momentary switches that when pressed will let me be able to select from 3 speeds or 3 settings. Here is my basic sketch without any switches.

Any advice will be appreciated?
TIA

/* Example sketch to control a stepper motor with TB6600 stepper motor driver, AccelStepper library and Arduino: acceleration and deceleration. More info: https://www.makerguides.com */

// Include the AccelStepper library:
#include <AccelStepper.h>
// Define stepper motor connections and motor interface type. Motor interface type must be set to 1 when using a driver:
#define dirPin 2
#define stepPin 3
#define motorInterfaceType 1
// Create a new instance of the AccelStepper class:
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);
void setup() {
// Set the maximum speed and acceleration:
stepper.setMaxSpeed(1000);
stepper.setAcceleration(500);
}
void loop() {
// Set the target position:
stepper.moveTo(8000);
// Run to target position with set speed and acceleration/deceleration:
stepper.runToPosition();
delay(1000);
// Move back to zero:
stepper.moveTo(0);
stepper.runToPosition();
delay(1000);
}

---------------------------------------------------------------------------------------------------------------
Replies:
 #include <AccelStepper.h>
#define dirPin 2
#define stepPin 3
#define motorInterfaceType 1

const int buttonPin1 = 8;
const int buttonPin2 = 9;
const int buttonPin3 = 10;
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;

void setup () {

pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
}

void loop () {

buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3= digitalRead(buttonPin3);

if (buttonState1 == 1) {
stepper.setMaxSpeed(300);
stepper.setAcceleration(500);
}
if (buttonState2 == 1) {
stepper.setMaxSpeed(600);
stepper.setAcceleration(500);
}
if (buttonState3 == 1) {
stepper.setMaxSpeed(1000);
stepper.setAcceleration(500);
}
}

//in void setup () not finish
-------------------------------

How do I upload images to share with you all? I have a Nema 34 with microstep driver and powersupply. Things I would like to share if possible?

 

Make the best of today.


   
Quote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2227
 

@iclazion

How do I upload images to share with you all?

Click the Attach Files option on the bottom bar where you type your posts.

To make your programs easier to read,
https://forum.dronebotworkshop.com/question-suggestion/sticky-post-for-editing/#post-4939


   
ReplyQuote
Iclazion
(@iclazion)
Mr
Joined: 4 years ago
Posts: 6
Topic starter  
This post was modified 4 years ago by Iclazion

Make the best of today.


   
ReplyQuote
Iclazion
(@iclazion)
Mr
Joined: 4 years ago
Posts: 6
Topic starter  

Make the best of today.


   
ReplyQuote
Iclazion
(@iclazion)
Mr
Joined: 4 years ago
Posts: 6
Topic starter  

Make the best of today.


   
ReplyQuote
Iclazion
(@iclazion)
Mr
Joined: 4 years ago
Posts: 6
Topic starter  
Posted by: @iclazion

stepper.setMaxSpeed(300);

Reason I ask is "setMaxSpeed" is not a defined variable. It's assuming there is a MaxSpeed. 

Make the best of today.


   
ReplyQuote
triform
(@triform)
Member
Joined: 5 years ago
Posts: 324
 

@iclazion

I think that some of the methods in that library are 'float' types.

https://www.airspayce.com/mikem/arduino/AccelStepper/classAccelStepper.html

You may want to adjust based on that.


   
ReplyQuote
Iclazion
(@iclazion)
Mr
Joined: 4 years ago
Posts: 6
Topic starter  
This post was modified 4 years ago by Iclazion

Make the best of today.


   
ReplyQuote
JoeLyddon
(@joelyddon)
Member
Joined: 5 years ago
Posts: 157
 

Have Fun,
Joe Lyddon

www.woodworkstuff.net


   
ReplyQuote