Loras not talking to each other? #423
paulrose71
started this conversation in
General
Replies: 2 comments 1 reply
-
I suggest you try with the default examples first (Sender and Receiver/ReceiverCallback). Very less likely due to the library. |
Beta Was this translation helpful? Give feedback.
1 reply
-
No, nothing at all. Ill buy new hardware tomorrow. Thanks again Sandeep. Appreciated. Paul |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi Sandeep,
My Loras aren't talking to one another? I have two Arduino UNO's and two duinotech lora shields. They just plug on top of each other. My code is just the basic comms code. I think all my code is fine. I reckon I must have damaged my hardware? This is the only explanation I can think of? Thanks alot.
Paul
Tx......
#include <SPI.h>
#include <LoRa.h>
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
const byte ROWS = 4;
const byte COLS = 3;
int counter = 0;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("LoRa Sender Unit");
LoRa.setSPIFrequency(8E6); //Sandeep: Override the default SPI frequency of 10 MHz used by the library. Default is 8E6. Else 4E6 or 1E6. Must be called before LoRa.begin(). This call is optional and only needs to be used if you need to change the default SPI frequency used. Some logic level converters cannot support high speeds such as 8 MHz, so a lower SPI frequency can be selected
//LoRa.begin(915E6); //Sandeep: Returns 1 on success, 0 on failure. Can put an if/while in here for debugging.
if (!LoRa.begin(915E6)) { //Sandeep: Returns 1 on success, 0 on failure. Can put an if/while in here for debugging.
Serial.println("Starting LoRa failed!");
while (1);
}
LoRa.setSyncWord(0xF3); //set a unique communication key (Syncword). Default is 0x34
LoRa.setTxPower(17); //set the power of the Lora radio to the maximum. 20-2. Default is 17.
LoRa.onReceive(onReceive); //Sandeep: Register a callback function for when a packet is received.
LoRa.receive(); //Sandeep: Puts the radio in continuous receive mode.
//lcd.backlight(); //lcd not working! Think I blew it up!!!
//lcd.init();
}
void loop() { //sketch only fails when a 3,2, or 1 is pressed. It'll print the 3, then it won't print anything else.????
Serial.print("Sending packet: ");
Serial.println(counter);
LoRa.beginPacket();
LoRa.print("hello ");
LoRa.print(counter);
LoRa.endPacket();
counter++;
delay(1000);
char customKey = customKeypad.getKey();
if (customKey){
Serial.println(customKey);
//lcd.clear(); //lcd not working! Think I blew it up!!!
//lcd.setCursor(0, 0);
//lcd.print(customKey);
LoRa.beginPacket();
LoRa.print(customKey);
LoRa.endPacket();
LoRa.receive();
}
}
void onReceive(int packetSize) { //Sandeep: this function is called when a packet it received.
char buf[20]="";
int k;
int n;
for (int i = 0; i < packetSize; i++) {
k=i;
if(k>18){k=18;} //make sure we don't write past end of string
buf[k]=(char)LoRa.read();
}
Serial.println(buf[0]);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(buf[0]);
}
Rx.....
#include <SPI.h>
#include <LoRa.h>
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("LoRa Receiver Unit");
LoRa.setSPIFrequency(8E6); //Sandeep: Override the default SPI frequency of 10 MHz used by the library. Default is 8E6. Else 4E6 or 1E6. Must be called before LoRa.begin(). This call is optional and only needs to be used if you need to change the default SPI frequency used. Some logic level converters cannot support high speeds such as 8 MHz, so a lower SPI frequency can be selected
if (!LoRa.begin(915E6)) { //Sandeep: Returns 1 on success, 0 on failure. Can put an if/while in here for debugging.
Serial.println("Starting LoRa failed!");
while (1);
}
LoRa.setSyncWord(0xF3); //set a unique communication key (Syncword).
LoRa.setTxPower(17); //set the power of the Lora radio to the maximum. 20-2. Default is 17.
LoRa.receive(); //Sandeep: Puts the radio in continuous receive mode.
}
void loop() {
int packetSize = LoRa.parsePacket(); //Sandeep: Check if a packet has been received. Returns the packet size in bytes or 0 if no packet was received.
if (packetSize) { //if the packet size is greater than 0, then...
Serial.print("Received packet '"); //print on the serial monitor.
while (LoRa.available()) { //Sandeep: Returns number of bytes available for reading. Soo, while there are some bytes to read....
Serial.print((char)LoRa.read()); //Sandeep: Read the next byte from the packet. Returns the next byte in the packet or -1 if no bytes are available.
}
Serial.print("' with RSSI ");
Serial.println(LoRa.packetRssi());
Serial.println(LoRa.packetFrequencyError()); //Sandeep: Returns the frequency error of the received packet in Hz. The frequency error is the frequency offset between the receiver centre frequency and that of an incoming LoRa signal.
}
}
Beta Was this translation helpful? Give feedback.
All reactions