AccelStepper library - motor ticks when turning

Hi,

When I'm using the AccelStepper library to control this closed loop stepper motor, the motor ticks when turning, maybe ~5 ticks/sec. Depending on the speed of the motor the ticks become more (at higher speed) or less (at lower speed) powerful.
At a low speed (<500 steps/sec) the ticks can only be detected by holding the motor and feeling the ticks. However, at greater speeds (>1000) you can also hear them and see the motor "house" move a little bit with each tick.
I'm not 100% certain but it seems like the ticking frequency is the same independent of speed. So if I tell the motor to make 3 revolutions, a slower speed will result in more ticks total because more time is needed to complete the revolutions.

Neither using the stepper library that comes with the Arduino IDE nor manually setting the pulse pin HIGH and LOW in a loop results in any ticking. Therefore I don't think it is the motor that is faulty.

This is the code I'm using:

#include <AccelStepper.h>

AccelStepper stepper(1, 7, 6);

long receivedPosition = 0;
long receivedSpeed = 0;
char receivedCommand;
bool newData, runAllowed = false;

void setup() 
{
	Serial.begin(9600); //define baud rate
}

void loop() 
{
	checkSerial();

	moveStepper();
}

void moveStepper()
{
	if (runAllowed == true)
	{
		if (stepper.currentPosition() != receivedPosition)
		{
			stepper.runSpeedToPosition();
		}
		else
		{
			runAllowed = false;
		}
	}
}

void checkSerial()
{
	if (Serial.available() > 0)
	{
		receivedCommand = Serial.read();
		newData = true;
	}

	if (newData == true)
	{
		// RUN
		if (receivedCommand == 'r')
		{
			runAllowed = true;

			receivedPosition = Serial.parseFloat(); //value for the steps
			receivedSpeed = Serial.parseFloat(); //value for the speed

			stepper.moveTo(receivedPosition);
			stepper.setMaxSpeed(receivedSpeed);
			stepper.setSpeed(receivedSpeed);
			
		}
	}
	newData = false;
}

Everything seems to work fine except for the ticking issue. Does anyone have any idea why this happens?

Are you sending serial commands 5 times a second? parseFloat is a blocking function which would easily explain the ticks.

To use serial without this issue, buffer a whole serial command/line/packet and
only parse it when its completely received - no blocking functions need be called then.

1 Like

Hi Mark, thanks for the response. I followed your advice and implemented something similar to what Robin2 does in Example 5 in this post. However the ticking still persisted.

What solved the issue for me was completely disabling all the debugging messages that the IDE I'm using (vMicro in Visual Studio) sends by default. I tried this after noting that running the same code from the Arduino IDE didn't produce any ticking. I should probably have suspected this was the issue earlier but I'm new to Arduino development so I didn't think of it. Thanks again for responding!

Its best to explain if you are using a different IDE up-front, any non-standard setup could be an issue. Glad you figured it out though, we wouldn't have been able to!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.