1

I connected a GSM module with the Arduino UNO. The connections are as follows:

Gnd of gsm -----> Gnd of arduino

TX of gsm -----> pin 9 of arduino

Rx of gsm -----> pin 10 of arduino

GSM is powered from a 9V-1Amp wall adapter.

The GSM is performing according to all the AT commands (like making a voice call, hanging a call, answering a call) which are given, but it is displaying garbage values on serial monitor in response.

Here is the code:

#include <SoftwareSerial.h>
SoftwareSerial myserial(9, 10);
void setup() {
 Serial.begin(115200);
 myserial.begin(9600);
 myserial.println("ATDXXXXXXXXXX;");
 delay(30000);
 myserial.println("ATH");
}
void loop() {
 if (myserial.available()>0){
 Serial.println(myserial.read());
 }
}

What could be reasons for the GSM to output garbage values and how can I resolve it?

jfpoilpret
9,1627 gold badges38 silver badges54 bronze badges
asked Dec 20, 2016 at 19:34
4
  • 115200 baud is at the top end of what software serial can handle. It's probably failing miserably. Better to use hardware serial on a board with multiple UARTs. Commented Dec 20, 2016 at 20:49
  • @Majenko from the code, the OP is using SoftwareSerial at only 9600 then that should be fine. Commented Dec 20, 2016 at 21:19
  • @jfpoilpret It was hard to tell since the code was such a mess. Yes, I could have formatted it myself, but that's the job of the OP to do. If they can't even be bothered to do that, then... meh... Commented Dec 20, 2016 at 21:20
  • 1
    Could you post the garbage (and its value in hexadecimal if unprintable) you get? Commented Dec 20, 2016 at 21:20

1 Answer 1

1
 Serial.println(myserial.read());

myserial.read() returns an integer. That integer is either the ASCII code of the next character in the buffer, or -1 if there is no character to read.

You then print that integer, each one on its own line.

So the response "OK\r\n" from, say, "AT\r\n" would look like:

79
75
13
10

Instead you need to write the data, not print it:

Serial.write(myserial.read());

Also, the way you have written your code, you will get no response for 30 seconds - that is, until everything has already happened. Only after it has all finished will you get some feedback - and that may not be complete since you may overrun the buffer depending on what the modem sends.

answered Dec 20, 2016 at 23:20
1
  • I tried using Serial.write() in place of Serial.println() but still I am getting the garbage values. The module is not responding even while sending an AT command through Serial Monitor. Commented Dec 26, 2016 at 15:48

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.