Kesara MalindaChathura Yapa Bandara
Published

Getting Started with LoRa NODE RN2483A

How to use RN2483 LoRa module for Long Range Communication (15Km) and LoRaWAN with ChirpStack/The Things Network(TTN)

IntermediateWork in progress3 hours697
Getting Started with LoRa NODE RN2483A

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Aptinex LoRaNODE RN2483A
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Module Connection to MCU

Code

Arduino_RN2483_Transmitter.ino

C/C++
#include <SoftwareSerial.h>

// Define the SoftwareSerial pins
const int rxPin = 10;  // RX pin to Arduino (connect to TX of RN2483)
const int txPin = 11;  // TX pin from Arduino (connect to RX of RN2483)

// Create a SoftwareSerial object
SoftwareSerial loraSerial(rxPin, txPin);

// Function to send a command to RN2483 and print the response to Serial Monitor
void loraSendCommand(String command) {

  while (loraSerial.available()) {
    loraSerial.read();
  }

  // Send the command to the RN2483 module
  loraSerial.println(command);

  // Wait for a response
  String response = "";
  unsigned long timeout = millis() + 5000;  // 5 seconds timeout

  while (millis() < timeout) {
    if (loraSerial.available()) {
      char c = loraSerial.read();
      response += c;
      // Check if response ends with "\r\n"
      if (response.endsWith("\r\n")) {
        break;
      }
    }
  }

  // Print the response to the Serial Monitor
  Serial.println("Response: " + response);
}

void setup() {

  Serial.begin(9600);

  // Initialize software serial for RN2483 communication
  loraSerial.begin(57600);  // Default baud rate of the RN2483 is 57600

  Serial.println("LoRa RN2483 Communication Setup");

  //  initialization commands to configure the RN2483
  loraSendCommand("sys reset");
  delay(100);

  loraSendCommand("radio set wdt 0");
  delay(1000);

  loraSendCommand("mac pause");
  delay(1000);

  loraSendCommand("radio set sync FF");
  delay(1000);
}

void loop() {
  // Send the message "FFFFFFFF"
  String messageToSend = "FFFFFFFF";
  Serial.println("Sending Hex Message: " + messageToSend);

  // Send the hex string
  loraSendCommand("radio tx " + messageToSend);

  // Wait for a while before sending the next packet
  delay(20000);  // Send data every 10 seconds
}

Arduino_RN2483_Reciever.ino

C/C++
#include <SoftwareSerial.h>

// Define the SoftwareSerial pins
const int rxPin = 10; // RX pin to Arduino (connect to TX of RN2483)
const int txPin = 11; // TX pin from Arduino (connect to RX of RN2483)

// Create a SoftwareSerial object
SoftwareSerial loraSerial(rxPin, txPin);

// Function to send a command to RN2483 and print the response to Serial Monitor
void loraSendCommand(String command) {
  // Clear any previous data in the buffer
  while (loraSerial.available()) {
    loraSerial.read();
  }

  // Send the command to the RN2483 module
  loraSerial.println(command);

  // Wait for a response
  String response = "";
  unsigned long timeout = millis() + 5000; // 5 seconds timeout

  while (millis() < timeout) {
    if (loraSerial.available()) {
      char c = loraSerial.read();
      response += c;
      // Check if response ends with "\r\n"
      if (response.endsWith("\r\n")) {
        break;
      }
    }
  }

  // Print the response to the Serial Monitor
  Serial.println("Response: " + response);
}

void setup() {
  // Initialize hardware serial for debugging
  Serial.begin(9600);
  
  // Initialize software serial for RN2483 communication
  loraSerial.begin(57600); // Default baud rate of the RN2483 is 57600
  
  Serial.println("LoRa RN2483 Communication Setup");

  // Initialization commands to configure the RN2483
  loraSendCommand("sys reset");
  delay(100);

  loraSendCommand("radio set wdt 0");
  delay(1000);

  loraSendCommand("mac pause");
  delay(1000);

  loraSendCommand("radio set sync FF");
  delay(1000);

  // Set the RN2483 module to receive mode
  loraSendCommand("radio rx 0"); // Continuous receive mode
}

void loop() {
  // Check for incoming messages
  if (loraSerial.available()) {
    String message = "";
    while (loraSerial.available()) {
      char c = loraSerial.read();
      message += c;
      // Check if message ends with "\r\n"
      if (message.endsWith("\r\n")) {
        break;
      }
    }

 

    // Extract the message part from the response
    if (message.startsWith("radio_rx")) {
      int startIndex = message.indexOf(" ") + 1; // Find the space after "radio_rx"
      String extractedMessage = message.substring(startIndex);
      Serial.println("Extracted Message: " + extractedMessage);
    }

    // Set the RN2483 module back to receive mode after receiving a message
    loraSendCommand("radio rx 0");
  }
}

Credits

Kesara Malinda
3 projects • 1 follower
Contact
Chathura Yapa Bandara
19 projects • 5 followers
Contact

Comments

Please log in or sign up to comment.