Last active
September 22, 2015 20:12
-
-
Save YokiToki/9d5e730c0c196ebaf3cf to your computer and use it in GitHub Desktop.
SIM900 Arduino Shield AT Serial
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> | |
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