I posted a couple weeks ago about having a GSM error. I moved past it and the code seemed to be working on my GSM module (I think a SIMCOM). But then I needed to create some more systems and out of a total of 8 GSM modules, my code and setup only work on two of them - despite the fact that they should be identical and from the same supplier.
The following code (thanks to this genius post) works without error to send and receive SMS on two of the boards:
#include <SoftwareSerial.h>
char inchar; // Will hold the incoming character from the GSM shield
SoftwareSerial SIM900 = SoftwareSerial(2,3);
void setup() {
Serial.begin(19200);
initializeGSM();
}
void initializeGSM() {
SIM900.begin(19200);
Serial.println("Turned on");
SIM900.print("ATEO\r");
Response();
SIM900.print("AT\r");
delay(1000);
Response();
SIM900.println("AT+CMGF=1\r"); // set SMS mode to text
Response();
delay(1000);
SIM900.println("AT+CNMI=1,2,0,0,0\r");
delay(100);
Response();
delay(5000); // give time to log on to network.
Serial.println("Ready...");
}
void Response() {
int count = 0;
delay(1000);
Serial.println(SIM900.available());
while(1) {
if(SIM900.available()) {
char data =SIM900.read();
if(data == 'K'){Serial.println("OK");break;}
if(data == 'R'){Serial.println("GSM Not Working");break;}
}
count++;
if(count == 100){Serial.println("GSM not Found");break;}
}
}
void loop() {
RecSMS();
delay(2000);
}
void RecSMS(){...}
So again, the above code works to set up the module on 2 modules. On the other 6, it simply hangs during the Response()
call. SIM900.available()
returns 0 and then says "GSM Not Found." So I tried to initialize the TX pin during setup as:
digitalWrite(2, LOW);
Which then gives me a promising SIM900.available()
value of about 63, which corresponds to what a confirmation would be. However, when I print the "data" variable containing the byte read off the GSM module/SIM card, I get a couple bits of garbage like the following output:
Has anyone experienced this problem and knows a way to properly initialize the GSM module?
AT+CMGF=1
you have theResponse()
before thedelay()
. I wonder if that matters.