I have problem to send data from processing to arduino mega.
Processing Code :
import processing.serial.*;
Serial myPort;
void setup()
{
println(Serial.list());
String arduinoPort = Serial.list()[0];
myPort = new Serial(this, arduinoPort, 9600)
}
void draw()
{
byte a= 3;
myPort.write(char(a));
}
Arduino Code :
#include <Servo.h>
#include <Wire.h>
Servo myservo1;
Servo myservo2;
void setup()
{
Serial.begin(9600);
myservo1.attach(9);
myservo2.attach(10);
myservo1.write(90);
myservo2.write(90);
}
void loop()
{
if(Serial.available()>0){
myservo1.write(70);
myservo2.write(70);
}
}
Code is really simple, processing send a value to trigger arduino mega turning 2 servo motors.
But it doesn't response at all.. Please help if anyone has any clue.
Thanks :))
-
2Some things to try: 1) Send the output from Processing to a terminal to check that Processing does what you think it should do. 2) Send the "correct" text to the Arduino from a terminal to check whether correct text will cause the proper response. 3) Put one or more LEDs on your board and light them when significant things happen such as receiving any text, attempting to control the motors, etc. 4) Keep on testing smaller and smaller parts of the system until you identify something that behaves differently than you intended it to. Fix that and try again.JRobert– JRobert2015年01月21日 22:05:40 +00:00Commented Jan 21, 2015 at 22:05
-
Thanks a lot Robert! Finally I realized its because I didnt add delay after every time sending data to arduino..wei– wei2015年01月25日 13:53:11 +00:00Commented Jan 25, 2015 at 13:53