I want to develop C# win app application to control stepper motor. To do that first i want to control the motors by entering data from serial monitor at Arduino IDE 2.0.0. I am using CNC Shield and related motor drivers. All equipment is working, i tested all by entering data directly to code. I am able to control the motor. However, i can not control the motor via serial monitor. There is no rotation at all.
I wanted to control by giving two data(direction and rotation) but i am not able to rotate the motor. According to mo code, my input is in the form of "C,3600".I am adding the code below. I think i have problem in if or for loop.
I really appreciate to all helps.
#include <Stepper.h>
const int StepX = 2;
const int DirX = 5;
//const int StepY = 3;
//const int DirY = 6;
//const int StepZ = 4;
//const int DirZ = 7;
int index =0;
String data[2];
void setup() {
pinMode(StepX,OUTPUT);
pinMode(DirX,OUTPUT);
//pinMode(StepY,OUTPUT);
//pinMode(DirY,OUTPUT);
//pinMode(StepZ,OUTPUT);
//pinMode(DirZ,OUTPUT);
}
void loop() {
//digitalWrite(DirY, HIGH);
//digitalWrite(DirZ, HIGH);
if(Serial.available()){
data [index] = Serial.readStringUntil(',');
Serial.print("data read:");
Serial.println(data[index]);
index++;
if(index==2){
index = 0;
for(int x = 0; x<data[1].toInt(); x++) { // loop for data[1] steps
if(data[0] == "C") digitalWrite(DirX,HIGH); // set direction, HIGH for clockwise
//, LOW for anticlockwise
else if(data[0] == "W") digitalWrite(DirX,LOW);
/*digitalWrite(DirX,HIGH);
delayMicroseconds(500);
digitalWrite(DirX,LOW);
delayMicroseconds(500);*/
}
}
while(1);
}