Skip to content

Debug mode

Jan Gromeš edited this page Jun 27, 2020 · 8 revisions

When something isn't working as expected, it might be useful to take a peek "under the hood", to find out what exactly is RadioLib doing, and where it might be failing. For that purpose, there's a couple of debugging options that can be used.

Enabling debug

To enable debug, you can go to the BuildOpt.h file, and uncomment either one or both of these lines:

//#define RADIOLIB_DEBUG
//#define RADIOLIB_VERBOSE

Alternatively, you can define the debug macros in the Arduino sketch - much like custom build configuration, this must be done prior to including the main library header file:

#define RADIOLIB_DEBUG
#define RADIOLIB_VERBOSE

#include <RadioLib.h>

void setup() {
  // etc.
}

The default debug port is set to Serial, on most Arduino boards, this should correspond to the Serial port connected to USB. If you want to use a different port, simply change the value of RADIOLIB_DEBUG_PORT macro to e.g. Serial2, or whichever Serial port you want to use. SoftwareSerial ports are supported as well.

NOTE: RadioLib DOES NOT automatically initialize the debug port with Serial.begin(). This is done to prevent collisions when user already calls the begin() method from Arduino sketch. For that reason, debug interface initialization MUST be done prior to RadioLib module initialization (e.g. lora.begin(), otherwise there will be no debug output from the begin() method.

Debug levels

RADIOLIB_DEBUG

Enabling this macro will only print out basic debug info - for example, when writing to an SPI register fails. This is useful on modules like SX127x or RF69, which use direct SPI register access.

RADIOLIB_VERBOSE

Enabling this macro will print out full transcript of all SPI or UART communication. This is useful on modules like SX126x or UART-based modules, which have command-based interface (instead of SPI register transfers).