Thanks guy's
That work fine with serial communication
Now i want to build a GUI by using processing for same problem which i have mentioned earlier
i wrote a code for that also when i execute the code i got the window of GUI
but that window is unable to communicate with arduino and my system
Please guide me
Arduino Code
#define EN 8
//Direction pin
#define X_DIR 5
#define Y_DIR 6
//#define Z_DIR 7
//Step pin
#define X_STP 2
#define Y_STP 3
//#define Z_STP 4
//A4988
int delayTime=900; //Delay between each pause (uS)
int stps=2000 ;// Steps to move
int a,b,c,d,e;
void step(boolean dir, byte dirPin, byte stepperPin, int steps)
{
digitalWrite(dirPin, dir);
delay(100);
for (int i = 0; i < steps; i++) {
digitalWrite(stepperPin, HIGH);
delayMicroseconds(delayTime);
digitalWrite(stepperPin, LOW);
delayMicroseconds(delayTime);
}
}
void setup()
{
pinMode(X_DIR, OUTPUT); pinMode(X_STP, OUTPUT);
pinMode(Y_DIR, OUTPUT); pinMode(Y_STP, OUTPUT);
// pinMode(Z_DIR, OUTPUT); pinMode(Z_STP, OUTPUT);
pinMode(EN, OUTPUT);
//digitalWrite(EN, LOW);
Serial.begin(9600) ;
}
void loop()
{
Serial.begin(9600) ;
while(Serial.available()==0){}
a=Serial.parseInt();
Serial.begin(9600) ;
while(Serial.available()==0){}
b=Serial.parseInt();
Serial.begin(9600) ;
while(Serial.available()==0){}
c=Serial.parseInt();
while(Serial.available()==0){}
d=Serial.parseInt();
Serial.begin(9600) ;
while(Serial.available()==0){}
e=Serial.parseInt();
for(int i=1; i<=a; i++)
{
step(false, X_DIR, X_STP, stps); //X, Clockwise
if(Serial.available()>=0)
{
step(false, X_DIR, X_STP, stps); //X, Clockwise
b=Serial.read();
delay(b); // dipping time in solution
step(true, X_DIR, X_STP, stps); //X, Counterclockwise
delay(1000);
step(false, Y_DIR, Y_STP, stps); //Y, Clockwise
delay(1000);
step(false, X_DIR, X_STP, stps); //X, Clockwise
step(false, X_DIR, X_STP, stps); //X, Clockwise
c=Serial.read();
delay(c); // dipping time in solution
step(true, X_DIR, X_STP, stps); //X, Counterclockwise
delay(1000);
step(false, Y_DIR, Y_STP, stps); //Y, Clockwise
delay(1000);
step(false, X_DIR, X_STP, stps); //X, Clockwise
d=Serial.read();
delay(d); // dipping time in solution
step(true, X_DIR, X_STP, stps); //X, Counterclockwise
delay(1000);
step(false, Y_DIR, Y_STP, stps); //Y, Clockwise
delay(1000);
step(false, X_DIR, X_STP, stps); //X, Clockwise
e=Serial.read();
delay(e); // dipping time in solution
step(true, X_DIR, X_STP, stps); //X, Counterclockwise
delay(1000);
step(false, Y_DIR, Y_STP, stps); //Y, Clockwise
delay(1000);
}
step(true, Y_DIR, Y_STP, stps); //Y, Counterclockwise
step(true, Y_DIR, Y_STP, stps); //Y, Counterclockwise
step(true, Y_DIR, Y_STP, stps); //Y, Counterclockwise
step(true, Y_DIR, Y_STP, stps); //Y, Counterclockwise*/
delay(1000);
}
}
Processing Code is
import controlP5.; //import ControlP5 library
import processing.serial.;
Serial port;
ControlP5 cp5; //create ControlP5 object
PFont font, FONT;
String text;
int a,b,c,d,e;
void setup(){ //same as arduino program
textAlign(CENTER,CENTER);
size(1000, 7000); //window size, (width, height)
printArray(Serial.list()); //prints all available serial ports
//port = new Serial(this, "COM3", 9600); //i have connected arduino to com3, it would be different in linux and mac os
//lets add buton to empty window
cp5 = new ControlP5(this);
font = createFont("Times New Roman", 20); // custom fonts for buttons and title
FONT = createFont("Times New Roman", 10);
cp5.addButton("Enter the Number of dipping cycles") //"red" is the name of button
.setPosition(100, 150) //x and y coordinates of upper left corner of button
.setSize(500, 70) //(width, height)
.setFont(font)
;
cp5.addTextfield("a").setPosition(700,150).setSize(100,70).setFont(font);
cp5.addButton("Enter the Dipping time in First Precourser") //"red" is the name of button
.setPosition(100, 250) //x and y coordinates of upper left corner of button
.setSize(500, 70) //(width, height)
.setFont(font)
;
cp5.addTextfield("b").setPosition(700,250).setSize(100,70).setFont(font);
cp5.addButton("Enter the Dipping time in Distilled Water1") //"yellow" is the name of button
.setPosition(100, 350) //x and y coordinates of upper left corner of button
.setSize(500, 70) //(width, height)
.setFont(font)
;
cp5.addTextfield("c").setPosition(700,350).setSize(100,70).setFont(font);
cp5.addButton("Enter the Dipping time in Second Precourser") //"blue" is the name of button
.setPosition(100, 450) //x and y coordinates of upper left corner of button
.setSize(500, 70) //(width, height)
.setFont(font)
;
cp5.addTextfield("d").setPosition(700,450).setSize(100,70).setFont(font);
cp5.addButton("Enter the Dipping time in Distilled Water2") //"alloff" is the name of button
.setPosition(100, 550) //x and y coordinates of upper left corner of button
.setSize(500, 70) //(width, height)
.setFont(font)
;
cp5.addTextfield("e").setPosition(700,550).setSize(100,70).setFont(font);
cp5.addButton("Submit").setPosition(380, 650).setSize(150, 100).setFont(font);
}
void draw(){ //same as loop in arduino
background(#FFCE71); // background color of window (r, g, b) or (0 to 255)
//lets give title to our window
fill(0,2, 0); //text color (r, g, b)
textFont(font);
text("Welcome to Solid State Physics Research Laboratory, Department of Physics, ACA", 480, 30); // ("text", x coordinate, y coordinat)
text("Sequential Ionic Layer Adsorption Reaction (SILAR) deposition System ", 470, 80);
textFont(FONT);
text(" NOTE - Dipping time in milisecond [1sec=1000]", 800,130);
}
//lets add some functions to our buttons
//so whe you press any button, it sends perticular char over serial port
void Submit()
{
port.write('a');
port.write('b');
port.write('c');
port.write('d');
port.write('e');
}