Created
August 2, 2017 01:30
-
-
Save tahmmee/1927e6b21680948657f732db1b75048b to your computer and use it in GitHub Desktop.
AT commands for gsm shield with audio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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