Hello,
I am using this guide to learn basics about communication between Arduino and Processing.
First part from the tutorial where I'm sending message from Arduino to Processing is working fine. However the second part of the tutorial where message should be send from Processing to Arduino to turn on onBoardLed connected with pin13 doesn't work.
I'm using Arduino Mega 2560.
Description of the problem:
Arduino code is uploaded successfully. Arduino LEDs blink couple of times and then blow out as it is normal during uploading. Arduino is waiting for message from Processing to turn on the onBoardLed. But when I run Processing something weird happens. OnBoardLed and RX Led are on all the time no matter if I'm sending message or not.
I'm doing everything the same as it is in this guide.
Please give me advice what may cause this issue.
Arduino Code:
#define onBoardLed 13
char val;
void setup() {
Serial.begin(9600);
pinMode(onBoardLed, OUTPUT);
}
void loop() {
if(Serial.available() > 0) {
val = Serial.read();
}
if(val == '1') {
digitalWrite(onBoardLed, HIGH);
}
else {
digitalWrite(onBoardLed, LOW);
}
delay(50);
}
Processing Code:
import processing.serial.*;
Serial myPort;
String portName;
void setup() {
size(200, 200);
portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
}
void draw() {
if(mousePressed == true) {
myPort.write('1');
println('1');
}
else {
myPort.write('0');
}
}