Advertisement
Guest User

Arduino SIM808 test

a guest
Jul 12th, 2019
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.68 KB | None | 0 0
  1. #define TINY_GSM_MODEM_SIM808
  2.  
  3. // Set serial for debug console (to the Serial Monitor, speed 115200)
  4. #define SerialMon Serial
  5.  
  6. // Set serial for AT commands (to the module)
  7. // Software Serial on Uno, Nano
  8. #include <SoftwareSerial.h>
  9. SoftwareSerial SerialAT(6, 7); // RX, TX
  10.  
  11. #define TINY_GSM_DEBUG SerialMon
  12.  
  13. #include <TinyGsmClient.h>
  14.  
  15. // Module baud rate
  16. uint32_t rate = 9600; // Set to 0 for Auto-Detect
  17.  
  18. void setup() {
  19.   // Set console baud rate
  20.   SerialMon.begin(115200);
  21.   delay(3000);
  22. }
  23.  
  24. void loop() {
  25.  
  26.   if (!rate) {
  27.     rate = TinyGsmAutoBaud(SerialAT);
  28.   }
  29.  
  30.   if (!rate) {
  31.     SerialMon.println(F("***********************************************************"));
  32.     SerialMon.println(F(" Module does not respond!"));
  33.     SerialMon.println(F("   Check your Serial wiring"));
  34.     SerialMon.println(F("   Check the module is correctly powered and turned on"));
  35.     SerialMon.println(F("***********************************************************"));
  36.     delay(30000L);
  37.     return;
  38.   }
  39.  
  40.   SerialAT.begin(rate);
  41.  
  42.   // Access AT commands from Serial Monitor
  43.   SerialMon.println(F("***********************************************************"));
  44.   SerialMon.println(F(" You can now send AT commands"));
  45.   SerialMon.println(F(" Enter \"AT\" (without quotes), and you should see \"OK\""));
  46.   SerialMon.println(F(" If it doesn't work, select \"Both NL & CR\" in Serial Monitor"));
  47.   SerialMon.println(F("***********************************************************"));
  48.  
  49.   while(true) {
  50.     if (SerialAT.available()) {
  51.       SerialMon.write(SerialAT.read());
  52.     }
  53.     if (SerialMon.available()) {
  54.       SerialAT.write(SerialMon.read());
  55.     }
  56.     delay(0);
  57.   }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement