You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.3 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
7 years ago
  1. /**************************************************************
  2. *
  3. * This script tries to auto-detect the baud rate
  4. * and allows direct AT commands access
  5. *
  6. * TinyGSM Getting Started guide:
  7. * http://tiny.cc/tiny-gsm-readme
  8. *
  9. **************************************************************/
  10. // Select your modem:
  11. #define TINY_GSM_MODEM_SIM800
  12. // #define TINY_GSM_MODEM_SIM808
  13. // #define TINY_GSM_MODEM_SIM900
  14. // #define TINY_GSM_MODEM_A6
  15. // #define TINY_GSM_MODEM_A7
  16. // #define TINY_GSM_MODEM_M590
  17. // #define TINY_GSM_MODEM_ESP8266
  18. // #define TINY_GSM_MODEM_XBEE
  19. #include <TinyGsmClient.h>
  20. // Set serial for debug console (to the Serial Monitor, speed 115200)
  21. #define SerialMon Serial
  22. // Set serial for AT commands (to the module)
  23. // Use Hardware Serial on Mega, Leonardo, Micro
  24. #define SerialAT Serial1
  25. // or Software Serial on Uno, Nano
  26. //#include <SoftwareSerial.h>
  27. //SoftwareSerial SerialAT(2, 3); // RX, TX
  28. #define TINY_GSM_DEBUG SerialMon
  29. #include <TinyGsmClient.h>
  30. // Module baud rate
  31. uint32_t rate = 0; // Set to 0 for Auto-Detect
  32. void setup() {
  33. // Set console baud rate
  34. SerialMon.begin(115200);
  35. delay(5000);
  36. }
  37. void loop() {
  38. if (!rate) {
  39. rate = TinyGsmAutoBaud(SerialAT);
  40. }
  41. if (!rate) {
  42. SerialMon.println(F("***********************************************************"));
  43. SerialMon.println(F(" Module does not respond!"));
  44. SerialMon.println(F(" Check your Serial wiring"));
  45. SerialMon.println(F(" Check the module is correctly powered and turned on"));
  46. SerialMon.println(F("***********************************************************"));
  47. delay(30000L);
  48. return;
  49. }
  50. SerialAT.begin(rate);
  51. // Access AT commands from Serial Monitor
  52. SerialMon.println(F("***********************************************************"));
  53. SerialMon.println(F(" You can now send AT commands"));
  54. SerialMon.println(F(" Enter \"AT\" (without quotes), and you should see \"OK\""));
  55. SerialMon.println(F(" If it doesn't work, select \"Both NL & CR\" in Serial Monitor"));
  56. SerialMon.println(F("***********************************************************"));
  57. while(true) {
  58. if (SerialAT.available()) {
  59. SerialMon.write(SerialAT.read());
  60. }
  61. if (SerialMon.available()) {
  62. SerialAT.write(SerialMon.read());
  63. }
  64. delay(0);
  65. }
  66. }