RAK13300 as Receiver
Setting up RAK13300 as Receiver
- You need to select RAK11200 as your WisBlock Core.
Figure 1: Selecting RAK11200 as WisBlock Core- Next, copy the following sample code into your Arduino IDE:
Click to view the sample code.
/**
* @file LoRaP2P_RX.ino
* @author rakwireless.com
* @brief Receiver node for LoRa point to point communication
* @version 0.1
* @date 2021-08-21
*
* @copyright Copyright (c) 2020
*
*/
#include <Arduino.h>
#include <SX126x-Arduino.h> //http://librarymanager/All#SX126x
#include <SPI.h>
// Function declarations
void OnRxDone(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr);
void OnRxTimeout(void);
void OnRxError(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 RcvBuffer[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 Rx Test");
Serial.println("=====================================");
// Initialize the Radio callbacks
RadioEvents.TxDone = NULL;
RadioEvents.RxDone = OnRxDone;
RadioEvents.TxTimeout = NULL;
RadioEvents.RxTimeout = OnRxTimeout;
RadioEvents.RxError = OnRxError;
RadioEvents.CadDone = NULL;
// Initialize LoRa chip.
lora_rak13300_init();
// Initialize the Radio
Radio.Init(&RadioEvents);
// Set Radio channel
Radio.SetChannel(RF_FREQUENCY);
// Set Radio RX configuration
Radio.SetRxConfig(MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR,
LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH,
LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON,
0, true, 0, 0, LORA_IQ_INVERSION_ON, true);
// Start LoRa
Serial.println("Starting Radio.Rx");
Radio.Rx(RX_TIMEOUT_VALUE);
}
void loop()
{
// Put your application tasks here, like reading of sensors,
// Controlling actuators and/or other functions.
}
/**@brief Function to be executed on Radio Rx Done event
*/
void OnRxDone(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr)
{
Serial.println("OnRxDone");
delay(10);
memcpy(RcvBuffer, payload, size);
Serial.printf("RssiValue=%d dBm, SnrValue=%d\n", rssi, snr);
for (int idx = 0; idx < size; idx++)
{
Serial.printf("%02X ", RcvBuffer[idx]);
}
Serial.println("");
Radio.Rx(RX_TIMEOUT_VALUE);
}
/**@brief Function to be executed on Radio Rx Timeout event
*/
void OnRxTimeout(void)
{
Serial.println("OnRxTimeout");
Radio.Rx(RX_TIMEOUT_VALUE);
}
/**@brief Function to be executed on Radio Rx Error event
*/
void OnRxError(void)
{
Serial.println("OnRxError");
Radio.Rx(RX_TIMEOUT_VALUE);
}
- You can now select the right serial port and upload the code.
Since you are using RAK11200 as WisBlock Core, you need to configure the BOOT0 pin before uploading. You need to short it to the ground then press the reset button of the WisBlock Base before releasing the BOOT0 pin. If not done properly, uploading the source code to RAK11200 will fail. Check the full details on the RAK11200 Quick Start Guide.
Figure 1: Selecting the correct Serial Port
Figure 1: Uploading the RAK13300 example codeIf you experience any error in compiling the example sketch, check the updated code for the RAK13300 WisBlock LPWAN Wireless Module that can be found on the RAK13300 WisBlock Example Code Repository
- When you successfully uploaded the example sketch, open the Serial Monitor of the Arduino IDE to see the initial logs. You may not see any logs yet if you have not set the transmitter up or you do not have any existing transmitting device.
Setting up the Dummy Transmitter
In this example, you will be using RAK11310 as the WisBlock Core and RAK19003 as the WisBlock Base for the dummy transmitter.
- You need to select RAK11310 as your WisBlock Core.
Figure 1: Selecting RAK11300 as WisBlock Core- Open the example code for LoRaP2P Transmitter.
Figure 1: Opening the example code- Select the correct port and upload.
Figure 1: Selecting the correct serial port
Figure 1: Uploading the code- When you have successfully uploaded the example sketch, open the Serial Monitor of the Arduino IDE to see the initial logs.
Figure 1: Transmission logs in Serial MonitorOnTxDone respond means that your transmitter is now ready.
Testing the Receive and Transmit Transaction
- To check if the communication is successful, you can power the transmitting node via battery or power brick to avoid confusion in the serial port.
Figure 1: Receiving and Transmitting Node Setup- Connect the receiving node to your PC and open the serial monitor. You will see the message is received.
Figure 1: Payload logs received in Serial Monitor