School project problem (arduino)

A little further exploration on the topic…

If you are going to use println() from the Arduino it will send a \r (return) and \n (line feed) as part of the string.

//Shows where \n and \r are in the received data: 
String temp = valori;
temp = temp.replace('\n', 'n');
temp = temp.replace('\r', 'r');
println(temp);

//You must trim whitespace before compare to remove \r and \n
valori = trim(valori);
println(valori);

You may not compare strings with == and must use equals().

References:
https://processing.org/reference/String_equals_.html
https://processing.org/reference/trim_.html

I modified my write() in previous code to println() on the Arduino side and modified Processing code as per this discussion and it works.

This is just one way to do this.

1 Like