Smart Home Automation Forum
Arduino demo source code for LoRa "SENDER" - Printable Version

+- Smart Home Automation Forum (https://www.kincony.com/forum)
+-- Forum: Technical Support (https://www.kincony.com/forum/forumdisplay.php?fid=20)
+--- Forum: KinCony ALR (https://www.kincony.com/forum/forumdisplay.php?fid=59)
+--- Thread: Arduino demo source code for LoRa "SENDER" (/showthread.php?tid=6165)



Arduino demo source code for LoRa "SENDER" - admin - 07-21-2024

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.