0
  1. Need another new libraries.
  2. This is the code for java.
  3. My porposes are sending from java to arduino variable like this String = "hello" But nothing Its happiens.

Java code:

package j;
import arduino.*;
public class K {
 public static void main(String[] args) {
 Arduino obj = new Arduino("COM4", 115200);
 obj.openConnection();
 String MyStr="hello";
 System.out.println(MyStr); 
 obj.serialWrite(MyStr); 
 obj.closeConnection(); 
 
 }
}

This is minimal arduino code fragment: It's working if from console send "hello" ,"1","2", "help" String vars.

Arduino code:

int RR=255;
int GG=255;
int BB=255;
String MyStr="0";
void setup() {
 Serial.begin(115200);
 Serial.setTimeout(0);
}
void loop() {
 //L0();
 
 
 while (Serial.available()>0) { //if data has been written to the Serial stream
 //data0=Serial.read();
 String MyStr = Serial.readString();
 if ((MyStr).equals("1")){
 Serial.println (MyStr);
 RR=200;GG=0;BB=0;
 }
 
 
 if (MyStr == ("2")) {
 Serial.println (MyStr);
 RR=0;GG=0;BB=255;
 }
 if (MyStr == "hello") {
 Serial.println (MyStr);
 RR=0;GG=244;BB=0;
 }
 
 if (MyStr == "help") {
 Serial.println (MyStr);
 RR=225;GG=255;BB=255;
 }
 
 }
 
}
8
  • 1
    Does it work if you send the same string using the same COM settings using e.g. a terminal program like Putty? Commented Sep 28 at 15:51
  • i think you never declared MyStr. Commented Sep 28 at 16:22
  • 1
    Please provide a real minimal reproducible example. Commented Sep 29 at 3:40
  • Arduino resets on a new USB connection and waits in the bootloader a few seconds Commented Sep 29 at 6:49
  • if ("1".equals(data0)) is what you need. Duplicate Commented Sep 29 at 7:48

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.