Hey UniquePete,
So three things,
-
I was in fact doing the wrong example “WiFi_LoRa_32FactoryTest” but also did not have the correct example (and still don’t) “WiFi_LoRa_32_V3_FactoryTest”. I believe something went wrong when I did the library download, probably in a folder somewhere that doesn’t show up in examples.
-
I got it to work utilizing RadioLib, so thank you for that advice.
Overall thank you for your help and advice getting it to work.
- For everyone else:
My code for the sender:
#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include <RadioLib.h>
// Pin Definitions for LoRa module
#define LoRa_MOSI 10
#define LoRa_MISO 11
#define LoRa_SCK 9
#define LoRa_nss 8
#define LoRa_dio1 14
#define LoRa_nrst 12
#define LoRa_busy 13
// Create an instance of the LoRa module
SX1262 radio = new Module(LoRa_nss, LoRa_dio1, LoRa_nrst, LoRa_busy);
void setup() {
// Initialize Serial communication
Serial.begin(9600);
// Initialize SPI communication for LoRa module
SPI.begin(LoRa_SCK, LoRa_MISO, LoRa_MOSI, LoRa_nss);
// Initialize LoRa module
Serial.print(F("[SX1262] Initializing ... "));
int state = radio.begin();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// Set the frequency (in Hz)
// Range: 150-960 MhZ 900 MHz frequency
radio.setFrequency(915000000); // 900 MhZ
// Set other configurations as needed
}
void loop() {
// Transmit a message
Serial.print(F("[SX1262] Transmitting packet … "));
// Send the message
int state = radio.transmit("Hello from Transmitter!");
// Check transmission status
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
}
delay(5000); // Wait for 5 seconds before transmitting again
}
My code for the receiver:
#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include <RadioLib.h>
#define LoRa_MOSI 10
#define LoRa_MISO 11
#define LoRa_SCK 9
#define LoRa_nss 8
#define LoRa_dio1 14
#define LoRa_nrst 12
#define LoRa_busy 13
SX1262 radio = new Module(LoRa_nss, LoRa_dio1, LoRa_nrst, LoRa_busy);
void setup() {
Serial.begin(9600);
Serial.println(F(“Serial communication initialized.”));
SPI.begin(LoRa_SCK, LoRa_MISO, LoRa_MOSI, LoRa_nss);
Serial.println(F("SPI communication initialized."));
// Initialize LoRa module
Serial.print(F("[SX1262] Initializing ... "));
int state = radio.begin();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("Initialization successful!"));
} else {
Serial.print(F("Initialization failed, code "));
Serial.println(state);
while (true);
}
// Set the frequency (in Hz)
// Range: 150-960 MhZ 900 MHz frequency
radio.setFrequency(915000000); // 433 MHz
}
void loop() {
// Receive a packet
String str;
int state = radio.receive(str);
if (state == RADIOLIB_ERR_NONE) {
// Packet received successfully
Serial.println(F("Received packet successfully!"));
// Print the RSSI (Received Signal Strength Indicator) of the last received packet
Serial.print(F("[SX1262] RSSI:\t\t"));
Serial.print(radio.getRSSI());
Serial.println(F(" dBm"));
// Print the SNR (Signal-to-Noise Ratio) of the last received packet
Serial.print(F("[SX1262] SNR:\t\t"));
Serial.print(radio.getSNR());
Serial.println(F(" dB"));
// Print the received data
Serial.print(F("[SX1262] Voltage:\t\t"));
Serial.println(str);
//Print the voltage
//Serial.print(F("[SX1262] Voltage:\t\t"));
//Serial.println(str);
} else if (state != RADIOLIB_ERR_RX_TIMEOUT && state != RADIOLIB_ERR_CRC_MISMATCH) {
// Some other error occurred (excluding timeout and CRC mismatch)
Serial.print(F("Failed to receive packet, code "));
Serial.println(state);
}
}