Can a "smart stepper" count the steps accurately ?

Hello !

I am doing a project with a NEMA 23 stepper motor (see in attached pdf file) that runs continuously, with an arduino, and a Gshield driver (gShield v5 - Synthetos). I would like to be able to count the steps of the motor since it started and to be able to display this value when I click on a button for example.
I have already tried, but I think it is not possible with my driver.

I wanted to know if a "smart stepper" like this one : 3.2A NEMA23 Smart Stepper - The island of misfit electronics would be able to do that.

Thank you so much,

Regards,

57HS25.pdf (352 KB)

What does the user manual say?

Paul

In the user manual there is a section called "Position control modes" but i dont really get how this work and how I can use it with arduino...

"Position control modes
In the position control modes, the smart stepper counts the number of forward and reverse steps seen
on the step pin. For example if the motor is a 200 steps per rotation motor with 16x micro stepping and
we have had 1800 clockwise steps, then we know the shaft angle should be 360/(200*16) *1800=202.5
degrees. The encoder allows us to measure the actual motor shaft angle, for example it could measure
our actual angle is 202.2 degrees. Then we would have an error of 0.3 degrees. This means we need to
apply some current (force) to the motor shaft to make it move. To do this we use the current error, past
error, and rate of change of error to determine what force to apply to motor. To put this in a
mathematical equation we have: (see attached) "

Or, do you know if only with the arduino and the Gshield I could print a precise Step Number (since it started to run) whenever I clic on a button for exemple ?

I tried with the [u]https://www.arduino.cc/en/Tutorial/StepperOneStepAtATime[/u] exemple, but the use of delay seams suspicious... and the value of number of steps (stepcount) is not really a feedback from the motor itself.

Thanks !

Can't the Arduino keep count of the steps that it instructs the driver to make and display the number whenever you want?

...R

olook:
In the user manual there is a section called "Position control modes" but i dont really get how this work and how I can use it with arduino...

"Position control modes
In the position control modes, the smart stepper counts the number of forward and reverse steps seen
on the step pin. For example if the motor is a 200 steps per rotation motor with 16x micro stepping and
we have had 1800 clockwise steps, then we know the shaft angle should be 360/(200*16) *1800=202.5
degrees. The encoder allows us to measure the actual motor shaft angle, for example it could measure
our actual angle is 202.2 degrees. Then we would have an error of 0.3 degrees. This means we need to
apply some current (force) to the motor shaft to make it move. To do this we use the current error, past
error, and rate of change of error to determine what force to apply to motor. To put this in a
mathematical equation we have: (see attached) "

That description explains how it takes the positioning parameter you send the thing and makes it move to your desired degree parameter. Does it work properly when you send it the degree parameter?

Paul

Thanks to both of you.

In fact, as Robin said it's working when Arduino is counting the steps and then display it when i click on my button. If I'm adding 2 or more buttons, and I'm clicking all of them at the exact same time, Would I will have the same "stepCount" value ??

Here the code :

// this constant won't change:
const int buttonPin = 2; // the pin that the pushbutton is attached to
const int ledPin = 13; // the pin that the LED is attached to

// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0;

#include <Stepper.h>

const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 9, 11, 10, 6);

int stepCount = 0; // number of steps the motor has taken
// previous state of the button

void setup() {
// initialize the button pin as a input:
pinMode(buttonPin, INPUT);
// initialize the LED as an output:
pinMode(ledPin, OUTPUT);
// initialize serial communication:
Serial.begin(9600);
}

void loop() {
int motorSpeed = 100;
if (motorSpeed > 0) {
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);

myStepper.setSpeed(motorSpeed);
// step 1/100 of a revolution:
myStepper.step(stepsPerRevolution / 100);
//Serial.print("steps:");
//Serial.println(stepCount);
stepCount++;

// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == HIGH) {
// if the current state is HIGH then the button went from off to on:
buttonPushCounter++;
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(stepCount);
} else {
// if the current state is LOW then the button went from on to off:
Serial.println("off");
}
// Delay a little bit to avoid bouncing
}
// save the current state as the last state, for next time through the loop
lastButtonState = buttonState;
// turns on the LED every four button pushes by checking the modulo of the
// button push counter. the modulo function gives you the remainder of the
// division of two numbers:
if (buttonPushCounter % 4 == 0) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}

}
}

olook:
it's working when Arduino is counting the steps and then display it when i click on my button. If I'm adding 2 or more buttons, and I'm clicking all of them at the exact same time, Would I will have the same "stepCount" value ??

I'm afraid I don't understand what you are thinking of doing. Why do you think extra buttons might affect the counting of steps?

...R

PS ... When posting code please use the code button </>
codeButton.png

so your code 
looks like this

and is easy to copy to a text editor See How to use the forum