Not understud serial print when is 19200, on SIM900 + Arduino Uno

Arduino Uno + Sim900.

whith this code the output is clear, but when y put de serial.print (// Serial.println("valida"+valida):wink:
the output is not clear, a lot of numbers.
Paste my cod under de text,
Thanks,

My setup is:

void setup()
{
//digitalWrite(9,HIGH);
//delay(1000);
Serial.println("Esperando Mensajes");
Serial.begin(19200); // for serial monitor
mySerial.begin(19200); // for GSM shield

mySerial.print("AT+CMGF=1\r"); // set SMS mode to text
delay(100);
mySerial.print("AT+CNMI=2,2,0,0,0\r");
// blurt out contents of new SMS upon receipt to the GSM shield's serial out
delay(100);

}

void loop()
{
char SerialInByte;
// Now we simply display any text that the GSM shield sends out on the serial monitor
if(mySerial.available() >0)
{
incoming_char=mySerial.read(); //Get the character from the cellular serial port.
Serial.print(incoming_char); //Print the incoming character to the terminal.
delay(5);
//-------------------------------------------
smsRecibo = String(smsRecibo + incoming_char);
largo = smsRecibo.length();
//valida si prende o apaga, largo 13
if (largo=13)
{
mensaje = smsRecibo;
//Serial.print(mensaje);
int elemento = mensaje.indexOf('O'); //palabra ON o OF
String valida = mensaje.substring(elemento,1);
//prende automatico control por humedad
//T000
if (valida == "ON")
{
//se llama a subrutina para seguir parseando
// Serial.println("valida"+valida);
validar();
}
//apaga

//if (valida == "OF")
//{
/*
//apaga RELE---------------
*/
//apagaRele();
//}
}

}
}

      String valida = mensaje.substring(elemento,1);
      //prende automatico control por humedad
      //T000
      if (valida == "ON")

Did you read the documentation?

Parameters

string: a variable of type String

from: the index to start the substring at

to (optional): the index to end the substring before

So, you are extracting a substring consisting of ONE character max.

If the String does not start with 'O', you are extracting GARBAGE as the substring, starting with position -1. Not a good idea.

A one character String can never equal "ON".

Quit being lazy. Use TWO Serial.print() statements to print two things.

thanks, the problem is:

variable mensaje = PRENDO/ON/T000

and i validate the existence of ON in this string, tell me what is the best solution for this problem,

thanks a lot,
Juan

    if (largo=13)

Most people use == in if statements, for good reason.

tell me what is the best solution for this problem,

First, strings and Strings are completely different things. Do NOT use string when you mean String.

Strings really have no place on the Arduino.

But, since you have them, it pays to read the documentation. The indexOf() method takes a character OR a String, and determines if the object it is called on contains the character or String.

So, if you want to know if a String contains "ON", just ask.

   int onPos = mensaje.IndexOf("ON");
   if(onPos >= 0)
   {
      // mensaje contains "ON"
   }
   else
   {
      // Well, it doesn't
   }

Excelent, a lot of thanks!!!

Out serial monitor: 19200

AT+CMGF=1

OK
AT+CNMI=2,2,0,0,0

OK

al levantar el arduino

Out serial monitor i dont understud un serial print

Serial.print("Largo"+String(largo));

ALargo1TLargo2+Largo3CLargo4MLargo5GLargo6FLargo7=Largo81Largo9
Largo10
Largo11
Largo12OLargo13KLargo14
Largo15
Largo16ALargo17TLargo18+Largo19CLargo20NLargo21MLargo22ILargo23=Largo242Largo25,Largo262Largo27,Largo280Largo29,Largo300Largo31,Largo320Largo33
Largo34
Largo35
Largo36OLargo37KLargo38
Largo39
Largo40

Out serial monitor i dont understud un serial print

Serial.print("Largo"+String(largo));

How about if you ditch the stupid act, and use 2 print statements?

Serial.print("Largo");
Serial.print(largo);

Serial.print("Largo"+String(largo));

largo is one variable.
Thanks

Serial.print("Largo"+String(largo));

largo is one variable.
Thanks

jazpiroz:
Serial.print("Largo"+String(largo));

largo is one variable.
Thanks

What is your point? largo is one variable. "Largo" is one literal. You have TWO things to print. Use TWO Serial print statements, NOT one.

my idea is print in the serial monitor: "Largo 10" for example.
but the problem is: the monitor when i used 9600 for other programs print well, but in this program where i used sim900 set monitor to 19200.
in this escenario the messages for sim900 print well, but the others serial print not.

The baud rate you use to talk to the serial port that the PC is listening to has no relationship with the baud rate you use to talk to the modem. If using 9600 to talk to the PC, keep using that. It doesn't matter that you talk to the modem at a different speed.

ok, thanks por this aclaration. test this and i tell you the results.