Skip to content

tool_at_debug

Sara Damiano edited this page Sep 11, 2026 · 1 revision

title: AT Debug

AT Debug

This sketch tries to auto-detect the baud rate and provides direct access to AT commands.


The Complete Code

/** ============================================================================
 * @example{lineno} AT_Debug.ino
 *
 * @brief This script tries to auto-detect the baud rate and provides direct
 * access to AT commands.
 *
 * @warning The quality of the passthrough connection created by this sketch is
 * limited by the baud rate and the speed of the Arduino.  If possible, you
 * should connect your modem directly to your computer and use a terminal
 * program to send AT commands.
 * ========================================================================== */

// Select your modem:
// #define TINY_GSM_MODEM_SIM800
// #define TINY_GSM_MODEM_SIM808
// #define TINY_GSM_MODEM_SIM868
// #define TINY_GSM_MODEM_SIM900
// #define TINY_GSM_MODEM_SIM7000
// #define TINY_GSM_MODEM_SIM7000SSL
// #define TINY_GSM_MODEM_SIM7080
// #define TINY_GSM_MODEM_SIM5360
// #define TINY_GSM_MODEM_SIM7600
// #define TINY_GSM_MODEM_A7672X
// #define TINY_GSM_MODEM_UBLOX
// #define TINY_GSM_MODEM_SARAR4
// #define TINY_GSM_MODEM_SARAR5
// #define TINY_GSM_MODEM_M95
// #define TINY_GSM_MODEM_BG95
// #define TINY_GSM_MODEM_BG96
// #define TINY_GSM_MODEM_A6
// #define TINY_GSM_MODEM_A7
// #define TINY_GSM_MODEM_M590
// #define TINY_GSM_MODEM_MC60
// #define TINY_GSM_MODEM_MC60E
// #define TINY_GSM_MODEM_ESP8266
// #define TINY_GSM_MODEM_ESP32
// #define TINY_GSM_MODEM_XBEE
// #define TINY_GSM_MODEM_SEQUANS_MONARCH

// Set serial for debug console (to the Serial Monitor)
#define SerialMon Serial

// Set serial for AT commands (to the module)
// Use Hardware Serial on Mega, Leonardo, Micro
#if !defined(__AVR_ATmega328P__) && !defined(SerialAT)
#define SerialAT Serial1

// or Software Serial on Uno, Nano
#elif !defined(SerialAT)
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(2, 3);  // RX, TX
#endif

#include <TinyGsmClient.h>

#if (defined(ARDUINO_NRF52840_FEATHER)) && !defined(ADAFRUIT_TINYUSB_H_)
#include <Adafruit_TinyUSB.h>  // for Serial
#endif

// Module baud rate
uint32_t rate = 0;  // Set to 0 for Auto-Detect

void setup() {
  // Set console baud rate
  SerialMon.begin(115200);
  delay(6000);
}

void loop() {
  if (!rate) { rate = TinyGsmAutoBaud(SerialAT); }

  if (!rate) {
    SerialMon.println(
        F("***********************************************************"));
    SerialMon.println(F(" Module does not respond!"));
    SerialMon.println(F("   Check your Serial wiring"));
    SerialMon.println(
        F("   Check the module is correctly powered and turned on"));
    SerialMon.println(
        F("***********************************************************"));
    delay(30000L);
    return;
  }

  SerialAT.begin(rate);

  // Access AT commands from Serial Monitor
  SerialMon.println(
      F("***********************************************************"));
  SerialMon.println(F(" You can now send AT commands"));
  SerialMon.println(
      F(" Enter \"AT\" (without quotes), and you should see \"OK\""));
  SerialMon.println(
      F(" If it doesn't work, select \"Both NL & CR\" in Serial Monitor"));
  SerialMon.println(
      F("***********************************************************"));

  while (true) {
    if (SerialAT.available()) { SerialMon.write(SerialAT.read()); }
    if (SerialMon.available()) { SerialAT.write(SerialMon.read()); }
    delay(0);
  }
}

Generated by Doxygen and m.css with templates from doxybook2 Updated on 2026-09-11

Clone this wiki locally