AT Communication - Mega with GSM

I'm attempting to use a Multitech socketmodem with my Mega. I had the Arduino GSM Shield working great. The standard GSM library doesn't seem to work out of the box with the multitech modem, so I'm trying to back down and write the AT commands from scratch. I am trying it first with the Arduino GSM Shield that I know works, but I cannot seem to even make this work.

I have tried a few pieces of code I've seen in this forum that supposedly let you type from serial in to the software serial , so that you can type direct AT commands, but this doesn't seem to work for me. I'm using the software serial on (10,3) as the Mega is suppose to, but nothing works. I'm also not apposed to using the extra hardware TX/RX on the mega, but I was hoping to get back to the GSM library with some modification, so I was trying to stay with software serial. Well thanks for any help you can give.

The standard GSM library doesn't seem to work out of the box with the multitech modem

Gee, what a surprise.

I have tried a few pieces of code I've seen in this forum that supposedly let you type from serial in to the software serial , so that you can type direct AT commands, but this doesn't seem to work for me.

What code? How is the modem connected? What actually happened?

I'm using the software serial on (10,3) as the Mega is suppose to, but nothing works.

Pin 3 on the Mega does not support pin change interrupts, which the software serial library uses. Why are you using software serial on a device with 4 hardware serial ports?

I'm also not apposed to using the extra hardware TX/RX on the mega

Why not?

Paul,

Thanks for the reply.

I was trying to software serial because that's what the GSM library was based on. And if I was going to get that work with the new chip, I figured I needed to understand how to talk through it first. I believe the first parameter of softwareserial is the RX and therefore that is why I used pin 10, since it did support change interrupt on 10.

I have also tried hardware serial to no avail. I'll document that at the bottom.

Here is what I've tried. The software serial example:

SoftwareSerial mySerial(10, 11); // RX, TX

void setup()  
{
  // Open serial communications and wait for port to open:
  Serial.begin(57600);
 
  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(4800);
  mySerial.println("Hello, world?");
}

void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}

From this all I see is the "Goodnight Moon!" listed there. No matter what send via the serial monitor, I never see any response. I did also try swapping the RX,TX lines to be sure something wasn't just crossed.

Then I tried it tied into straight serial (swapping again, in case I was wrong on the RX and TX). With what I thought was some serial echo code. And never received any response. I assume that I should be able to type int "AT" and receive "OK", but this has never happened under any scenario.

void setup() {                
  Serial.begin(9600);
}

void loop() {
   /*  check if data has been sent from the computer: */
  if (Serial.available()) {
       Serial.write(Serial.read());
  }
}

Any help will be appreciated.

I have no idea what a 'Multitech socketmodem' is, nor am I going to start looking for it.

However, if you want a general approach to using a SIM900 based modem then check the link in my signature.

Dannable, that link is helpful.

I will not add that piece of code to the list that I cannot get to talk to the gsm. I tried the Software Relay code on pins 7 and 8 and never got a response from the GSM.

Also tried an legit UNO instead of the mega I was using.. Made no difference. Have tried a couple of different computers as well, with no luck.

Hello MakoMaker,
I think I can help you but let's start from scratch again...

Afaik, in order to connect Arduino with a modem (GSM or CDMA) you mostly need to interface/use four pins:

  1. VCC pin
  2. Ground pin
  3. Transmit pin
  4. receive pin

I recommend grounding low-active unused modem inputs DTR and RTS not allowing them to "float" to avoid rubbish.

In order to obtain the establish communication with the modem (i.e. OK response to the 'AT' command), you can use either the SoftwareSerial function or the SerialX.xxx function. For that, I use the following 'bridge' sketches:

Using SoftwareSerial with UNO:

#include <SoftwareSerial.h>

SoftwareSerial GPRS(7, 8); // pin 7 transimit (TX) and pin 8 receive (RX)
unsigned char buffer[64]; 
int count=0;
void setup()
{
  GPRS.begin(115200);
  Serial.begin(19200); 
}

void loop()
{
  if (GPRS.available())
  {
    while(GPRS.available())
    {
      buffer[count++]=GPRS.read();
      if(count == 64)break;
  }
    Serial.write(buffer,count);  
    clearBufferArray();          
    count = 0;                   
  }
  if (Serial.available())     
    GPRS.write(Serial.read()); 
}
void clearBufferArray() 
{
  for (int i=0; i<count;i++)
    { buffer[i]=NULL;}  
}

Using for example Serial2.xxx with Mega:

unsigned char buffer[64];
int count=0;   
void setup()
{
  Serial2.begin(115200);    
  Serial.begin(9600);     

}

void loop()
{
  if (Serial2.available())       
  {
    while(Serial2.available())      
    {
      buffer[count++]=Serial2.read();  
      if(count == 64)break;
  }
    Serial.write(buffer,count);     
    clearBufferArray();            
    count = 0;                     


  }
  if (Serial.available())  
    Serial2.write(Serial.read());   
}
void clearBufferArray()          
{
  for (int i=0; i<count;i++)
    { buffer[i]=NULL;}            
}

Wait around 20 seconds before type 'AT'. Notice that I have set 115200 given that that's the default
baud rate for most Multitech modems (AT+APR?). By the way, which Multitech modem are you using with your Multitech Scoketmodem. MTSMC....?

Regards,

p

Palliser,

Thank you. That is a wealth of info. I would think that even I should be able to make one of those two work. But in nothing that I do, can I receive anything back from the modem. I've tried both the software serial with an Uno, and a hardware serial with a Meta.

I am using the MTSMC-H5. Based on the device guide below, I've connected:

Arduino 5v - h5 VCC (Pin 61)
Arduino GND - h5 GND (Pin 63)

Uno D7 - h5 RxD (Pin 34)
Uno D8 - h5 TxD (pin 35)

Mega TX2 (16) - h5 RxD (pin 34)
Mega RX2 (17) - h5 TxD (pin 34)

(Also I've tried reversing the tx and rx with every configuration in case something was backwards)

http://www.multitech.com/manuals/s000540d.pdf

I am at the point where I am wondering if there is some fault in the modem. I doubt that is the case, but I'm at the end of ideas. I have tried it with a sim card installed and no installed. When the sim is installed, it goes into a slow blink after a minute or two, which the device manual says is it looking for a connection. it does this whether I send it any commands or not. I tried grounding those two pins that were mentioned in the post above as well. No change.

I waited the 20 seconds also. Made no different. Tried both of the methods in the above post several times.

Thanks again so much for the help Palliser.

Hello MakoMaker,

I just tested a MTSMC-H5 with a SocketModem shield (Arduino based) using the Serial2 code and I can communicate with Arduino Due. I mean, I get OK responses after the AT commands. As I told you, given that the SocketModem has the Arduino UNO footprint, I had to use a couple of wires between the shield and the Due pins (TX2/RX2). See below a picture of the pins that I used from the socket modem (ALL the jumpers removed) to connect to the Arduino Due.

Another way to test the modem is connecting the pins you mentioned (61,63,34,35) directly with any Arduino but those pins are too fragile. A little carelessness and you will brake them.

P.S. Here a link to the shield. I am not sure if you are using the same.

Multitech SocketModem Arduino based

Regards,

p

Thanks Palliser.

I have not yet tried it with the Arduino Shield adapter. I wanted to make it work without it so that I knew how to build an accepting socket for it myself. I will go ahead and order one.

I have been using jumper wires directly with the pins on the bottom of the modem. One interesting thing I did find this morning, although I still cannot get a reply, is that the pin 34 marked RxD is the serial output for the modem. I was assuming it was the receiving end, but a support rep at Multitech told me it was the output. and that TxD 35 was the input.

I will try the shield adapter, but plan to continue to test all possible configurations with this modem. I really want need to make it work without the shield, but I can start there.

I've obtained a second one of the H5 modems and have tested it also, so I have confirmed that the problem is not with the device.

Palliser, are you letting the arduino 5v power the modem or are you powering it through the power jack on the shield?

MakoMaker:
Palliser, are you letting the arduino 5v power the modem or are you powering it through the power jack on the shield?

MakoMaker,
I have tried the modem alone like you and it also works OK. This type of modem is TTL (serial).

I am powering the modem through the shield. Voltage in modem between VCC(61) and GND(63) is 4.20 VDC.

Have you tried with the Arduino IDE serial monitor with Newline selected? I am asking you because if you have the No line ending selected, then you will never see the response from the modem. Some times the devil is in the details...

p

Palliser,

I have done it with the Newline selected.

I now the multitech shield and testing with it. Sadly same result, no response yet. I am using 2 diferent computers and 1 real uno and two (chinese) mega's. Trying the software serial on the uno and the serial connection on the mega's. I will continue testing with this. My last ditch effort will be to purchase a scope and use it to determine which pins are transmitting and be sure that things are being configured properly.

One question: When I type in "AT" on the serial window, would you expect to see an "AT" show in the window below? In some configurations I see this echo back. Sometimes, nothing is shown. In some configurations I see giberish, which I feel like might be close to a reponse. I type in "AT" and it replies back with 1 to 3 symbols that dont' make sense.

I have also tried going through several different baud rates with the H5 modem. Also, I've included some println statements when I get that giberish and I see my println text clearly so that makes me think the serial connection with the arduino is fine and the gibberish is coming from the h5.

anyways, I will continue to update here and my adventure continues. I figure eventually it has to click.