Hi guys!
I have to implement communication via serial port. I have a GPS module which sends to Arduino (via Serial port, i made an interface to normalize tension with a simple MAX232 since the module works at +-12 or so).
Ok, communication between Arduino and GPS is fine, 'cause i can read the GPS sentences. I'm using the SerialEvent() example but i have a "little" problem: it just doesn't clear the inputString. Via serial monitor i see the same sentences repeated over and over very fast but it doesn't clear the string: i just see the sentences repeated very fast and it stops only when i detach the RX pin or when i power down the GPS. Nor i can't compare the string! If i make
if(inputString == "Ready")
where Ready is actually the string received by Arduino it seems that he doesn't enter in the 'if' condition.
Here's the code, which is nearly the original:
String inputString = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete
void setup() {
// initialize serial:
Serial.begin(9600);
// reserve 200 bytes for the inputString:
inputString.reserve(200);
}
void loop() {
// print the string when a newline arrives:
if (stringComplete) {
Serial.println(inputString);
/* this is where my added code is, but for some reason it doesn't work*/
if(inputString=="Ready") {
Serial.print("Ok, please begin");
}
// clear the string: this doesn't work.
inputString = "";
stringComplete = false;
}
}
/*
SerialEvent occurs whenever a new data comes in the
hardware serial RX. This routine is run between each
time loop() runs, so using delay inside loop can delay
response. Multiple bytes of data may be available.
*/
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
if (inChar == '\n') {
stringComplete = true;
}
}
}
What i have to think? Maybe there's a mistake on the MAX232 interface, like a loop on some pin, but... i don't think: i tried to look with an oscilloscope and i see what i'm expecting to see.
This is a weekend project, but i'm expecting it to work!

Thank you guys!