LoRa, a wireless modulation method, is based on Chirp Spread Spectrum (CSS) technology. It transmits data by encoding it in radio waves through chirp pulses, similar to the way dolphins and bats communicate. This LoRa technology can be used to transmit bi-directional information to long-distance without consuming much power.
LoRaWANLoRaWAN is a point-to-multipoint networking protocol that uses Semtechโs LoRa modulation scheme. It is a Media Access Control (MAC) layer protocol built on top of LoRa modulation.
The ๐๐ผ๐ฅ๐ฎ๐ช๐๐ก Protocol inherently does not facilitate communication between two LoRa modules, but there is technique called the ๐ฅ๐ฎ๐ฑ๐ถ๐ผ๐๐ฒ๐ฎ๐ฑ Packet Method which does follow the ๐๐ผ๐ฅ๐ฎ๐ช๐๐ก protocol but allows us to communicate with two LoRa modules.
๐ฅ๐ฎ๐ฑ๐ถ๐ผ๐๐ฒ๐ฎ๐ฑ is a ๐ฃ๐ฎ๐ฐ๐ธ๐ฒ๐ ๐ฅ๐ฎ๐ฑ๐ถ๐ผ ๐น๐ถ๐ฏ๐ฟ๐ฎ๐ฟ๐ ๐ณ๐ผ๐ฟ ๐ฒ๐บ๐ฏ๐ฒ๐ฑ๐ฑ๐ฒ๐ฑ ๐บ๐ถ๐ฐ๐ฟ๐ผ๐ฝ๐ฟ๐ผ๐ฐ๐ฒ๐๐๐ผ๐ฟ๐. It provides a complete object-oriented library for sending and receiving packetized messages
LoRa SX1278 ModuleThe LoRa module that I am using here is the SX1278 Ra-02 which operates on 433MHz.
The circuit diagram for Arduino LoRa SX1278 Transmitter is given below. The LoRa SX1278 is not 5V friendly so do not supply 5V to it else the board will get damaged. Use 3.3V of Arduino to connect it to VCC pin.
The circuit diagram for Arduino LoRa SX1278 Receiver is given below. An OLED Display is connected additionally to read the received values.
After completing the hardware setup, the next step involves working with the Arduino IDE. When using Arduino to interface with the LoRa module, there is a comprehensive LoRa library developed by Sandeep Mistry that is readily available for use.
To add the library, open you Arduino IDE and follow Sketch -> Include Library -> Manage Libraries
#include <SPI.h>
#include <LoRa.h>
int counter = 0;
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("LoRa Sender");
if (!LoRa.begin(433E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
LoRa.setTxPower(20);
}
void loop() {
Serial.print("Sending packet: ");
Serial.println(counter);
// send packet
LoRa.beginPacket();
LoRa.print("hello ");
LoRa.print(counter);
LoRa.endPacket();
counter++;
delay(5000);
}
Receiver Code#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <SPI.h>
#include <LoRa.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
String inString = ""; //hold incoming characters
String myMessage = ""; // hold compleye message
int led = 3;
void setup() {
Serial.begin(9600);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
delay(2000);
display.clearDisplay();
display.display();
while (!Serial);
Serial.println("LoRa Receiver");
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(20, 30);
// Display static text
display.println("LoRa Receiver");
display.display();
if (!LoRa.begin(433E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
pinMode(led, OUTPUT);
}
void loop() {
String message = "";
// try to parse packet
int packetSize = LoRa.parsePacket();
if (packetSize) {
Serial.print("Received packet '");
digitalWrite(led, HIGH);
delay(1000);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 10);
// Display static text
display.println("Received packet - ");
display.display();
Serial.println(packetSize);
// read packet
while (LoRa.available()) {
// Serial.print((char)LoRa.read());
message += (char)LoRa.read();
}
// display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(20, 30);
// Display static text
display.println(message);
display.display();
Serial.print(message);
// print RSSI of packet
Serial.print("' with RSSI ");
Serial.println(LoRa.packetRssi());
digitalWrite(led, LOW);
}
}
Comments