[SOLVED] Error while sending SMS

Hello,

I'm currently testing the GSM shield and the result is currently not as expected...

Here is the context:

  • I bought a prepaid card
  • I went through the process I wanted to automate with a regular phone: enter the pin code, send a given message on a given phone number

It worked before using the shield, and after also (so: no issue with the pin code, chip, ...)

I tried to automate the process with the following code. The first step is OK (pin code accepted) -> The error occurs on sms.begin(phone). I tried to format the phone number in national/international formats: it does not work...

#include <GSM.h>

#define PIN   "1111"
#define PHONE "0473436495"
#define TEXT  "Hello, from Arduino!"

boolean isOK;

void setup()
{
  GSM gsm;
  boolean isInitialized;
  GSM_SMS sms;
  char resultBeginGSM;
  int resultBeginSMS;
  int resultEndSMS;

  isOK = false;
  
  Serial.begin(9600);
  pinMode(13, OUTPUT);

  Serial.println("**************************************************");
  Serial.println("Example: using Arduino GSM Shield");
  Serial.print  ("Parameters: - PIN   = ");
  Serial.println(PIN);
  Serial.print  ("            - PHONE = ");
  Serial.println(PHONE);
  Serial.print  ("            - TEXT  = ");
  Serial.println(TEXT);
  Serial.println("**************************************************");
  Serial.println("");

  Serial.println("... Initializing GSM shield");   
  resultBeginGSM = gsm.begin(PIN);
  switch(resultBeginGSM)
  {
    case ERROR:
      Serial.println("--- Error while initializing the GSM shield");
      isInitialized = false;
      break;
    case GSM_READY:
      Serial.println("+++ GSM shield has been correctly initialized");
      isInitialized = true;
      break;
    default:
      Serial.print("--- UNDEFINED error while initializing the GSM shield: ");
      Serial.println(resultBeginGSM);
      isInitialized = false;
      break;
  }
  Serial.println("");
  
  if(isInitialized == true)
  {
    Serial.println("... Trying to send an sms");
    
    resultBeginSMS = sms.beginSMS(PHONE);
    if(resultBeginSMS == 1)
    {
      sms.print(TEXT);
      resultEndSMS = sms.endSMS();
      if(resultEndSMS == 1)
      {
        Serial.println("+++ Message successfully sent");
        isOK = true;
      }
      else
        Serial.println("-- Error while sending message");
    }    
    else
      Serial.println("--- Error while initializing SMS");
      
    Serial.println("");
  }
}


void loop()
{
  if(isOK == true)
    digitalWrite(13, HIGH);
  else
  {
    digitalWrite(13, HIGH);
    delay(250);
    digitalWrite(13, LOW);
    delay(250);
  }
}

Is someone able to explain me what I am missing???

Thanks a lot for your help
Serge

Little update about my problem: when I instantiate my variable gsm in debug mode "GSM gsm(true)", it works.
Is there some tricks behind that???

Serge

I added a delay after the GSM was initialized and it works fine now!