problem with serial communication with arduino uno and 3G Shield SIM5216E

Hi
I have problem with serial communication with arduino uno and 3G Shield SIM5216E ItedStudio. Sketch sends AT command successfully through serial but not able to get reply. Serial monitor just shows AT+CMGF=1 nothing happens after this. If i am connecting shield directly to PC through USB To Serial COM port its working fine in hyper-terminal. Showing all Reply's and messages. Please help what i am missing? Thanks in advance.

int led = 13;
int onModulePin = 8;        // the pin to switch on the module (without press on button) 

int timesToSend = 1;        // Numbers of SMS to send
int count = 0;

int n_sms,x,sms_start;
char data[256];

void switchModule(){
    digitalWrite(onModulePin,HIGH);
    delay(2000);
    digitalWrite(onModulePin,LOW);
}

void setup(){

    Serial.begin(115200);                // UART baud rate
    delay(2000);
    pinMode(led, OUTPUT);
    pinMode(onModulePin, OUTPUT);
    switchModule();                    // switches the module ON

    for (int i = 0;i < 5;i++){
        delay(5000);
    } 

    Serial.println("AT+CMGF=1");         // sets the SMS mode to text
    delay(100);
    x = 0;
    do{
        while(Serial.available()==0);
        data[x]=Serial.read();  
        x++;       

    }
    while(!((data[x-1] == 'K') && (data[x-2] == 'O')));
}

void loop(){

    while (count < timesToSend){
        delay(1500);

        while(Serial.available()!=0) Serial.read();

        Serial.println("AT+CPMS=\"SM\",\"SM\",\"SM\"");    //selects SIM memory
        Serial.flush();
        for (x=0;x < 255;x++){            
            data[x]='\0';                        
        } 
        x=0;
        do{
            while(Serial.available()==0);
            data[x]=Serial.read();  
            x++;       

        }while(!((data[x-1] == 'K') && (data[x-2] == 'O')));

        x=0;
        do{
            x++;
        }while (data[x] != ' ');

        x++;
        n_sms=0;
        do{
            n_sms*=10;
            n_sms=n_sms + (data[x]-0x30);

            x++;

        }while (data[x] != ',');
        
        Serial.print(" ");
        Serial.print(n_sms,DEC);

// Now it shows the total number of SMS and the last SMS
        Serial.println("  SMS stored in SIM memory. Showing last SMS:");

        Serial.print("AT+CMGR=");    //Reads the last SMS 
        Serial.println(n_sms-1,DEC);
        Serial.flush();
        for (x=0;x < 255;x++){            
            data[x]='\0';                        
        } 
        x=0;
        do{
            while(Serial.available()==0);
            data[x]=Serial.read();  
            x++;           
            if((data[x-1] == 0x0D) && (data[x-2] == '"')){
                x=0;
            }
        }
        while(!((data[x-1] == 'K') && (data[x-2] == 'O')));

        data[x-3]='\0';        //finish the string before the OK

        Serial.println(data);    //shows the message

        delay(5000);

        count++;
    }
}

Are you using the Serial instance to talk to the shield or to talk to the PC? You can't do both.

I am using Serial pins TX - D0 and RX D1 for talking to the shield. This shield is 100% Compatible to arduino and stack-able. USB port is present directly on the shield, if communicating with the shield USB port to PC then no Problem but if removing from PC and stacking on the arduino then problem starts.

Hi all is anybody there who can help me?

Hi amitkrj,

First, contol your waiting loop for switching on the module. Some time 55000 is not enough. So when you send the at commnand before the module switched on, the device does not send you any response. Try, 56000,7000 etc.

Second, After sending AT code "Serial.println("AT+CMGF=1")", you must end the command with the sequence of codes belowe.

Serial.write(0x1A);
Serial.write(0x0D);
Serial.write(0x0A);
delay(100);

These should help you with your problem.

Same problem, please help me. Thanks

Same problem, please help me. Thanks

Same solution. Don't try to use the Serial instance to talk to the shield AND the PC. Use the Serial instance to talk to the PC and a SoftwareSerial instance, on other pins, to talk to the shield. Presuming, of course, that you can use other pins. If not, you need a better shield.

PaulS:

Same problem, please help me. Thanks

Same solution. Don't try to use the Serial instance to talk to the shield AND the PC. Use the Serial instance to talk to the PC and a SoftwareSerial instance, on other pins, to talk to the shield. Presuming, of course, that you can use other pins. If not, you need a better shield.

Can you provide example please. I am new to Arduino. Thanks

Can you provide example please.

An example of what? What have YOU tried? You want someone to write code for you, get your wallet out and head over to Gigs and Collaborations.

PaulS:

Can you provide example please.

An example of what? What have YOU tried? You want someone to write code for you, get your wallet out and head over to Gigs and Collaborations.

I'm trying to send at commands to 3G Shield SIM5216E via Arduino UNO board.

void setup()
{
  Serial.begin(115200);

}
void loop()
{
 while(1)
  { 
  Serial.print("ATD0812464224;\r");
  delay(5000);

  }
}

ITEAD 3G Shield
http://imall.iteadstudio.com/im121026002.html

Thanks

I'm trying to send at commands to 3G Shield SIM5216E via Arduino UNO board.

Using an infinite loop inside an infinite loop. Why?

The code does something, but you haven't bothered mentioning what it does.

The USB port on Arduino is the same serial port on Pins 0 and 1. Try configuring your GSM shield to use a SoftwareSerial port. The SeeedStudio GSM shield can use hardware serial (ports 0,1) or SoftwareSerial (ports 7,8). The Arduino cannot communicate to the PC terminal monitor AND the GSM shield on port 0,1 at the same time. I think this is your first problem to resolve. Search examples on software serial. Also, check the manufacturer webpage instructions on how to switch the GSM shield to use SoftWareSerial.

JayStel:
The USB port on Arduino is the same serial port on Pins 0 and 1. Try configuring your GSM shield to use a SoftwareSerial port. The SeeedStudio GSM shield can use hardware serial (ports 0,1) or SoftwareSerial (ports 7,8). The Arduino cannot communicate to the PC terminal monitor AND the GSM shield on port 0,1 at the same time. I think this is your first problem to resolve. Search examples on software serial. Also, check the manufacturer webpage instructions on how to switch the GSM shield to use SoftWareSerial.

Ok, now successfully sent AT Command to 3G Shield via Software Serial.

#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX

char AtCommand[] = "ATI\r";
void setup()  
{
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  Serial.println(AtCommand);

  // set the data rate for the SoftwareSerial port
  mySerial.begin(115200);
  mySerial.println(AtCommand);
}

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

I got following response.

AªRá
?S,«?Âcº]Wt SRSÔÕ$9OR¨JE*e
M??¶HUªjõÕ¿SI©?3ò5?©YW5¥··]HUªU¥

How can i convert this response to string.
Thanks in advance.

How can i convert this response to string.

Store each character in a char array. After each addition, add a NULL.

But, I would think that it would be a good idea to get correct data, first.

SoftwareSerial can, under some circumstances, talking to the right device, for short periods of time, operate correctly at 115200. But, not for long, and not with all devices, and not with a lot else going on, and not with a lot of data being exchanged.

Can you lower the baud rate of the other device?

PaulS:

How can i convert this response to string.

Store each character in a char array. After each addition, add a NULL.

But, I would think that it would be a good idea to get correct data, first.

SoftwareSerial can, under some circumstances, talking to the right device, for short periods of time, operate correctly at 115200. But, not for long, and not with all devices, and not with a lot else going on, and not with a lot of data being exchanged.

Can you lower the baud rate of the other device?

I have just played with the same module. The baud rate is to high for software.serial. But you can change the baud rate of the GSM-module. This code worked for me to get a readable response

#include <SoftwareSerial.h>

#define rxPin 6
#define txPin 7
#define baudrate 9600

SoftwareSerial mySerial(rxPin, txPin); // RX, TX

char AtCommand[] = "ATI\r";
void setup()  
{
  // Open serial communications and wait for port to open:
  Serial.begin(baudrate);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  
  Serial.println(AtCommand);

  // set the data rate for the SoftwareSerial port
  Serial.println("wait 5s for modem to wake up");
  delay(5000);
  mySerial.begin(115200);
  mySerial.println("AT+IPR=9600\r\n"); // chnage baudrate to 9600 baud
  
  Serial.println("Changing baudrate");
  mySerial.begin(baudrate);
  mySerial.println(AtCommand);
}

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

Then I get the following response in terminal

wait 5s for modem to wake up
Changing baudrate
ATI

Manufacturer: SIMCOM INCORPORATED
Model: SIMCOM_SIM5216E
Revision: SIM5216E_V1.5
IMEI: 359769032286210
+GCAP: +CGSM,+DS,+ES

OK

My plan is to use this card with Arduino Mega and hardware UARTs, but I hope this hind can save some struggle fort others.

digitalfotografen:
Store each character in a char array. After each addition, add a NULL.

But, I would think that it would be a good idea to get correct data, first.

SoftwareSerial can, under some circumstances, talking to the right device, for short periods of time, operate correctly at 115200. But, not for long, and not with all devices, and not with a lot else going on, and not with a lot of data being exchanged.

Can you lower the baud rate of the other device?

I have just played with the same module. The baud rate is to high for software.serial. But you can change the baud rate of the GSM-module. This code worked for me to get a readable response

#include <SoftwareSerial.h>

#define rxPin 6
#define txPin 7
#define baudrate 9600

SoftwareSerial mySerial(rxPin, txPin); // RX, TX

char AtCommand[] = "ATI\r";
void setup()  
{
 // Open serial communications and wait for port to open:
 Serial.begin(baudrate);
 while (!Serial) {
   ; // wait for serial port to connect. Needed for Leonardo only
 }
 pinMode(rxPin, INPUT);
 pinMode(txPin, OUTPUT);
 
 Serial.println(AtCommand);

// set the data rate for the SoftwareSerial port
 Serial.println("wait 5s for modem to wake up");
 delay(5000);
 mySerial.begin(115200);
 mySerial.println("AT+IPR=9600\r\n"); // chnage baudrate to 9600 baud
 
 Serial.println("Changing baudrate");
 mySerial.begin(baudrate);
 mySerial.println(AtCommand);
}

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




Then I get the following response in terminal


wait 5s for modem to wake up
Changing baudrate
ATI

Manufacturer: SIMCOM INCORPORATED
Model: SIMCOM_SIM5216E
Revision: SIM5216E_V1.5
IMEI: 359769032286210
+GCAP: +CGSM,+DS,+ES

OK




My plan is to use this card with Arduino Mega and hardware UARTs, but I hope this hind can save some struggle fort others.

Hey I have the issue with the SoftwareSerial stuff. My 3G shield works fine if it connects to Arduino directly without PC. But If I change the baud rate to be 9600 then it would not come out anything but the "ATI" string in the com terminal.

And if i do not change the baud rate, leave it all to be 115200, in the com monitor, I will get some strange output just as

AªRá
?S,«?Âcº]Wt SRSÔÕ$9OR¨JE*e
M??¶HUªjõÕ¿SI©?3ò5?©YW5¥··]HUªU¥

I have test Arduino Uno R3 and Mega R3. Same issue.

Any ideas?

It does not make sense to expect to communicate with the PC at 1/12 the rate that you communicate with the GSM shield. Communication should generally be at the highest speed possible. Having Serial communicate at 115200 should be the first change made.

Of course, whatever speed you use MUST be the same on both ends. That you get entirely unreadable data raises the possibility that they are not.