Go Down

Topic: Serial terminal AT commands? (Read 2704 times) previous topic - next topic

Tuppe

Jan 12, 2014, 10:32 pm Last Edit: Jan 12, 2014, 10:35 pm by Tuppe Reason: 1
I want to send AT commands to SIM900 module through Serial terminal. This is driving me crazy, I've been stuck with this problem about 5 hours now.

I can communicate fine with the module(SoftwareSerial), for example:

SIM900.print("AT+COPS?\r");

I'm able to receive all the information. But I'd like to insert commands directly through the Serial terminal too.

This is what I have, but it's not working:
Code: [Select]
if (Serial.available()){
String inputString;
while (Serial.available())
{
   char inChar = (char)Serial.read();
   inputString += inChar;
}
SIM900.print(inputString);
}


Is it because all the characters are separated? If I use Serial.println, all the characters appear on different lines, thus they probably have carriage return after each character, so instead of "AT+COPS?\r" I'm sending "A\r\nT\r\n+\r\nC\r\nO\r\nP\r\nS\r\n?\r\n"
How can I truncate those characters to one piece of string?

I have tried strcat and various methods also with no avail.

I'm losing my mind here :smiley-eek:

MathiasVDA

Hey Tuppe,

the second post in this topic will help you

http://forum.arduino.cc/index.php?topic=206159.0

Good luck

Tuppe

I did read that already before posting this, but that method was(if I interpret it correctly) utilizing this function:
Code: [Select]

modemAccess.writeModemCommand(AT_COMMAND,tDelay);


I don't use any libraries(not the GSM library) other than SoftwareSerial, I'm sending commands directly, for example:
Code: [Select]
SIM900.print("AT+CMGF=1\r");

I don'y know what the writeModemCommand does internally, so I cannot implement it.

Tuppe

#3
Jan 13, 2014, 12:49 pm Last Edit: Jan 15, 2014, 12:28 pm by Tuppe Reason: 1
New day, new thoughts, I was able to make it work!  $)

The whole problem was within the Serial.read speed.
Here's a topic about the problem:
http://forum.arduino.cc/index.php/topic,48103.0.html

Only if I add "delay(1)" to the loop, I'm able to send the packet as a whole!
Code: [Select]
if (Serial.available())
{
 char sinchar;
 SIM900.print("AT+");
 while((sinchar=Serial.read())>=0)
 {
 SIM900.print(sinchar);
 delay(1);
}
 SIM900.print("\r");
}


Also, when I read the message, I need to add delay(1), or else the message is getting randomly corrupted.
Receiving:
Code: [Select]
 if(SIM900.available())
 {
 while((inchar=SIM900.read())>=0)
 {
   Serial.print(inchar);
   delay(1);
   carray[i]=inchar;
   i++;
 }
}

!NOTE! If you add delay to receiving, buffer might fill out faster than you can read the characters, so everything longer than 64 characters will get cut.
Solution: remove the delay if possible or increase buffer size to 128 or 256(very high, takes away from SRAM).

It was about that little thing all the time. I was so sure that it should work with that code that it made me insane. It just needed some extra time.

If anyone knows a better workaround for this, please let us know. Delaying is never a good option, but in my case, I don't need super lightning fast transmissions.

I hope someone finds this solution helpful.

MathiasVDA


New day, new thoughts, I was able to make it work!  $)

The whole problem was within the Serial.read speed.
Here's a topic about the problem:
http://forum.arduino.cc/index.php/topic,48103.0.html

Only if I add "delay(1)" to the loop, I'm able to send the packet as a whole!


Or you can use the method that I explained in the thread I mentioned ;). That was what I wanted to tell you, the library command is just sending the AT command over serial just like you do.

Tuppe


Or you can use the method that I explained in the thread I mentioned ;). That was what I wanted to tell you, the library command is just sending the AT command over serial just like you do.

Yes, but you need to include GSM library files for that. I'm short on space and can't waste it on libraries.

The library performs this function, which is equivalent to my own written one:
Code: [Select]

  if(trace)
Serial.println(ATcommand);

  // Flush other texts
  flush();
 
  //Enter debug mode.
  connect();
  //Send the AT command.
  println(ATcommand);

  delay(responseDelay);

  //Get response data from modem.
  String result = "";
  if(trace)
theGSM3ShieldV1ModemCore.gss.cb.debugBuffer();

  while (available())
  {
    char c = read();
    result += c;
  }
  if(trace)
Serial.println(result);
  //Leave the debug mode.
  disconnect();
  return result;
}

Go Up