I want to read data from Arduino. My Arduino code is simple:
void setup()
{
// Initialize serial communications at a 9600 baud rate
Serial.begin(9600);
}
void loop()
{
// Send 'Hello, world!' over the serial port
Serial.println("Hello, World!!");
// Wait 100 milliseconds so we don't drive ourselves crazy
delay(100);
}
In Processing I have the following code
import processing.serial.*;
Serial myPort;
String val;
void setup() {
String portName = Serial.list()[1];
myPort = new Serial(this, portName, 9600);
}
void draw() {
if (myPort.available() > 0)
{
// If data is available,
val = myPort.readStringUntil('\n');
}
println(val); // pr
}
But val is always Null. I don't understand why it returns this value every time. The port is available.