Thanks for the comments. Tried out several pins, had a seeed ranger helped out. Managed to create transmit and receiving code, both Lora initialised. One was transmitting, but the receiver did not receive the message. No idea what went wrong, but here are the codes for the transmit.
#include <Arduino.h>
#include <SX126x-Arduino.h>
#include <SPI.h>
// Pin Definitions (based on Seeed Studio Wiki)
const int LORA_RESET_PIN = 12; // RESET
const int LORA_DIO1_PIN = 14; // DIO1
const int LORA_BUSY_PIN = 13; // BUSY
const int LORA_NSS_PIN = 15; // NSS / CS
const int LORA_SCLK_PIN = 6; // SCK
const int LORA_MISO_PIN = 8; // MISO
const int LORA_MOSI_PIN = 7; // MOSI
// LoRa Settings
#define RF_FREQUENCY 868E6 // Asia Frequency
#define TX_OUTPUT_POWER 22 // dBm
// Buffers
#define BUFFER_SIZE 64
static uint8_t TxdBuffer[BUFFER_SIZE];
// LoRa Radio Events
static RadioEvents_t RadioEvents;
hw_config hwConfig;
// Function Declarations
void OnTxDone(void);
void OnTxTimeout(void);
// LoRa Initialization
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("Initializing LoRa Transmitter...");
// Configure LoRa Hardware
hwConfig.CHIP_TYPE = SX1262_CHIP;
hwConfig.PIN_LORA_RESET = LORA_RESET_PIN;
hwConfig.PIN_LORA_NSS = LORA_NSS_PIN;
hwConfig.PIN_LORA_SCLK = LORA_SCLK_PIN;
hwConfig.PIN_LORA_MISO = LORA_MISO_PIN;
hwConfig.PIN_LORA_MOSI = LORA_MOSI_PIN;
hwConfig.PIN_LORA_DIO_1 = LORA_DIO1_PIN;
hwConfig.PIN_LORA_BUSY = LORA_BUSY_PIN;
// Initialize LoRa Hardware
lora_hardware_init(hwConfig);
// Setup Radio Event Callbacks
RadioEvents.TxDone = OnTxDone;
RadioEvents.TxTimeout = OnTxTimeout;
// Initialize the Radio
Radio.Init(&RadioEvents);
Radio.SetChannel(RF_FREQUENCY);
// Configure TX Settings
Radio.SetTxConfig(MODEM_LORA, TX_OUTPUT_POWER, 0, 0, 7, 1, 8, false, true, 0, 0, false, 3000);
Serial.println("LoRa Transmitter Initialized.");
}
void loop() {
// Prepare and Send Data
const char* message = "Hello LoRa!";
memset(TxdBuffer, 0, BUFFER_SIZE);
strncpy((char*)TxdBuffer, message, BUFFER_SIZE);
Serial.printf("Sending Message: %s\n", message);
Radio.Send(TxdBuffer, strlen(message));
// Wait before sending the next message
delay(3000); // Adjust this value as needed
}
// Event Callbacks
void OnTxDone(void) {
Serial.println("Transmission Complete.");
}
void OnTxTimeout(void) {
Serial.println("Transmission Timeout.");
}
and here is the receiving code
#include <Arduino.h>
#include <SX126x-Arduino.h>
#include <SPI.h>
// Pin Definitions
const int LORA_RESET_PIN = 12; // RESET
const int LORA_DIO1_PIN = 14; // DIO1
const int LORA_BUSY_PIN = 13; // BUSY
const int LORA_NSS_PIN = 15; // NSS / CS
const int LORA_SCLK_PIN = 6; // SCK
const int LORA_MISO_PIN = 8; // MISO
const int LORA_MOSI_PIN = 7; // MOSI
// LoRa Settings
#define RF_FREQUENCY 868E6 // Asia Frequency
#define RX_TIMEOUT_VALUE 3000
// Buffers
#define BUFFER_SIZE 64
static uint8_t RcvBuffer[BUFFER_SIZE];
static uint16_t BufferSize = BUFFER_SIZE;
// LoRa Radio Events
static RadioEvents_t RadioEvents;
hw_config hwConfig;
// Function Declarations
void OnRxDone(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr);
void OnRxTimeout(void);
void OnRxError(void);
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("Initializing LoRa Receiver...");
// Configure LoRa Hardware
hwConfig.CHIP_TYPE = SX1262_CHIP;
hwConfig.PIN_LORA_RESET = LORA_RESET_PIN;
hwConfig.PIN_LORA_NSS = LORA_NSS_PIN;
hwConfig.PIN_LORA_SCLK = LORA_SCLK_PIN;
hwConfig.PIN_LORA_MISO = LORA_MISO_PIN;
hwConfig.PIN_LORA_MOSI = LORA_MOSI_PIN;
hwConfig.PIN_LORA_DIO_1 = LORA_DIO1_PIN;
hwConfig.PIN_LORA_BUSY = LORA_BUSY_PIN;
// Initialize LoRa Hardware
lora_hardware_init(hwConfig);
// Setup Radio Event Callbacks
RadioEvents.RxDone = OnRxDone;
RadioEvents.RxTimeout = OnRxTimeout;
RadioEvents.RxError = OnRxError;
// Initialize the Radio
Radio.Init(&RadioEvents);
Radio.SetChannel(RF_FREQUENCY);
// Configure RX Settings
Radio.SetRxConfig(MODEM_LORA, 0, 7, 1, 0, 8, 0, false, 0, true, 0, 0, false, true);
Serial.println("LoRa Receiver Initialized. Listening...");
Radio.Rx(0);
}
void loop() {
Radio.IrqProcess();
}
// Event Callbacks
void OnRxDone(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr) {
BufferSize = size;
memcpy(RcvBuffer, payload, BufferSize);
Serial.printf("Received Message: %.*s\n", size, payload);
Serial.printf("RSSI: %d dBm | SNR: %d\n", rssi, snr);
// Resume Listening
Radio.Rx(0);
}
void OnRxTimeout(void) {
Serial.println("Receive Timeout.");
Radio.Rx(0);
}
void OnRxError(void) {
Serial.println("Receive Error.");
Radio.Rx(0);
}