After scouring the internet for information i found several suggestions as to what the pins are through the b2b connector but still not getting anywhere, updated sketch below and some information links I’ve gathered:
This one i suspect should be most reliable:
#include <SPI.h>
#include <RadioLib.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// ✅ Updated Pin Configuration (B2B Connector)
#define LORA_NSS 41 // ✅ SPI Chip Select (GPIO41)
#define LORA_SCK 7 // ✅ SPI Clock (GPIO7)
#define LORA_MOSI 9 // ✅ SPI MOSI (GPIO9)
#define LORA_MISO 8 // ✅ SPI MISO (GPIO8)
#define LORA_RST 42 // ✅ LoRa Reset (GPIO42)
#define LORA_BUSY 40 // ✅ LoRa BUSY (GPIO40)
#define LORA_DIO1 39 // ✅ LoRa IRQ (DIO1 - GPIO39)
#define LORA_ANT_SW 38 // ✅ Antenna Switch (GPIO38)
// ✅ Temperature Sensor Configuration
#define ONE_WIRE_PIN 2 // DS18B20 data pin
OneWire oneWire(ONE_WIRE_PIN);
DallasTemperature sensors(&oneWire);
// ✅ Battery Voltage Monitoring
#define BATTERY_PIN 4 // ADC pin for battery voltage
// ✅ LoRa Configuration
#define LORA_FREQUENCY 868E6
#define LORA_SPREADING_FACTOR 12
#define LORA_BANDWIDTH 125E3
#define LORA_CODING_RATE 5
#define LORA_TX_POWER 22
// ✅ Ensure Device Starts the Transmission
#define INITIATING_NODE
// ✅ LoRa Module Instance
Module mod(LORA_NSS, LORA_DIO1, LORA_RST, LORA_BUSY);
SX1262 radio(&mod);
void setup() {
Serial.begin(115200);
while (!Serial);
Serial.println("[SX1262] LoRa Initialization - Correct B2B Pins");
// ✅ Initialize SPI Bus with Correct Pins
Serial.println("[SPI] Initializing...");
SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_NSS);
Serial.println("[SPI] Initialized!");
// ✅ Reset SX1262
Serial.println("[SX1262] Resetting module...");
pinMode(LORA_RST, OUTPUT);
digitalWrite(LORA_RST, LOW);
delay(10);
digitalWrite(LORA_RST, HIGH);
delay(10);
Serial.println("[SX1262] Reset Complete!");
// ✅ Initialize Temperature Sensor
Serial.println("[TEMP] Initializing DS18B20...");
sensors.begin();
// ✅ Initialize LoRa
Serial.println("[SX1262] Initializing LoRa...");
SPI.beginTransaction(SPISettings(500000, MSBFIRST, SPI_MODE0)); // Reduce SPI Speed
int state = radio.begin(LORA_FREQUENCY, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, LORA_CODING_RATE,
0x12, LORA_TX_POWER, 8, 1.6, false);
SPI.endTransaction();
Serial.print("LoRa Init Status: ");
Serial.println(state);
if (state == RADIOLIB_ERR_NONE) {
Serial.println("✅ [SUCCESS] LoRa initialized successfully!");
} else {
Serial.println("❌ [ERROR] LoRa initialization failed!");
Serial.print("🔎 [ERROR CODE] ");
Serial.println(state);
while (true) { // Prevent further execution if LoRa fails
delay(100);
}
}
#ifdef INITIATING_NODE
sendLoRaData();
#else
radio.startReceive();
#endif
}
void loop() {
delay(15000);
Serial.println("[SX1262] Sending new LoRa data...");
sendLoRaData();
}
// ✅ Read Temperature from DS18B20
float readTemperature() {
Serial.println("[TEMP] Reading temperature...");
sensors.requestTemperatures();
float temp = sensors.getTempCByIndex(0);
Serial.print("[TEMP] Temperature: ");
Serial.print(temp);
Serial.println(" °C");
return temp;
}
// ✅ Read Battery Voltage using 220KΩ / 100KΩ Voltage Divider (16-sample averaging)
int readBatteryVoltage() {
long sum = 0;
for (int i = 0; i < 16; i++) {
sum += analogReadMilliVolts(BATTERY_PIN);
delay(5);
}
float measuredMilliVolts = sum / 16.0;
int batteryMilliVolts = measuredMilliVolts * 3.2; // Voltage divider correction
Serial.print("[BATTERY] Voltage: ");
Serial.print(batteryMilliVolts);
Serial.println(" mV");
return batteryMilliVolts;
}
// ✅ Convert Battery Voltage to Percentage
int getBatteryPercentage(int batteryMilliVolts) {
int fullCharge = 4200; // Fully charged at 4.2V
int emptyCharge = 3200; // Minimum voltage before shutdown at 3.2V
int batteryPercentage = ((batteryMilliVolts - emptyCharge) * 100) / (fullCharge - emptyCharge);
return constrain(batteryPercentage, 0, 100);
}
// ✅ Read RSSI (Signal Strength)
int readRSSI() {
return radio.getRSSI();
}
// ✅ Send Data Over LoRa
void sendLoRaData() {
float temperature = readTemperature();
int batteryMilliVolts = readBatteryVoltage();
int batteryPercentage = getBatteryPercentage(batteryMilliVolts);
int rssi = readRSSI();
// ✅ Construct JSON message
char message[128];
snprintf(message, sizeof(message),
"{\"hostname\":\"ESP32S3\", \"temp\":%.2f, \"batt\":%d, \"rssi\":%d}",
temperature, batteryPercentage, rssi);
Serial.print("[SX1262] Sending packet: ");
Serial.println(message);
int transmissionState = radio.startTransmit(message);
if (transmissionState == RADIOLIB_ERR_NONE) {
Serial.println("✅ [SUCCESS] Transmission Complete!");
} else {
Serial.print("❌ [ERROR] Transmission Failed, Code: ");
Serial.println(transmissionState);
}
}
Current Result:
15:04:25.649 -> [SX1262] LoRa Initialization - Correct B2B Pins
15:04:25.649 -> [SPI] Initializing...
15:04:25.649 -> [SPI] Initialized!
15:04:25.649 -> [SX1262] Resetting module...
15:04:25.753 -> [SX1262] Reset Complete!
15:04:25.753 -> [TEMP] Initializing DS18B20...
15:04:25.772 -> [SX1262] Initializing LoRa...
Sits like that indefinitely, away to do something else and come back to it with a clear head.