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.

80 lines
2.2 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
6 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. // Set serial for debug console (to the Serial Monitor, speed 115200)
  20. #define SerialMon Serial
  21. // Set serial for AT commands (to the module)
  22. // Use Hardware Serial on Mega, Leonardo, Micro
  23. #define SerialAT Serial1
  24. // or Software Serial on Uno, Nano
  25. //#include <SoftwareSerial.h>
  26. //SoftwareSerial SerialAT(2, 3); // RX, TX
  27. #define TINY_GSM_DEBUG SerialMon
  28. #include <TinyGsmClient.h>
  29. // Module baud rate
  30. uint32_t rate = 0; // Set to 0 for Auto-Detect
  31. void setup() {
  32. // Set console baud rate
  33. SerialMon.begin(115200);
  34. delay(3000);
  35. }
  36. void loop() {
  37. if (!rate) {
  38. rate = TinyGsmAutoBaud(SerialAT);
  39. }
  40. if (!rate) {
  41. SerialMon.println(F("***********************************************************"));
  42. SerialMon.println(F(" Module does not respond!"));
  43. SerialMon.println(F(" Check your Serial wiring"));
  44. SerialMon.println(F(" Check the module is correctly powered and turned on"));
  45. SerialMon.println(F("***********************************************************"));
  46. delay(30000L);
  47. return;
  48. }
  49. SerialAT.begin(rate);
  50. // Access AT commands from Serial Monitor
  51. SerialMon.println(F("***********************************************************"));
  52. SerialMon.println(F(" You can now send AT commands"));
  53. SerialMon.println(F(" Enter \"AT\" (without quotes), and you should see \"OK\""));
  54. SerialMon.println(F(" If it doesn't work, select \"Both NL & CR\" in Serial Monitor"));
  55. SerialMon.println(F("***********************************************************"));
  56. while(true) {
  57. if (SerialAT.available()) {
  58. SerialMon.write(SerialAT.read());
  59. }
  60. if (SerialMon.available()) {
  61. SerialAT.write(SerialMon.read());
  62. }
  63. delay(0);
  64. }
  65. }