Skip to content

Instantly share code, notes, and snippets.

@tahmmee
Created August 2, 2017 01:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tahmmee/1927e6b21680948657f732db1b75048b to your computer and use it in GitHub Desktop.
Save tahmmee/1927e6b21680948657f732db1b75048b to your computer and use it in GitHub Desktop.
AT commands for gsm shield with audio
#include <SoftwareSerial.h>
#include <string.h>
char incoming_char = 0;
SoftwareSerial cell(2, 3);
const char* commands[]={"ATZ",
"AT",
"AT+CGREG?",
"AT+IFC=1,1",
"AT+CMGF=1",
"AT+CLIP=1",
"ATE0",
"AT+COLP=1",
"AT+QAUDCH=1"};
String readCell()
{
String response = "";
while(cell.available() > 0)
{
incoming_char=cell.read();
if((incoming_char >= ' ') && (incoming_char <= 'z'))
response += incoming_char;
}
return response;
}
void runCommand(const char *cmd){
// send command to modem
cell.print(cmd);
cell.print("\r");
// read response
String rc = readCell();
// debugging
Serial.println(cmd);
Serial.println(rc);
}
void setup()
{
Serial.begin(9600);
cell.begin(9600);
Serial.print("Starting modem communication...");
delay(12000);
for (int i = 0; i < 9; i++){
runCommand(commands[i]);
delay(1500);
}
Serial.print("OK\nWaiting for phone call:\n");
}
void loop()
{
String rc = readCell();
if(rc.startsWith("RING")){
Serial.println("Answering...");
delay(1000);
cell.print("ATA\r");
}
// allow AT commands to be read over serial port
if(Serial.available() > 0)
{
incoming_char = Serial.read();
Serial.print(incoming_char);
cell.print(incoming_char);
}
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment