Skip to content

Instantly share code, notes, and snippets.

@YokiToki
Last active September 22, 2015 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YokiToki/9d5e730c0c196ebaf3cf to your computer and use it in GitHub Desktop.
Save YokiToki/9d5e730c0c196ebaf3cf to your computer and use it in GitHub Desktop.
SIM900 Arduino Shield AT Serial
#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8);
char incoming_char=0;
String inputString = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete
void setup()
{
Serial.begin(19200); // for serial monitor
inputString.reserve(200);
SIM900.begin(19200); // for GSM shield
}
void loop()
{
serialEvent(); //call the function
// print the string when a newline arrives:
if (stringComplete) {
inputString = inputString + "\r";
SIM900.print(inputString);
// clear the string:
inputString = "";
stringComplete = false;
}
// Now we simply display any text that the GSM shield sends out on the serial monitor
if(SIM900.available() >0)
{
incoming_char=SIM900.read(); //Get the character from the cellular serial port.
Serial.print(incoming_char); //Print the incoming character to the terminal.
}
}
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
if (inChar == '\n') {
stringComplete = true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment