1

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:

Garbage output from printing the data char during the Response function

Has anyone experienced this problem and knows a way to properly initialize the GSM module?

6
  • 2
    GSM module running at a different baud rate?
    – Majenko
    Sep 17, 2015 at 19:25
  • Is there a way to determine which baud rate it's running at? Or reset it?
    – Andrew
    Sep 17, 2015 at 19:44
  • 2
    Experiment by trying different common "standard" baud rates - if you find that a different one works then that's your problem. If not, then it's not.
    – Majenko
    Sep 17, 2015 at 19:52
  • I tried all of the baud rates from 2400-115200 and they all produced similar outputs. I also tried changing the jumper pin on the GSM module to change the TX/RX pins but that did not work either.
    – Andrew
    Sep 18, 2015 at 11:09
  • In your initialize-func after sending the AT+CMGF=1 you have the Response() before the delay(). I wonder if that matters.
    – ott--
    Jan 3, 2016 at 19:25

1 Answer 1

1

I am owner of this blog whose link you shared, so first of all, I am felling happy that you got something out of it. Now secondly, this code you got from my post is incomplete.

You need to buy that one in order to get the complete code. The code I designed is using AT commands but the above code which you have mixed with your own code is using the Arduino library that's why it's not giving the correct results.

So, either use the complete code from my website or use the Arduino library code only because it has the commands for checking the response, you don't need to use my code to get the response.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.