Sending String with MyPort.write from processing to arduino.

I am trying to send a String from processing to my arduino with no succes.

I can send "char variable" but it wont send a string.

processing code (sending char, WORKS)

import processing.serial.*;

Serial myPort;  // Create object from Serial class

void setup() 
{
  size(200, 200); //make our canvas 200 x 200 pixels big
  String portName = Serial.list()[0]; //change the 0 to a 1 or 2 etc. to match your port
  myPort = new Serial(this, portName, 9600);
}

void draw() {
  
  if (mousePressed == true) 
  {                           //if we clicked in the window
    myPort.write('1');         //send a 1
    println("oussama");
  } else 
  {                           //otherwise
    myPort.write('0');          //send a 0
  }
}

Arduino code(sending char, WORKS)

char val; // Data received from the serial port
int ledPin = 3; // Set the pin to digital I/O 13

void setup() {
  pinMode(ledPin, OUTPUT); // Set pin as OUTPUT
  Serial.begin(9600); // Start serial communication at 9600 bps
}
void loop() {

  if (Serial.available())
  { // If data is available to read,
    val = Serial.read(); // read it and store it in val
  }
  if (val == '1')
  { // If 1 was received
    digitalWrite(ledPin, HIGH); // turn the LED on
    delay(1000);
    digitalWrite(ledPin, LOW); // turn the LED on
    
  } else {
    digitalWrite(ledPin, LOW); // otherwise turn it off
  }
  delay(10); // Wait 10 milliseconds for next reading
}

When i try to send an String with myPort.write: processing(sending String, DOES NOT WORK)

import processing.serial.*;

Serial myPort;  // Create object from Serial class

void setup() 
{
  size(200, 200); //make our canvas 200 x 200 pixels big
  String portName = Serial.list()[0]; //change the 0 to a 1 or 2 etc. to match your port
  myPort = new Serial(this, portName, 9600);
}

void draw() {
  
  if (mousePressed == true) 
  {                           //if we clicked in the window
    myPort.write("test");         //send a 1
    println("oussama");
  } else 
  {                           //otherwise
    myPort.write('0');          //send a 0
  }
}

arduino(sending String, DOES NOT WORK)

String val; // Data received from the serial port
int ledPin = 3; // Set the pin to digital I/O 13

void setup() {
  pinMode(ledPin, OUTPUT); // Set pin as OUTPUT
  Serial.begin(9600); // Start serial communication at 9600 bps
}
void loop() {

  if (Serial.available())
  { // If data is available to read,
    val = Serial.read(); // read it and store it in val
  }
  if (val == "test")
  { // If 1 was received
    digitalWrite(ledPin, HIGH); // turn the LED on
    delay(1000);
    digitalWrite(ledPin, LOW); // turn the LED on
    
  } else {
    digitalWrite(ledPin, LOW); // otherwise turn it off
  }
  delay(10); // Wait 10 milliseconds for next reading
}

Can anyone help me with this?

I cant run both programs at the same time so i don't know what the processing is sending to my device.

processing(sending String, DOES NOT WORK)

What proof do you have that the string is not sent?

  if (Serial.available())
  { // If data is available to read,
    val = Serial.read(); // read it and store it in val
  }
  if (val == "test")

Serial.read() reads one character. One character will never equal "test". Using == is not how to compare strings, if you were to collect the characters that Processing sends into a NULL terminated array of chars.

http://forum.arduino.cc/index.php?topic=396450.0

Ima check it out thanks alot!

I found a solution using this do while loop.

char val; // Data received from the serial port
int ledPin = 3; // Set the pin to digital I/O 13
String inputread;

void setup() {
  pinMode(ledPin, OUTPUT); // Set pin as OUTPUT
  Serial.begin(9600); // Start serial communication at 9600 bps
}
void loop() {
  inputread = "";
  if (Serial.available())
  { // If data is available to read,
    do{ 
      val = Serial.read(); // read it and store it in val
      if (val != -1){
        inputread = inputread +val;
        }
      }while(val != -1);
  }
  if (inputread == "kkk")
  { // If 1 was received
    digitalWrite(ledPin, HIGH); // turn the LED on
    delay(1000);
    digitalWrite(ledPin, LOW); // turn the LED on
    
  } else {
    digitalWrite(ledPin, LOW); // otherwise turn it off
  }
  delay(10); // Wait 10 milliseconds for next reading
}