Skip to content

Debug mode

Jan Gromeš edited this page Mar 10, 2024 · 6 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 BuildOptUser.h file, and uncomment any of these lines:

//#define RADIOLIB_DEBUG_BASIC        (1)   // basic debugging (e.g. reporting GPIO timeouts or module not being found)
//#define RADIOLIB_DEBUG_PROTOCOL     (1)   // protocol information (e.g. LoRaWAN internal information)
//#define RADIOLIB_DEBUG_SPI          (1)   // verbose transcription of all SPI communication - produces large debug logs!

Any combination of debug levels may be enabled, information from different levels are distinguished by a prefix.

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. radio.begin(), otherwise there will be no debug output from the begin() method.

On non-Arduino platforms, RADIOLIB_DEBUG_PORT defaults to stdout.

Debug levels

RADIOLIB_DEBUG_BASIC ("RLB_DBG")

Enabling this macro will only print out basic debug info - for example, timeouts when waiting for GPIO signals or radio module not being found due to version register mismatch.

RADIOLIB_DEBUG_PROTOCOL ("RLB_PRO")

Enabling this macro will print information important for debugging protocols. This is very useful when debugging LoRaWAN.

RADIOLIB_DEBUG_SPI ("RLB_SPI")

Enabling this macro will print out full transcript of all SPI communication. It should be noted that this outputs A LOT of information in the debug log. This can make debugging higher levels (e.g. protocols) cumbersome, so it should only be used when investigating issues with the radio module itself.