accelstepper (stepper.movto)

hello everyone I write program in visual basic that send a value to arduino via serial port and controlling the stepper motor by that value . if I send 1 the stepper motor will turn one time in clock wise and stop and if it -1 it will turn one time in counter clock wise and stop its like a cnc program in one axis and I use accelstepper library
I write this code for arduino but its not working
#include <AccelStepper.h>

AccelStepper stepper(1, 9, 7);

void setup()
{
Serial.begin(9600);
stepper.setMaxSpeed(10000);
stepper.setAcceleration(5000);
}

void loop()
{
char c;

if(Serial.available())
{
int steps = Serial.read();
stepper.moveTo(steps);
}
stepper.run();
}

When you send "-1" that is two characters. But you are only reading one character.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example.

As you have control of the VB code I recommend that you use the system in the third example.

...R

ok how to make the motor move one turn and stop when receve serial signal using accelstepper

muhndkalel:
ok how to make the motor move one turn and stop when receve serial signal using accelstepper

Do you mean 1 step, or 1 revolution (200 steps) ?

You need to study the AccelStepper documentation and its examples

The function moveTo() only tells the library the destination you require. It does not move the motor. You also need repeated calls to run() or runSpeed() to get it to move.

Or you can use the blocking functions runToPosition() or runSpeedToPosition() which will complete all the steps before giving control back to your program.

There are various ways to control the motor from your PC. You could send the number of steps to the Arduino or you could send the number of revolutions and let the Arduino convert that to the required number of steps.

...R

1 revolution

muhndkalel:
1 revolution

I was kind-of hoping you would read the whole of my Reply.

...R