04-18-2023, 04:59 AM
Hello everyone ! especially to Hificat... I am developing a project where we are using Lora SX1278 in the KC868-A6 module, according to the characteristics of the Lora the device has a range of 1 km - 5 km, the code used by the sender is the following :
And the code for the receiver is the following
I have soldered the antenna on the correct pin and have done some tests, the communication works fine up to 3 meters, but when I move the modules further than 3 meters the communication fails ... maybe you could help me a little, we require a range of more than 200 meters... can you help me and tell me if I'm making a mistake in programming or installing the hardware? Or if I need to buy another Lora module maybe...?
Code:
#include "Arduino.h"
#include "PCF8574.h"
#include <RTClib.h>
#include <Wire.h>
#include <LoRa.h>
#include <SPI.h>
#include <WiFi.h>
#define ss 5
#define rst 21
#define dio0 2
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
while (!Serial);
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!");
Dwin_hmi.begin(115200);
LoRa.setPins(ss, rst, dio0);
pcf8574.pinMode(P0, OUTPUT);
pcf8574.pinMode(P1, OUTPUT);
pcf8574.pinMode(P2, OUTPUT);
pcf8574.pinMode(P3, OUTPUT);
pcf8574.pinMode(P4, OUTPUT);
pcf8574.pinMode(P5, OUTPUT);
Serial.print("Init pcf8574...");
if (pcf8574.begin()){
Serial.println("OK");
}else{
Serial.println("NO");
}
pcf8574.digitalWrite(P0, HIGH);
pcf8574.digitalWrite(P1, HIGH);
pcf8574.digitalWrite(P2, HIGH);
pcf8574.digitalWrite(P3, HIGH);
pcf8574.digitalWrite(P4, HIGH);
pcf8574.digitalWrite(P5, HIGH);
}
void loop() {
LoRa.beginPacket(); //Send LoRa packet to receiver
LoRa.print("LP01");
LoRa.endPacket();
Serial.println("Sending packet LP0: 1 ");
}
And the code for the receiver is the following
Code:
#include "Arduino.h"
#include "PCF8574.h"
#include <RTClib.h>
#include <Wire.h>
#include <LoRa.h>
#include <SPI.h>
#include <MCP23017.h>
#define ss 5
#define rst 14
#define dio0 21
void setup() {
Serial.begin(115200);
Serial1.begin(9600,SERIAL_8N1,13,12);
while (!Serial);
Serial.println("LoRa Receiver");
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() {
//Serial1.write(0x01);
//delay(20);
//Serial1.flush();
//delay(15);
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);
if (LoRaData == "LP01") {
pcf8574.digitalWrite(P0, HIGH);
}
if (LoRaData == "LP00") {
pcf8574.digitalWrite(P0, LOW);
}
}
Serial.print("' with RSSI "); // print RSSI of packet
Serial.println(LoRa.packetRssi());
}
}
I have soldered the antenna on the correct pin and have done some tests, the communication works fine up to 3 meters, but when I move the modules further than 3 meters the communication fails ... maybe you could help me a little, we require a range of more than 200 meters... can you help me and tell me if I'm making a mistake in programming or installing the hardware? Or if I need to buy another Lora module maybe...?