int stpPin = 12;
int dirPin = 13;
int a = 0;
void setup()
{
pinMode(stpPin, OUTPUT);
pinMode(dirPin, OUTPUT);
}
void loop()
{
if (a < 200)
{
a++;
digitalWrite(stpPin, HIGH);
delay(10);
digitalWrite(stpPin, LOW);
delay(10);
}
else
{
digitalWrite(dirPin, HIGH);
a++;
digitalWrite(stpPin, HIGH);
delay(10);
digitalWrite(stpPin, LOW);
delay(10);
if (a>400)
{
a = 0;
digitalWrite(dirPin, LOW);
}
}
}
But how to control steppers from C# application send step and directory, if I have to #include <Stepper.h> function library and set Stepper stepper; what is a loaded code for Arduino?
The stepper library is not meant for the step-dir type of stepper motor driver. The AccelStepper library is for those drivers. There are many examples with the library to get you started.
Stepper or servo? You seem to have both. In either case, you will need to develop a protocol where you send a short (fast) command from C# to Arduino. Arduino then interprets this commands and issues instructions to the appropriate library.
DKWatson:
Stepper or servo? You seem to have both. In either case, you will need to develop a protocol where you send a short (fast) command from C# to Arduino. Arduino then interprets this commands and issues instructions to the appropriate library.
Hello, yes I'm using both stepper and servos control from C# application
Usually, when sending serial data from a host app, clockwise steps are indicated with a positive integer, counterclockwise with a negative integer. Your Arduino code must then interpret these values and set the dir pin accordingly. The step function simply requires the number of steps (positive value).
groundFungus:
The stepper library is not meant for the step-dir type of stepper motor driver. The AccelStepper library is for those drivers. There are many examples with the library to get you started.
DKWatson:
Usually, when sending serial data from a host app, clockwise steps are indicated with a positive integer, counterclockwise with a negative integer. Your Arduino code must then interpret these values and set the dir pin accordingly. The step function simply requires the number of steps (positive value).
I use two programs, one rotates with 360 degree full turn in one direction, another with change of direction on 360 degree. I’m trying to figure out, why I can’t stop movement by one or another way, depending on the load, even if I reset controller and load with Arduino IDE empty code, it performs the previous program, continues rotation or moving from side to side, and why holding the motor in hand, somehow affects motor work, steps begin to slow or even stops, I’m not touching shift itself, then if I put motor on the table, rotation stabilizes. Shaft also seems very sensitive, I can stop rotation without any pressure just with touching shaft
aive:
I use two programs, one rotates with 360 degree full turn in one direction, another with change of direction on 360 degree. I'm trying to figure out, why I can't stop movement by one or another way, depending on the load, even if I reset controller and load with Arduino IDE empty code, it performs the previous program,
I confess that even after looking at the two programs I am at a loss. Apart from the step and direction pins the programs are very similar and neither of them attempts to read incoming serial data.
If you are saying that you cannot replace one program with another then it helps if you print a message from setup() that identifies the program. That way you can be sure that the new program was loaded.
if the new program was not uploaded then you are likely to have received some error message in the Arduino IDE.