Zoran Roncevic
Published © GPL3+

LoRa project with RN2483 and Particle Photon

What is LoRa? How to make an simple LoRa project with Particle Photon and MikroElektronika LoRa click module?

IntermediateProtip1 hour9,337
LoRa project with RN2483 and Particle Photon

Things used in this project

Story

Read more

Schematics

Microchip RN2483 User guide

Official User Guide from Microchip about RN2483 LoRa module

Code

LoRa receiver - gateway

Arduino
Code for Particle Photon as LoRa "gateway"
void setup() {
  // put your setup code here, to run once:
  Serial1.begin(57600);
  Serial.begin(9600);
  pinMode(D7,OUTPUT);

delay(2000);
  RN2483_init();
  
}

void loop() {

    sendcmd("radio rx 0");  
    String resp = Serial1.readStringUntil('\n');
    Serial.println(resp);
    if (resp.indexOf("radio_rx") == 0) {
        Particle.publish("lora_msg",resp);
        digitalWrite(D7,HIGH);
        delay(500);
        digitalWrite(D7,LOW);
    }

}

void RN2483_init(){

  sendcmd("sys reset");
  sendcmd("radio set mod lora");
  sendcmd("radio set freq 868100000");
  sendcmd("radio set pwr 14");
  sendcmd("radio set sf sf12");
  sendcmd("radio set afcbw 125");
  sendcmd("radio set rxbw 250");
  sendcmd("radio set fdev 5000");
  sendcmd("radio set prlen 8");
  sendcmd("radio set crc on");
  sendcmd("radio set cr 4/8");
  sendcmd("radio set wdt 0");
  sendcmd("radio set sync 12");
  sendcmd("radio set bw 250");
  sendcmd("sys get hweui");
  sendcmd("mac pause");
    
}

void sendcmd(String data){
  Serial.println(data);
  Serial1.println(data); 
  delay(200);
  Serial.println(Serial1.readStringUntil('\n'));
}

LoRa Sender

Arduino
Flip & Click (Arduino DUE) board with LoRa click module.
String inputString = "";  
boolean stringComplete;

void setup() {
  // put your setup code here, to run once:
  Serial1.begin(57600);
  Serial.begin(9600);
  
  RN2483_init();

}

void loop() {

 for(int i='A'; i<='F';i++){
  String is;
  String temp;
  is = String(strtohex(""));
  is += String(i,HEX);
  is += String(i,HEX);
  is += String(i,HEX);
  is = "radio tx " + is;
  sendmsg(is);
  delay(9999);
 }
}

void RN2483_init(){
  sendcmd("sys reset");
  sendcmd("radio set mod lora");
  sendcmd("radio set freq 868100000");
  sendcmd("radio set pwr 14");
  sendcmd("radio set sf sf12");
  sendcmd("radio set afcbw 125");
  sendcmd("radio set rxbw 250");
  sendcmd("radio set fdev 5000");
  sendcmd("radio set prlen 8");
  sendcmd("radio set crc on");
  sendcmd("radio set cr 4/8");
  sendcmd("radio set wdt 0");
  sendcmd("radio set sync 12");
  sendcmd("radio set bw 250");
  sendcmd("sys get hweui");
  sendcmd("mac pause");
}

void sendcmd(String data){
  Serial.println(data);
  Serial1.println(data); 
  delay(200);
  Serial.println(Serial1.readStringUntil('\n'));
}

void sendmsg(String data){
  Serial.println(data);
  Serial1.println(data); 
  delay(200);
  // radio rx command has two responses, command and transmision
  Serial.println(Serial1.readStringUntil('\n')); // command response
  Serial.println(Serial1.readStringUntil('\n')); // transmision repsonse
}

String strtohex(String data){
  String sh;
  char ch;
  for (int i=0;i<data.length();i++){
    ch = data.charAt(i);
    sh += String(ch,HEX);
  }
  return sh;
}

Credits

Zoran Roncevic

Zoran Roncevic

19 projects • 127 followers
Hackster Live ambassador in Serbia. Organizer of Maker NS community.

Comments