I have written a code which receives string from Arduino to processing IDE. but when i receive data from Arduino to processing. it shows null error. can anyone help in this please?. Here's the code I'm attaching.
heres the code for processing IDE
import processing.serial.*;
Serial myPort; // Create object from Serial class
String val; // Data received from the serial port
void setup()
{
// I know that the first port in the serial list on my mac
// is Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you're using.
String portName = Serial.list()[2]; //change the 0 to a 1 or 2 etc. to match your port
myPort = new Serial(this, portName, 115200);
}
void draw()
{
if ( myPort.available() > 0)
{ // If data is available,
val = myPort.readStringUntil('\n'); // read it and store it in val
}
println(val); //print it out in the console
}
Here's the code for Arduino
void setup()
{
//initialize serial communications at a 9600 baud rate
Serial.begin(115200);
}
void loop()
{
//send 'Hello, world!' over the serial port
Serial.write("Hello, world!");
//wait 100 milliseconds so we don't drive ourselves crazy
delay(100);
}