Smart Home Automation Forum

Full Version: Arduino demo source code for LoRa "SENDER"
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Code:
#include <LoRa.h>
#include <SPI.h>

#define ss 41
#define rst 2
#define dio0 40

int counter = 0;

void setup()
{
  SPI.begin(42, 43, 44, 41);  //SPI.begin(PIN_SPI_SCK, PIN_SPI_MISO, PIN_SPI_MOSI, -1);   last one is SS not used, use -1
  Serial.begin(115200);
  Serial.println("LoRa Sender");

  LoRa.setPins(ss, rst, dio0);    //setup LoRa transceiver module
 
  while (!LoRa.begin(433E6))     //433E6 - Asia, 866E6 - Europe, 915E6 - North America
  {
    Serial.println(".");
    delay(500);
  }
  LoRa.setSyncWord(0xA5);
  Serial.println("LoRa Initializing OK!");
}

void loop()
{
  Serial.print("Sending packet: ");
  Serial.println(counter);

  LoRa.beginPacket();   //Send LoRa packet to receiver
  LoRa.print("KinCony LoRa");
  LoRa.print(counter);
  LoRa.endPacket();

  counter++;

  delay(2000);
}
before use this code, need to install LoRa SX1278 arduino library firstly.
[attachment=5664]