Hi guys I'm having a problem with comparing Serial.readString and a String with it always returns false
I am using the Software serial library if that makes any difference
So you check Serial for a character available then use Serial.readString to fill your String named data with characters and then do nothing with it.
Then without checking on mySerial.available you proceed to readString on that in a compare.
I don't use C++ Strings on small memory computers like AVR's. They waste cycles and bytes, they shotgun the heap (RAM) with actions designed to 'make things easier' for, well, I won't say it.
These microcontrollers are small hardware with small RAM. C char array strings are the way to go with these chips. You define your string with a fixed size from the start and you can manipulate the contents directly (char myString[ 12 ] is an array) through indexes and/or pointers or you can use functions in the <string.h> library.
It is not a good idea to use the String (capital S) class as it can cause memory corruption in the small memory on an Arduino. Just use cstrings - char arrays terminated with 0.
Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.
Everyone who has replied has nothing to do with my problem the if statement if (mySerial.readString().equals("SOURCE 11")) never returns true and in my piece of code that doesn't use the readString method if (string*.equals(inData)) returns true the first time it should return true but it doesn't after that no matter which value in the array is used.*
Then maybe set the baudrate up as fast as it runs reliably... perhaps 57600 for soft serial.
That will get your data in faster and clear the output buffer faster too.
Since I got 1.6.9 I've been running Serial at 250000. I have a word-match that keeps up too.