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!