SIM800C Serial Read Problems

Ahhh those pesky GSM modules. Pay £40 for an adafruit one and it's all set up for you, or pay £5 for a SIM800 module on it's own and you're in for a world of debug.

So I bought one (link below) and it's been a bit of a nightmare. Hoping for some sound advice.

I'm not having a single issue with sending information to it, it's just receiving information from it. I need that to know when someone is calling, to check my texts etc.

What's NOT wrong:

  • My baud rates are matching. They always are. The GSM module runs at 9600. Please do not suggest that I check this. I've got that one down!

  • It does connect to the network very quickly.

  • I've tried a few power supplies with varying degrees of success. I hear these modules spike at 2A when connecting to a network and making a call. I can do all those things effectively with both USB and Lipo battery power.

  • I've had it call and text my phone with no issues. When I call it, the phone rings, so I know it's connected with no issues.

What IS wrong:

  • It won't send formatted serial information to me. I get black diamonds with question marks inside, or complete gibberish.

  • Sometimes it'll just echo what I send to it without ever replying as it should.

Things I've tried:

  • MORE POWER! I've given it everything, and all of it's functions work except sending correct serial information to me.

  • All types of serial. Hardware, software, altsoft serial. All of them give me the same results.

  • Every sketch I could find online.

  • Even the FONA Library from Adafruit.

Here's some code I use which very effectively sends me texts and calls me...

/*
  GSM Send Sketch for Arduino
  
  Initializes GSM Module and sends an SMS to recipient
  
  The circuit:
  *Arduino pin 0 (RX) - GSM Module (TX)
  *Arduino pin 1 (TX) - GSM Module (RX)
  
  Created 2010
  by Meann Zabanal
  Modified 
  by John for GSM Shield testing
  Modified August 20, 2015
  by Amoree for GSM Shield testing Serial Monitor
*/

char Rx_data[150];
unsigned char Rx_index = 0;
int i = 0;
char msg[160];
int sig;

#define DEBUG true
void setup()  
{
  Serial.begin(9600);
  Serial1.begin(9600);
  
  init_GSM();
  //send_msg("NUMBER HERE", "Oooookaaaaayyyyyy.....?");  
}

void loop()
{
  if (Serial1.available())
    Serial.write(Serial1.read());
  if (Serial.available())
    Serial1.write(Serial.read());
}

void send_msg(char *number, char *msg)
{
  char at_cmgs_cmd[30] = {'\0'};
  char msg1[160] = {'\0'};
  char ctl_z = 0x1A;

  sprintf(msg1, "%s%c", msg, ctl_z);
  sprintf(at_cmgs_cmd, "AT+CMGS=\"%s\"\r\n",number);
  
  sendGSM(at_cmgs_cmd);
  delay(100);
  delay(100);
  delay(100);
  sendGSM(msg1);
  delay(100);
}

void sendGSM(char *string){
  Serial1.write(string);
  delay(90);
}

void clearString(char *strArray) {
  int j;
  for (j = 100; j > 0; j--)
    strArray[j] = 0x00;
}

void send_cmd(char *at_cmd, char clr){
  char *stat = '\0';
  while(!stat){
    sendGSM(at_cmd);
    delay(200);
    readSerialString(Rx_data);
    Serial.write(Rx_data);
    
    stat = strstr(Rx_data, "OK");
    Serial.println("Success");
    delay(50000);
  }
  if (clr){
    clearString(Rx_data);
    delay(200);
    stat = '\0';
  }
}

void init_GSM(){
  
 
  sendData("AT\r\n",1000,DEBUG); // AT
  sendData("ATD +447715451589;\r\n",1000,DEBUG); 
  //sendData("AT+CMGF=1\r\n",1000,DEBUG); //AT+CMGF=1
  //sendData("AT+CMGD=1\r\n",1000,DEBUG); //AT+CMGD=1

  delay(1000);
  delay(1000);
  delay(1000);
}

void readSerialString (char *strArray) {
  
  if(!Serial1.available()) {
    return;
  }
  
  while(Serial1.available()) {
    strArray[i] = Serial1.read();
    i++;
  }
}

String sendData(String command, const int timeout, boolean debug)
{
    String response = "";
    
    Serial1.print(command); 
    
    long int time = millis();
    
    while( (time+timeout) > millis())
    {
      while(Serial1.available())
      {
        
   
        char c = Serial1.read();
        response+=c;
        Serial.print(response);
      }  
    }
    
    if(debug)
    {
      Serial.print(response);
    }
    
    return response;
}

Here's some code I use to send a simple AT command to the module and reading its reply (all I get is black diamonds with ? inside)

#include <SoftwareSerial.h>

const byte rxPin = 2; // Wire this to Tx Pin of SIM900
const byte txPin = 3; // Wire this to Rx Pin of SIM900

SoftwareSerial SIM800(rxPin, txPin);

void setup() {
  Serial.begin(9600);
  SIM800.begin(9600); 
  delay(1000); // Let the module self-initialize
}

void loop() {
  Serial.println("Sending an AT command...");
  SIM800.println("AT");
  delay(30);
  while (SIM800.available()){
     String inData = SIM800.readStringUntil('\n');
     Serial.println("Got reponse from SIM800: " + inData);
  }  
}

I've tried this code ^^^^^ with various delay rates and I've tried reading it as a char, byte etc with no avail.

My circuit:

Power supply to VBAT and GND.
PWX to GND (This turns it on and gets it connecting to a network)
V_TTL to GND (this gives me SOME communication)
RX and TX to standard RX and TX on other devices (I've tried this on Uno, Mega, ESP8266 in various configurations)
I have a large radio antenna hooked up to GSM_ANT.

I'm a bit lost. I'm thinking it needs even more amperage to format serial information but if it can connect to a network and call me, how much more does it need? Is this a power or a code problem? Perhaps the module is so dirt cheap it's unable to interface with the SIM800C chip properly? Should I just give in, buy a FONA module and be done with it?

If you have any suggestions I'd love to hear them.

Link to what I purchased:

https://www.amazon.co.uk/gp/product/B078LT3JF6/ref=oh_aui_detailpage_o03_s00?ie=UTF8&psc=1

Thanks!

From a mistake I made. Have you connected all the grounds together?

itmoto:
From a mistake I made. Have you connected all the grounds together?

I haven't.....let me try that.

itmoto:
From a mistake I made. Have you connected all the grounds together?

stevenjryall:
I haven't.....let me try that.

Doesn't seem to have made a difference...

As far as I can tell readStringUntil( ) function is not available in SoftwareSerial library .

.

ieee488:
As far as I can tell readStringUntil( ) function is not available in SoftwareSerial library

As I say i've tried reading it as a char, byte etc and doing that means I don't use the readStringUntil() function. I've tried read() when declaring as anything but a String and readString() and readStringUntil() when declaring inData as a String. My code is kind of an example, I've tried every way I can think of reading it with no avail.

You are making it more difficult than it needs to be!

//listen for communication from SIM800 and write to Serial Monitor
if ( SIM800.available() )   
{  
    Serial.write( SIM800.read() );  
}

//listen from communication from Serial Monitor and write it to SIM800
if ( Serial.available() )   
{  
    SIM800.write( Serial.read() );  
}

The lack of ground connection was the cause of my gibberish serial output, at a time I thought my module was faulty then noticed what I had done.
Was sure that was the cause of your problem as your reply sounded like you failed to connected the ground lines on your sim800 and microcontroller.

Try a simple sketch to see if AT commands work as expected.

If that still doesn't work, hopefully others with more experience can help you solve this problem. That was the only thing I could think of.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

...R

Sorry for reviving this old thread. I just wanted to state for the people, like me, that read this post and had the same issues, that I can confirm that the module is working in this setup if you pull V_TTL not to ground but to your logic voltage level. Pulling this to 5V, or to the Arduino VCC worked for me.

Cheers,
Tim

Check the ground connection for the antenna