GSM Modem Power Cycle Issue

Hey guys - quick question that has me stumped. I have a GSM shield attached to a nano with power pin on D9 and software serial on 10,11.

My problem is on setup I start the software serial port and pull pin 9 high then low to turn the modem on. The issue is if I re-connect the com port on the pc it turns the gsm modem off. I was thinking of trying to set a flag prior to pulling pin 9 up and down that would check if the modem responds to any command (e.g. AT). I am just not sure how to do that in the setup part of the loop vs the main loop. any ideas/pointers?

Thanks :slight_smile: