How to properly check power supply (any shield) in a sketch ?

Hello everyone,

Does anyone know how can I properly check is my GSM shield (or any other shield) is properly powered on?

Currently I just set the pin numbers.

#define SIM800_RESET_PIN 77
#define PWKEY 6

Then I set these pin as output...

  pinMode(SIM800_RESET_PIN, OUTPUT);
  pinMode(PWKEY, OUTPUT);
  digitalWrite(SIM800_RESET_PIN, HIGH);
  digitalWrite(PWKEY, HIGH);

And a few instruction later I check power supply like this :

    case GSM_WAIT:
      if (digitalRead(PWKEY) == HIGH && digitalRead(SIM800_RESET_PIN) == HIGH) {
        Serial.println("GSM is ON");
        state = GPS_WAIT;
      } else {
        // Error handling, nothing special 
      }
      break;

My program is working, but I think this is a really useless test because in a way i'm just looking at the value of the variable which will alway be the expected value.

In fact, if my shield is not plugged it will still return "GSM is ON" ?
Do you know if it's possible to check this in a better way ?

I could send a command and wait for an expected answer like this :

if (inputString == "theExpectedString\r\n") {
    Serial.println("Expected answer received, consequently : GSM is ON");
}

But it's too long, my GMS is slow to get the network, and I have to be sure that the shield is properly powered on before sending ANY commands.

If someone can help me I would be glad :slight_smile:
Thank you !

Do you really have 77 or more pins on your Arduino?

Do you know if it's possible to check this in a better way ?

What you are checking is whether or not you have turned the power pin on. That isn't really useful information. Far faster to just turn it on.

But it's too long, my GMS is slow to get the network, and I have to be sure that the shield is properly powered on before sending ANY commands.

Present and powered on are two different things. Which are you really concerned about?

Thank you for your answer !

I'm using a Flip&Click board, yes there is a LOT of pins !! :smiley:

I can turn the power pin on, even if I didn't have plugged my shield in...
Checking this pin wont prove me that everything is fine (maybe broken or missing shield).

This only prove me that my shield is powered right ?

That's why I though that the only way to be sure is to receive an expected answer from the shield after sending a command...

I don't really know, maybe you have a better idea !

This only prove me that my shield is powered right ?

It doesn't even do that, actually. It only tells you that the pin is powered. If you don't have the shield connected, it can't possibly be powered.

That's why I though that the only way to be sure is to receive an expected answer from the shield after sending a command...

I don't really know, maybe you have a better idea !

I think you DO know.