RAK13302 as the Transmitter
Set Up RAK13302 as the Transmitter with the RAK3401
- If using the RAK3401, you need to select RAK4631 as your WisBlock Core.
Figure 1: Select RAK3401 as WisBlock CoreNOTE
The RAK3401 is not listed as separate board in the BSP. Choose RAK13302 to compile code for the RAK3401 since it is compatible with the RAK4631.
- Next, copy the following sample code into your Arduino IDE:
Click to view the sample code.
/**
* @file LoRaP2P_TX.ino
* @author rakwireless.com
* @brief Transmitter node for LoRa point to point communication
* @version 0.1
* @date 2026-01-27
*
* @copyright Copyright (c) 2026
*
*/
#include <Arduino.h>
#include <SX126x-Arduino.h> //http://librarymanager/All#SX126x
#include <SPI.h>
// Function declarations
void OnTxDone(void);
void OnTxTimeout(void);
// Define LoRa parameters
#define RF_FREQUENCY 868300000 // Hz
#define TX_OUTPUT_POWER 22 // dBm
#define LORA_BANDWIDTH 0 // [0: 125 kHz, 1: 250 kHz, 2: 500 kHz, 3: Reserved]
#define LORA_SPREADING_FACTOR 7 // [SF7..SF12]
#define LORA_CODINGRATE 1 // [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8]
#define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx
#define LORA_SYMBOL_TIMEOUT 0 // Symbols
#define LORA_FIX_LENGTH_PAYLOAD_ON false
#define LORA_IQ_INVERSION_ON false
#define RX_TIMEOUT_VALUE 3000
#define TX_TIMEOUT_VALUE 3000
static RadioEvents_t RadioEvents;
static uint8_t TxdBuffer[64];
void setup()
{
pinMode(WB_IO2, OUTPUT);
digitalWrite(WB_IO2, HIGH);
// Initialize Serial for debug output
time_t timeout = millis();
Serial.begin(115200);
while (!Serial)
{
if ((millis() - timeout) < 5000)
{
delay(100);
}
else
{
break;
}
}
Serial.println("=====================================");
Serial.println("LoRap2p Tx Test");
Serial.println("=====================================");
// Initialize the Radio callbacks
RadioEvents.TxDone = OnTxDone;
RadioEvents.RxDone = NULL;
RadioEvents.TxTimeout = OnTxTimeout;
RadioEvents.RxTimeout = NULL;
RadioEvents.RxError = NULL;
RadioEvents.CadDone = NULL;
// Initialize LoRa chip.
lora_rak3400_init();
// Initialize the Radio
Radio.Init(&RadioEvents);
// Set Radio channel
Radio.SetChannel(RF_FREQUENCY);
// Set Radio TX configuration
Radio.SetTxConfig(MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,
LORA_SPREADING_FACTOR, LORA_CODINGRATE,
LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
true, 0, 0, LORA_IQ_INVERSION_ON, TX_TIMEOUT_VALUE);
send();
}
void loop()
{
// Put your application tasks here, like reading of sensors,
// Controlling actuators and/or other functions.
}
/**@brief Function to be executed on Radio Tx Done event
*/
void OnTxDone(void)
{
Serial.println("OnTxDone");
delay(5000);
send();
}
/**@brief Function to be executed on Radio Tx Timeout event
*/
void OnTxTimeout(void)
{
Serial.println("OnTxTimeout");
}
void send()
{
TxdBuffer[0] = 'H';
TxdBuffer[1] = 'e';
TxdBuffer[2] = 'l';
TxdBuffer[3] = 'l';
TxdBuffer[4] = 'o';
Radio.Send(TxdBuffer, 5);
}
- You can now select the right serial port and upload the code.
Figure 1: Select the correct Serial Port
Figure 1: Upload the RAK13302 example codeNOTE
If you experience any error in compiling the example sketch, make sure that you have the latest version of the SX126x-Arduino library installed. The RAK13302 is supported by library versions V2.0.32 or newer.
- When you have successfully uploaded the example sketch, open the Serial Monitor of the Arduino IDE to see the transmission logs.
Figure 1: Transmission logs in Serial Monitor