LogoLogo
Terminal
  • Attic Lab
  • Getting Started
  • Crest Gold
  • Crest Silver
  • Videos on Computation
  • PI PICO (CIRCUITPYTHON)
    • Getting Started
    • Pin Out Diagram
    • Breadboards
    • 1. Led Blink
    • 2. RGB
    • 3. OLED
    • 4. Sensors
    • 5. Wifi
    • 6. Servos
  • Arduino
    • Getting Started
    • Pin Out Diagrams
      • Mega2560 R3
    • Programming
      • Arduino C - Cheat Sheet
    • Buttons
      • Momentary Switches
    • Display
      • LEDs
      • 7 Segment Displays
      • LCD Displays (GPIO)
      • LCD Displays (SPI)
      • OLEDs
    • Communication
      • Antenna Theory
      • Lora
      • Wifi
        • Boards
    • Project Ideas
    • Motion
      • DC Motors
      • Servo Motors
      • Stepper Motors
  • Microsoft Office
    • Word
    • Powerpoint
    • Excel
  • The Terminal
    • Basics
    • Cheat Sheet
    • Games
      • Level 1 - Bashcrawl
      • Level 2 - Bandit
  • TinkerCad
    • Gallery
    • Getting Started
    • Basic Operations
    • Basic Skills
    • Projects
      • Locking Container
  • Python
    • Hello World
    • Turtle Graphics
      • Strings in Turtle Graphics
      • Cheat Sheet
    • Variables
    • Loops
    • If Statements
    • Functions
    • Games
      • Pong
  • Raspberry Pi
    • Setup
      • Changing The Hostname
      • Headless Setup
      • Kiosk Mode
    • Remote Connections
    • Displays
      • Memory
        • External HD
      • HyperPixel 4.0
  • Ultimaker 3D Printing
    • The Thingiverse
    • Preparing the File
    • Printing
    • Calibration Prints
    • Print Set
  • Fusion 360
    • Getting Started
    • Design Tutorials
      • Tweezers
      • Mars Rover Wheel
    • Surface Modeling
  • Electronics
    • References
    • Antenna Theory
    • LoRa
  • PCB Milling
    • FlatCam
    • Candle
    • PCB Milling
  • Projects
  • Projects
    • Star Map Necklace
    • Ideas Respository
  • Latex
    • What is LaTeX?
    • Getting Started
    • Structure
    • Page Size & Margins
    • Styling
    • Images
    • Lists
    • Tables
    • Mathematics
      • Superscript and Subscripts
      • List of Symbols
      • Fractions and Binomials
      • Integrals, Sums & Limits
    • Colors
  • Web Development
    • The Internet
    • Intro to HTML
    • Basic Elements
    • Basic Styling
Powered by GitBook
On this page
  • Setup
  • Sending Code
  • Receiving Code
  • Library
  • RSSI
  • Further Reading

Was this helpful?

  1. Arduino
  2. Communication

Lora

PreviousAntenna TheoryNextWifi

Last updated 4 years ago

Was this helpful?

Setup

Sending Code

#include <SPI.h>
#include <LoRa.h>

int counter = 0;
int LED = 12;

void setup() {
  Serial.begin(9600);
  pinMode(LED, OUTPUT);
  pinMode(LED_BUILTIN, OUTPUT);
//   while (!Serial);

  Serial.println("LoRa Sender");

  LoRa.setTxPower(20);
  if (!LoRa.begin(433E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
  
  LoRa.setTxPower(20);
  LoRa.setSpreadingFactor(12);
  LoRa.setSignalBandwidth(62.5E3);
  LoRa.setCodingRate4(8);
  
}

void loop() { 
    // Serial.print("Sending packet: ");
  digitalWrite(LED, HIGH);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);
  Serial.print("Sending packet: ");
  Serial.println(counter);
  
  // send packet
  LoRa.beginPacket();
  LoRa.print("Hi Jemima! ");
  LoRa.print(counter);
  LoRa.endPacket();

  counter++;
  digitalWrite(LED, LOW);

  delay(2000);
}

Receiving Code

#include <Wire.h>
#include "rgb_lcd.h"

#include <SPI.h>
#include <LoRa.h>

int counter = 0;

rgb_lcd lcd;

const int colorR = 255;
const int colorG = 20;
const int colorB = 147;

void setup() {
    
    // set up the LCD's number of columns and rows:
    lcd.begin(16, 2);

    lcd.setRGB(colorR, colorG, colorB);
    // lcd.display();
    // Print a message to the LCD.

    Serial.begin(9600);
    while (!Serial);

    Serial.println("LoRa Sender");

    if (!LoRa.begin(433E6)) {
        Serial.println("Starting LoRa failed!");
        while (1);
    }

    lcd.print("LoRa Initialised");
    Serial.println("LoRa Initialised");
    LoRa.setTxPower(20);
    LoRa.setSpreadingFactor(12);
    LoRa.setSignalBandwidth(62.5E3);
    LoRa.setCodingRate4(8);

    delay(1000);
}

void loop() {
    // set the cursor to column 0, line 1
    // (note: line 1 is the second row, since counting begins with 0):
    
    // try to parse packet
  int packetSize = LoRa.parsePacket();
  if (packetSize) {
    // received a packet
    Serial.print("Received packet '");
    lcd.setCursor(0, 0);
    lcd.print("Received packet ");

    // read packet
    
    int count = 0;
    while (LoRa.available()) {
      lcd.setCursor(count, 0);
      count++;
      // do not print to serial and lcd at same time as once read a character is removed from the stream
      // Serial.print((char)LoRa.read());  
      lcd.print((char)LoRa.read());
    }
    lcd.setCursor(0, 1);
    lcd.print(LoRa.packetRssi());
    // print RSSI of packet
    Serial.print("' with RSSI ");
    Serial.println(LoRa.packetRssi());
    delay(2000);

  } else {
    lcd.setCursor(0, 1);
    lcd.print("           "); 
    lcd.setCursor(0, 0);
    lcd.print("Listening...      ");
  }
}

Library

RSSI

Typical LoRa values:

  • RSSI Min = -120 bBm

  • -30dBm = strong signal

  • -120dBm = weak signal

Further Reading

https://www.arduino.cc/en/reference/SPI
2MB
Long Distance Tracking and Monitoring with LoRa - Introduction - April 2016.pdf
pdf
GitHub - nRF24/RF24: OSI Layer 2 driver for nRF24L01 on Arduino & Raspberry Pi/Linux DevicesGitHub
Introducing LoRaâ„¢ !Instructables
https://paradisetronic.com/en/add-on-boards/433mhz-sx1276-lora-breakout-board-antennaparadisetronic.com
What are the best settings for a LoRa radioArduino Forum
GitHub - sandeepmistry/arduino-LoRa: An Arduino library for sending and receiving data using LoRa radios.GitHub
The Best LoRa Settings for Range and ReliabilityMedium
Logo
Logo
Logo
Logo
Logo