Pages: [1]   Go Down
Author Topic: Serial terminal AT commands?  (Read 1547 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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
« Last Edit: January 12, 2014, 04:35:54 pm by Tuppe » Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 104
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey Tuppe,

the second post in this topic will help you

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

Good luck
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I did read that already before posting this, but that method was(if I interpret it correctly) utilizing this function:
Code:
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:
SIM900.print("AT+CMGF=1\r");

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

Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

New day, new thoughts, I was able to make it work!  smiley-money

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:
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:
 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.
« Last Edit: January 15, 2014, 06:28:15 am by Tuppe » Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 104
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

New day, new thoughts, I was able to make it work!  smiley-money

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 smiley-wink. That was what I wanted to tell you, the library command is just sending the AT command over serial just like you do.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Or you can use the method that I explained in the thread I mentioned smiley-wink. 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:
  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;
}
Logged

Pages: [1]   Go Up
Jump to: