Created
January 10, 2016 17:28
-
-
Save bittailor/3301175cacad32da154c to your computer and use it in GitHub Desktop.
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 <Arduino.h> | |
#include <SoftwareSerial.h> | |
#include <SPI.h> | |
#include <Adafruit_GFX.h> | |
#include <Adafruit_PCD8544.h> | |
SoftwareSerial gprsSerial(7, 8); | |
Adafruit_PCD8544 display = Adafruit_PCD8544(3, 4, 5); | |
String readAnswer() { | |
while (!gprsSerial.available()) {} | |
return gprsSerial.readStringUntil('\n'); | |
} | |
int counter = 0; | |
void setup() { | |
Serial.println("GPSR Monitor"); | |
pinMode(9, OUTPUT); | |
digitalWrite(9, HIGH); | |
Serial.begin(115200); | |
gprsSerial.begin(9600); | |
display.begin(); | |
display.setContrast(50); | |
display.display(); | |
delay(2000); | |
digitalWrite(9, LOW); | |
display.clearDisplay(); | |
display.display(); | |
display.display(); | |
bool ok = false; | |
while (!ok) { | |
counter++; | |
counter %= 10; | |
display.clearDisplay(); | |
display.setCursor(0, 0); | |
display.print("Wait SIM "); display.println(counter); | |
display.display(); | |
gprsSerial.print("AT\r"); | |
while (gprsSerial.available()) { | |
String answer = readAnswer(); | |
ok = !answer.equals(""); | |
} | |
display.display(); | |
delay(500); | |
} | |
while (gprsSerial.available()) | |
{ | |
readAnswer(); | |
} | |
display.clearDisplay(); | |
display.display(); | |
display.println("Set Pin"); | |
display.display(); | |
gprsSerial.print("AT+CPIN=1210\r"); | |
display.println(readAnswer()); | |
while (gprsSerial.available()) { | |
readAnswer(); | |
} | |
display.display(); | |
} | |
void loop() { | |
counter++; | |
counter %= 10; | |
display.clearDisplay(); | |
display.setCursor(0, 0); | |
display.print("Signal "); | |
display.println(counter); | |
gprsSerial.print("AT+CSQ\r"); | |
display.println(readAnswer()); | |
display.println(readAnswer()); | |
display.println(readAnswer()); | |
while (gprsSerial.available()) { | |
readAnswer(); | |
} | |
display.display(); | |
delay(2000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment