GSM shield

How can I debug and find the error ind this code
while(notConnected)
{
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
notConnected = false;
else
{
Serial.println("Not connected");
delay(1000);
}
}

The problem is: gsmAccess.begin(PINNUMBER)==GSM_READY
the gsmAccess.begin doesn't returm GSM_READY
how can I debug on this?
I know til PINNUMBER is correct I have defined it earlier

best regards
Nikolaj

How you can debug it?
I would start by checking what gsmAccess.begin() does return.

I know i return char : 0 if asynchronous. If synchronous, returns status : ERROR, IDLE, CONNECTING, GSM_READY, GPRS_READY, TRANSPARENT_CONNECTED

But maby it returns GPRS_READY instead of GSM_READY.
but I tried to
String a;
a= gsm.begin(PINNUMBER);
Serial.println(a);

But i don't work I think is is the String format which is the problem, because it returns a char.
But char[20] a; dosn't work

Hm. You could compare the returned value with all the different statuses to find the right one.

A good usecase for a switch-statement.

That could be a god Idear :slight_smile: I will do that :slight_smile:
But Is it posible just to Serial.println it ?

Not sure.
I know putchar is used to print chars in C, but I don't know if it works with the arduino.

It's a good idea to post the errors you are getting, with the entire traceback, so that people can better help you debug your code. And remember to use code tags.

THIS IS MY CODE:

// import the GSM library
#include <GSM.h>

// PIN Number
#define PINNUMBER "7133"

// initialize the library instance
GSM gsmAccess(true); // include a 'true' parameter for debug enabled
GSMScanner scannerNetworks;
GSMModem modemTest;

void setup()
{
// initialize serial communications
Serial.begin(9600);
//scannerNetworks.begin();
Serial.println("Setup");
}

void loop(){
Serial.println("loop");
switch (gsmAccess.begin(PINNUMBER)) {
case 0:
Serial.println("Synkroniserer ikke");
break;
case IDLE:
Serial.println("IDLE");
delay(1000);
break;
case CONNECTING:
Serial.println("CONNECTING");
delay(1000);
break;
case GSM_READY:
Serial.println("GSM_READY");
delay(1000);
break;
case GPRS_READY:
Serial.println("GPRS_READY");
delay(1000);
break;
case TRANSPARENT_CONNECTED :
Serial.println("TRANSPARENT_CONNECTED ");
delay(1000);
break;
default:
Serial.println("ERROR eller udefineret");
delay(1000);
break;
}
}

THIS IS THE OUTPUT:
Setup
loop

Is dosn't give me a clue why gsmAccess.begin(PINNUMBER) dosn't return anything

Use code tags.

You did not include the ERROR status, but I think there must be an error elsewhere in your code as the default case is not getting called.
Do you get any warnings during compilation? Does it print this only once, indicating that the loop is broken?

No there isn't any Error when I compile nether any warnings.

NOW IT returned: GSM_READY

But I took serval minutes, isnt't that long time?

The problem was that my power suply was through the USB, which makes the GSM shield unreliable.
When I connected an external power suply, in my case 9Volt batteri.
Then the GSM shield returned the right AT commands and then the function began to work proberly.

and then the function began to work proberly.

But, they won't for long.