GPRS Shield sends wrong char after AT Commands entering

Hello,

Today i have setup my Arduino UNO with the GPRS Shield v1.2 and it seems to work.
But I get sometimes wrong char from the GPRS Shield after i send an AT Command.

You can see the terminal event, that the GPRS Shield starts correctly and with command AT+CMGR=3 I want to read the messages 3.
But I need to retype the command several times, to get the phonenumber correctly transmitted.

What is the Problem?

I use Arduino 1.0

<0>ÿÿÿÿÿÿÿÿ
RDY

+CFUN: 1

+CPIN: SIM PIN
AT+CPIN=XXXX

OK

+PACSP: 1

Call Ready

AT+CMGR=3

+CMGR: “REC READ”,"+436–42163404","",“12/06/09,19:50:43+˜8”
:-
ÿÿAT+CMGR=3

+CMGR: “REC READ”,"+436–42163404","",“12/06/09,19:50:43«08”
:-AT+CMGR=3

+CMGR: “REC READ”,"+4“6642163404","",“12/06/09,19:50:43+08”
:-AT+CMGR=3

+CMGR: “REC READ”,"+43664²163404","",“12/06/09,19:50:43+0¸”
:-AT+CMGR=3

+CMGR: “REC READ”,"+436–42163404","",“12/06/09,19:50:43+˜8”
:-
AT+CMGR=3

+CMGR: “REC READ”,"+4366”2163404","",“12/06/09,19:50:43+°8”
:-AT+CMGR=3

+CMGR: “REC READ”,"+43664216344","",“12/06/09,19:50:43+08”
:-ÿÿ

And here my small Arduino Sketch

#include <SoftwareSerial.h>

SoftwareSerial GPRS(4, 5);

void setup()
{

GPRS.begin(19200); // the GPRS baud rate
Serial.begin(19200); // the GPRS baud rate
pinMode(3, OUTPUT);
digitalWrite(3,LOW);
delay(1000);
digitalWrite(3,HIGH);
delay(2500);
digitalWrite(3,LOW);
delay(3500);
GPRS.print(“AT+CPIN=xxxx\r”);
}

void loop()
{
if (GPRS.available())
{
Serial.write(GPRS.read());
}
if (Serial.available())
GPRS.write(Serial.read());

}

no idea? :frowning:

there must be a reason why I getting wrong char into a transmisson… :question:

hi idS2001,after did a experiment, we consider the problem is occur in soft serial transfering data to the hard serial, you can do a test:
connect the pin D0 of Xduino to the pin 1 of the gprs shield, connect the pin D1 of Xduino to the pin of 0, and connect the VCC, GND of the Xduino to the VCC,GND of the gprs shield. it make the serial of the computer connect to the serial of the gprs shield directly, download a empty sketch to the Xduino, the connection as the picture:

jumper.png
in this time, your problem will no longer occurs, the experiment was proof the problem is caused by the program of the arduino , the gprs shield is working normally, in fact, if you are connect the Xduino and the gprs shield by the hard serial, the shield also can working normally. the problem you represent was occur in:
if (GPRS.available())
{
Serial.write(GPRS.read());
}
if (Serial.available())
GPRS.write(Serial.read());

Hello,

thx for your answer.
I think I found the problem in the software Serial Code. The error is not in the general code of the softwareserial library. I think the problem is that I and you in your wiki write the code without buffering the data from the serialport not into a char array.

In my arduino sketch, i changed the code in void main() from

if (GPRS.available())
{
Serial.write(GPRS.read());
}
if (Serial.available())
GPRS.write(Serial.read());[/code]

to following code


[code]#include <SoftwareSerial.h> 

SoftwareSerial GPRS(4, 5);
char buffer[255]; // buffer array for data recieve over serial port
int count=0;     // counter for buffer array

void clearBufferArray(); // initialize function
void setup()
{
  
  delay(10000);

  GPRS.begin(19200);               // the SoftwareSerial baud rate for communication between gprs shield and arduino
  Serial.begin(19200);             // the HardwareSerial baud ratte for communication between arduino and pc or notebook
  pinMode(3, OUTPUT);              // start up procedure for gprs shield to power up
  digitalWrite(3,LOW);
  delay(1000);
  digitalWrite(3,HIGH);
  delay(2500);
  digitalWrite(3,LOW);
  delay(3500);                      // end of start up procedure 
  GPRS.print("AT+CPIN=xxxx\r");     // send AT Command and PinCode over softwareserial from arduino to gprs shield
  pinMode(13,OUTPUT);
  
  digitalWrite(13,HIGH);
  //delay(5000);
}
 
void loop()
{
  if (GPRS.available())              // if date is comming from softwareserial port ==> data is comming from gprs shield
  {
    while(GPRS.available())          // reading data into char array 
    {
      buffer[count++]=GPRS.read();     // writing data into array
    }
    Serial.write(buffer);            // if no data transmission ends, write buffer to hardware serial port
    Serial.print("\r");              // send a CR because it is missing
    count = 0;                       // set counter of while loop to zero
    clearBufferArray();              // call clearBufferArray function to clear the storaged data from the array
    
    

  }
  if (Serial.available())            // if data is available on hardwareserial port ==> data is comming from PC or notebook
    GPRS.write(Serial.read());       // write it to the GPRS shield
}


void clearBufferArray()              // function to clear buffer array
{
  for (int i=0; i<255;i++)
    { buffer[i]=NULL;}                  // clear all index of array with command NULL
}

And after tryout I get perfect transmitted data from the GPRS Shield over SoftWareSerial :slight_smile:)

good job!!, thanks for your sharing, we will test the code you supplied, and update it soon.

look, here is my update for a smarter solutions if you are useing Arduino version bigger than 0019. Here you can use the String class.

[code]
#include <SoftwareSerial.h>
#define terminator 10 // DEC value for a LF(line feed) to skip while loop

SoftwareSerial GPRS(4, 5);
String IncDataSerial = “”; // a string for incomming text from GPRS shield over software serial

void setup()
{

delay(10000);

GPRS.begin(19200); // the SoftwareSerial baud rate for communication between gprs shield and arduino
Serial.begin(19200); // the HardwareSerial baud ratte for communication between arduino and pc or notebook
pinMode(3, OUTPUT); // start up procedure for gprs shield to power up
digitalWrite(3,LOW);
delay(1000);
digitalWrite(3,HIGH);
delay(2500);
digitalWrite(3,LOW);
delay(3500); // end of start up procedure
GPRS.print(“AT+CPIN=xxxx\r”); // send AT Command and PinCode over softwareserial from arduino to gprs shield
}

void loop()
{
if (GPRS.available()>0) // if date is comming from softwareserial port ==> data is comming from gprs shield
{
boolean getLF = false;
while(GPRS.available()>0 && !getLF) // reading data into string if activity is on port and getLF is false ==> no LF have been send
{
char buffer=GPRS.read(); // writing data into char
IncDataSerial += buffer;
if (buffer == terminator) {getLF = true;}
}

Serial.print(IncDataSerial);               // send string ( char array ) to hardware serial
Serial.print("\r");      // send a CR because it is missing

if (IncDataSerial.substring(0,5)  =="+CMGR") // gives you the call ID from the person who has send you an sms
{
  Serial.print("the phonenumber is: "); 
  Serial.println(IncDataSerial.substring(19,32)); // Format in Austria of mobile phone number +43xxx xxxxxxx => if your number  

//is longer you must change the substring values ( here 19 and 32)
}
IncDataSerial = “”;
}
if (Serial.available()>0) // if data is available on hardwareserial port ==> data is comming from PC or notebook
GPRS.write(Serial.read()); // write it to the GPRS shield
}[/code]

if you looks at substring to +CMTI you can detect an incomming sms and with the string class functions ( see arduino.cc) you get out all necessary informations after reading strings from your serial device.

I hope you like my open source code idea :slight_smile:

thanks again, we also update the gprs shield demo code in our wiki seeedstudio.com/wiki/GPRS_Sh … tware_UART.