Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Arduino demo source code for LoRa "Receiver"
#1
Code:
#include <LoRa.h>
#include <SPI.h>


#include <Wire.h>
#include <Bonezegei_SSD1306.h>
Bonezegei_SSD1306 oled(128, 64);

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

#include "Arduino.h"


#define ANALOG_A1   4
#define ANALOG_A2   6
#define ANALOG_A3   5
#define ANALOG_A4   7

const int Relay1 = 48;

const int K1 = 47;
const int K2 = 21;
const int K3 = 14;
const int K4 = 13;
const int K5 = 12;
const int K6 = 11;
const int K7 = 10;
const int K8 = 9;

const int IO0 = 0;  //GPIO0
const int DI1 = 16;  //DI
const int DI2 = 15;  //1-wire


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
  Wire.begin(39, 38);

  oled.begin();
  oled.clear();
//  oled.drawText(1, 0, "Arial8", oled.Font_Arial8);
  oled.drawText(1, 0, "KinCony", oled.Font_Arial14);
//  oled.drawText(1, 24, "Arial12", oled.Font_Arial12);
//  oled.drawText(1, 40, "Arial14", oled.Font_Arial14);
  oled.draw();  //update the screen
 
  Serial.begin(115200);
  Serial.println("begin");
  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!");
 
  pinMode(Relay1,OUTPUT);
 
  pinMode(K1,INPUT);
  pinMode(K2,INPUT);
  pinMode(K3,INPUT);
  pinMode(K4,INPUT);
  pinMode(K5,INPUT);
  pinMode(K6,INPUT);
  pinMode(K7,INPUT);
  pinMode(K8,INPUT);
 
  pinMode(DI1,INPUT);
  pinMode(DI2,INPUT);
  pinMode(IO0,INPUT);

  pinMode(ANALOG_A1,INPUT);
  pinMode(ANALOG_A2,INPUT);
  pinMode(ANALOG_A3,INPUT);
  pinMode(ANALOG_A4,INPUT);
  digitalWrite(Relay1, HIGH);
 


}

void loop()
{
uint8_t valk1 = digitalRead(K1);
uint8_t valk2 = digitalRead(K2);
uint8_t valk3 = digitalRead(K3);
uint8_t valk4 = digitalRead(K4);
uint8_t valk5 = digitalRead(K5);
uint8_t valk6 = digitalRead(K6);
uint8_t valk7 = digitalRead(K7);
uint8_t valk8 = digitalRead(K8);

uint8_t valdi1 = digitalRead(DI1);
uint8_t valdi2 = digitalRead(DI2);
uint8_t valIO0 = digitalRead(IO0);

   
if (valdi1==LOW) digitalWrite(Relay1, HIGH); else digitalWrite(Relay1, LOW);
if (digitalRead(DI2)==LOW)Serial.println("input2 down");
if (digitalRead(IO0)==LOW)Serial.println("DL Button down");

if (digitalRead(K1)==LOW)Serial.println("K1 down");
if (digitalRead(K2)==LOW)Serial.println("K2 down");
if (digitalRead(K3)==LOW)Serial.println("K3 down");
if (digitalRead(K4)==LOW)Serial.println("K4 down");
if (digitalRead(K5)==LOW)Serial.println("K5 down");
if (digitalRead(K6)==LOW)Serial.println("K6 down");
if (digitalRead(K7)==LOW)Serial.println("K7 down");
if (digitalRead(K8)==LOW)Serial.println("K8 down");


//-------------------------------------
  if (analogRead(ANALOG_A1)>0) Serial.printf("Current Reading A1 on Pin(%d)=%d\n",ANALOG_A1,analogRead(ANALOG_A1));
  if (analogRead(ANALOG_A2)>0) Serial.printf("Current Reading A2 on Pin(%d)=%d\n",ANALOG_A2,analogRead(ANALOG_A2));
  if (analogRead(ANALOG_A3)>0) Serial.printf("Current Reading A3 on Pin(%d)=%d\n",ANALOG_A3,analogRead(ANALOG_A3));
  if (analogRead(ANALOG_A4)>0) Serial.printf("Current Reading A4 on Pin(%d)=%d\n",ANALOG_A4,analogRead(ANALOG_A4));

//---------------------------------------
  int packetSize = LoRa.parsePacket();    // try to parse packet
  if (packetSize)
  {
   
    Serial.print("Received packet '");

    while (LoRa.available())              // read packet
    {
      String LoRaData = LoRa.readString();
      Serial.print(LoRaData);

      oled.begin();
      oled.clear();
      oled.drawText(1, 0, LoRaData.c_str(), oled.Font_Arial14);
      String temp=String(LoRa.packetRssi());
      oled.drawText(1, 40, temp.c_str(), oled.Font_Arial14);
      oled.draw();  //update the screen
     
    }
    Serial.print("' with RSSI ");         // print RSSI of packet
    Serial.println(LoRa.packetRssi());
  }



}

before use this code, need to install LoRa SX1278 arduino library firstly.
   
Reply


Messages In This Thread
Arduino demo source code for LoRa "Receiver" - by admin - 07-21-2024, 05:11 AM

Forum Jump:


Users browsing this thread:
1 Guest(s)