Setup() and loop() function do not execute ?

Hello,

In the Code below I used Serial.println() to debug the Program.

It do not execute any of the Serial.println().

I could upload the Code without Problems.

What could be cause ?

Thanks

#include <GSM.h>

#define PINNUMBER 
#define PIR 2 

// initialize the library instance
GSM gsmAccess;
GSM_SMS sms;
GSMVoiceCall vcs;
char numtel[20];

void setup() {
  pinMode(PIR, INPUT);
  Serial.begin(9600);
  while(!Serial);
  // connection state
  bool notConnected = true;

  // Start GSM shield
  // If your SIM has PIN, pass it as a parameter of begin() in quotes
  while (notConnected) {
    if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
      notConnected = false;
    } else {
      
      delay(1000);
    }
  }
  vcs.hangCall();
  Serial.println("setup-okay");
}


void loop() {
  Serial.println("loop-okay");
  if(digitalRead(PIR) == HIGH) {
   Serial.println("PIR okay");
  char remoteNum[20] = {""};  // telephone number to send sms
  // sms text
  char txtMsg[200] = {"Hi, someone seems into your Object !?"};

  // send the message
  sms.beginSMS(remoteNum);
  sms.print(txtMsg);
  sms.endSMS();
 }

 switch (vcs.getvoiceCallStatus()) {
    case IDLE_CALL: // Nothing is happening

      break;

    case RECEIVINGCALL: // Yes! Someone is calling us
      // Retrieve the calling number
      vcs.retrieveCallingNumber(numtel, 20);

      // Answer the call, establish the call
      vcs.answerCall();
      break;

    case TALKING:  // In this case the call would be established
      
      break;
  }
  delay(1000);
}

Use a Serial.println(…) into the setup function before the first while. Then you now, that your program runs.
Your while loop should have a time Limit, actual IT can hang endless…

Hello RudolfAtRTC,

Thank you, now it print out the message from the setup function.

However not from the loop function ?

Thanks

(we can’t see your code)

TheMemberFormerlyKnownAsAWOL:
(we can't see your code)

Hi,
Sorry my last Post didn't include some Code, but my first Post did it.

Because IT hangs in the while loop!
Your GSM is Not responding.

Hello,

Thanks for the Answer.

This is the actual setup() Function :

void setup() {
  pinMode(PIR, INPUT);
  Serial.begin(9600);
  Serial.println("setup-okay");
  //while(!Serial);  // not running
  // connection state
  bool notConnected = true;

  // Start GSM shield
  // If your SIM has PIN, pass it as a parameter of begin() in quotes
  while (notConnected) {
    if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
      Serial.println("connected");
      notConnected = false;
    } else {
      Serial.println("Not connected");
      delay(1000);
    }
  }
  vcs.hangCall();
  Serial.println("Waiting for a call!");
}

Which loop do you mean, the while(!Serial); I commented out, now it's just the Connection state loop ?

I tested the SIM-card on a normal Mobile-phone and it's activated and works.

"Edit-1" Not sure about this, perhaps it's because the Power, or the SIM-card type (I use 4G-SIM, and Power from the USB ?) :
As written in the Specification for GSM-Shield-2 :

Power
It is recommended that the board be powered with an external power supply that can provide between 700mA and 1000mA. Powering an Arduino and the GSM shield 2 from a USB connection is not recommended, as USB cannot provide the required current for when the modem is in heavy use.

and

SIM to use with this shield
The GSM shield 2 is compatible with Data only and Voice and Data SIM. GPRS and SMS are supported by 2G Data only SIM, while voice calls, supported by the hardware, require a Voice and Data SIM, the same you may use in a GSM mobile phone. The Data transfer is based on GPRS technology and therefore it is not compatible with 3G or UMTS only network providers. GPRS is a 2G technology.

https://www.arduino.cc/en/Main.ArduinoGSMShield

Thanks

So what does your setup function print ? Only the okay message, something more or does it get to ‘waiting for a call’?

I have doubts about the way you pass PINNUMBER; might be mistaken though. Try to pass PINNUMBER as an emoty string.

Where did you get the gsm library?

sterretje:
So what does your setup function print ? Only the okay message, something more or does it get to ‘waiting for a call’?

I have doubts about the way you pass PINNUMBER; might be mistaken though. Try to pass PINNUMBER as an emoty string.

Where did you get the gsm library?

I’m sorry about, yes that’s right, now I use #define PINNUMBER “1234” and it print out “not connected”.

The GSm-library is #include <GSM.h> on Arduino IDE 1.8.10 .

Solved, it was a PIN number issue.

Thought there was a PIN activated.

Thanks for all.

Can you post your updated code? It can help others.

#include <GSM.h> is the library that you included. It does not say how you installed it.

The Code works, but the Hardware does not work at all, as excepted.

It sends SMS, and receive calls, just the Audio don’t work.

As Example, the Microphone connected to the Audiojack of the GSM-Shield V2, do not work.
I will try to use the soldering points (M1P/M1N) on the shield, for the Microphone.

And the digital-PIN 8 on the Arduino, seems to not get low, when the PIR-out connector is low.

#include <GSM.h>

#define PINNUMBER ""
#define PIR 8 

// initialize the library instance
GSM gsmAccess;
GSM_SMS sms;
GSMVoiceCall vcs;
char numtel[20];

void setup() {
  pinMode(PIR, INPUT);
  Serial.begin(9600);
  //Serial.println("setup-okay");
  //while(!Serial);
  // connection state
  bool notConnected = true;

  // Start GSM shield
  // If your SIM has PIN, pass it as a parameter of begin() in quotes
  while (notConnected) {
    if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
      //Serial.println("connected");
      notConnected = false;
      theGSM3ShieldV1ModemCore.println("AT+QAUDCH=1"); // trying to get Audio/Speaker/Microphone) through Audiojack
      theGSM3ShieldV1ModemCore.println("AT+QMIC");     // ""
    } else {
      //Serial.println("Not connected");
      delay(1000);
    }
  }
  vcs.hangCall();
  //Serial.println("Waiting for a call!");
}


void loop() {
  //Serial.println("loop-okay");
  if(digitalRead(PIR) == HIGH) {
   Serial.println("PIR okay");
  char remoteNum[20] = {"SomeNumber"};  // telephone number to send sms
  // sms text
  char txtMsg[200] = {"Hi, someone seems into your Object !?"};

  // send the message
  sms.beginSMS(remoteNum);
  sms.print(txtMsg);
  sms.endSMS();
  //delay(2000);
  digitalWrite(PIR, LOW);
 }
 if(digitalRead(PIR) == LOW) {
  Serial.println("PIR down");
 }
 switch (vcs.getvoiceCallStatus()) {
    case IDLE_CALL: // Nothing is happening

      break;

    case RECEIVINGCALL: // Yes! Someone is calling us
      // Retrieve the calling number
      vcs.retrieveCallingNumber(numtel, 20);

      // Answer the call, establish the call
      vcs.answerCall();
      break;

    case TALKING:  // In this case the call would be established
      
      break;
  }
  delay(1000);
}