Take the 2-minute tour ×
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It's 100% free, no registration required.

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 :))

share|improve this question
2  
Some 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 Jan 21 at 22:05
    
Thanks a lot Robert! Finally I realized its because I didnt add delay after every time sending data to arduino.. –  wei Jan 25 at 13:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.