From 067d1dc67b36feca34ca709ece819b830c189d15 Mon Sep 17 00:00:00 2001 From: richonguzman Date: Tue, 2 Jan 2024 22:41:54 -0300 Subject: [PATCH] esp32 1W LoRa added --- src/battery_utils.cpp | 2 +- src/lora_utils.cpp | 24 ++++++++++++++++-------- src/pins_config.h | 17 +++++++++++++++-- src/utils.cpp | 16 ++++++++-------- 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/battery_utils.cpp b/src/battery_utils.cpp index 2b4f780..1b843e7 100644 --- a/src/battery_utils.cpp +++ b/src/battery_utils.cpp @@ -22,7 +22,7 @@ namespace BATTERY_Utils { #if defined(TTGO_T_LORA_V2_1) || defined(HELTEC_V2) sample = analogRead(batteryPin); #endif - #ifdef HELTEC_V3 + #if defined(HELTEC_V3) || defined(ESP32_DIY_LoRa) || defined(ESP32_DIY_1W_LoRa) sample = 0; #endif sampleSum += sample; diff --git a/src/lora_utils.cpp b/src/lora_utils.cpp index 7198ef9..beacb69 100644 --- a/src/lora_utils.cpp +++ b/src/lora_utils.cpp @@ -15,6 +15,11 @@ SX1262 radio = new Module(RADIO_CS_PIN, RADIO_DIO1_PIN, RADIO_RST_PIN, RADIO_BUS bool transmissionFlag = true; bool enableInterrupt = true; #endif +#ifdef ESP32_DIY_1W_LoRa +SX1268 radio = new Module(RADIO_CS_PIN, RADIO_DIO1_PIN, RADIO_RST_PIN, RADIO_BUSY_PIN); +bool transmissionFlag = true; +bool enableInterrupt = true; +#endif int rssi, freqError; float snr; @@ -22,7 +27,7 @@ float snr; namespace LoRa_Utils { void setFlag(void) { - #ifdef HELTEC_V3 + #if defined(HELTEC_V3) || defined(ESP32_DIY_1W_LoRa) transmissionFlag = true; #endif } @@ -51,12 +56,11 @@ namespace LoRa_Utils { LoRa.setTxPower(Config.loramodule.power); Serial.print("init : LoRa Module ... done!"); #endif - #ifdef HELTEC_V3 + #if defined(HELTEC_V3) || defined(ESP32_DIY_1W_LoRa) SPI.begin(RADIO_SCLK_PIN, RADIO_MISO_PIN, RADIO_MOSI_PIN); float freq = (float)Config.loramodule.iGateFreq/1000000; int state = radio.begin(freq); if (state == RADIOLIB_ERR_NONE) { - Serial.print("Initializing SX126X LoRa Module"); } else { Serial.println("Starting LoRa failed!"); @@ -66,8 +70,12 @@ namespace LoRa_Utils { radio.setSpreadingFactor(Config.loramodule.spreadingFactor); radio.setBandwidth(Config.loramodule.signalBandwidth); radio.setCodingRate(Config.loramodule.codingRate4); + #ifdef HELTEC_V3 state = radio.setOutputPower(Config.loramodule.power + 2); // values available: 10, 17, 22 --> if 20 in tracker_conf.json it will be updated to 22. - + #endif + #ifdef ESP32_DIY_1W_LoRa_GPS + state = radio.setOutputPower(Config.loramodule.power); // max value 20 (when 20dB in setup 30dB in output as 400M30S has Low Noise Amp) + #endif if (state == RADIOLIB_ERR_NONE) { Serial.println("init : LoRa Module ... done!"); } else { @@ -91,7 +99,7 @@ namespace LoRa_Utils { LoRa.write((const uint8_t *)newPacket.c_str(), newPacket.length()); LoRa.endPacket(); #endif - #ifdef HELTEC_V3 + #if defined(HELTEC_V3) || defined(ESP32_DIY_1W_LoRa) int state = radio.transmit("\x3c\xff\x01" + newPacket); if (state == RADIOLIB_ERR_NONE) { //Serial.println(F("success!")); @@ -132,7 +140,7 @@ namespace LoRa_Utils { freqError = LoRa.packetFrequencyError(); } #endif - #ifdef HELTEC_V3 + #if defined(HELTEC_V3) || defined(ESP32_DIY_1W_LoRa) if (transmissionFlag) { transmissionFlag = false; radio.startReceive(); @@ -166,7 +174,7 @@ namespace LoRa_Utils { #if defined(TTGO_T_LORA_V2_1) || defined(HELTEC_V2) || defined(ESP32_DIY_LoRa) LoRa.setFrequency(Config.loramodule.digirepeaterTxFreq); #endif - #ifdef HELTEC_V3 + #if defined(HELTEC_V3) || defined(ESP32_DIY_1W_LoRa) float freq = (float)Config.loramodule.digirepeaterTxFreq/1000000; radio.setFrequency(freq); #endif @@ -177,7 +185,7 @@ namespace LoRa_Utils { #if defined(TTGO_T_LORA_V2_1) || defined(HELTEC_V2) || defined(ESP32_DIY_LoRa) LoRa.setFrequency(Config.loramodule.digirepeaterRxFreq); #endif - #ifdef HELTEC_V3 + #if defined(HELTEC_V3) || defined(ESP32_DIY_1W_LoRa) float freq = (float)Config.loramodule.digirepeaterRxFreq/1000000; radio.setFrequency(freq); #endif diff --git a/src/pins_config.h b/src/pins_config.h index d37d048..05c6a41 100644 --- a/src/pins_config.h +++ b/src/pins_config.h @@ -28,8 +28,21 @@ #define RADIO_BUSY_PIN 13 // SX1262 BUSY #endif +#ifdef ESP32_DIY_1W_LoRa // Ebyte E22 400M30S +#define RADIO_SCLK_PIN 18 +#define RADIO_MISO_PIN 19 +#define RADIO_MOSI_PIN 23 +#define RADIO_CS_PIN 5 +#define RADIO_RST_PIN 27 +#define RADIO_DIO1_PIN 12 +#define RADIO_BUSY_PIN 14 +#define RADIO_RXEN 32 +#define RADIO_TXEN 25 +#endif + + // OLED -#if defined(TTGO_T_LORA_V2_1) || defined(ESP32_DIY_LoRa) +#if defined(TTGO_T_LORA_V2_1) || defined(ESP32_DIY_LoRa) || defined(ESP32_DIY_1W_LoRa) #define OLED_SDA 21 #define OLED_SCL 22 #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) @@ -55,7 +68,7 @@ #ifdef HELTEC_V3 #define internalLedPin 35 #endif -#ifdef ESP32_DIY_LoRa +#if defined(ESP32_DIY_LoRa) || defined(ESP32_DIY_1W_LoRa) #define internalLedPin 2 #endif diff --git a/src/utils.cpp b/src/utils.cpp index 121112a..a2bfc6d 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -113,7 +113,7 @@ namespace Utils { } else { beaconPacket = iGateBeaconPacket; } - #ifndef HELTEC_V3 + #if defined(TTGO_T_LORA_V2_1) || defined(HELTEC_V2) if (Config.sendBatteryVoltage) { beaconPacket += " (Batt=" + String(BATTERY_Utils::checkBattery(),2) + "V)"; } @@ -127,8 +127,8 @@ namespace Utils { fifthLine = ""; } sixthLine = ""; - show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, "SENDING iGate BEACON", 1000); - #ifndef HELTEC_V3 + show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, "SENDING iGate BEACON", 1000); + #if defined(TTGO_T_LORA_V2_1) || defined(HELTEC_V2) if (Config.sendBatteryVoltage) { sixthLine = " (Batt=" + String(BATTERY_Utils::checkBattery(),2) + "V)"; } @@ -152,7 +152,7 @@ namespace Utils { fifthLine = ""; sixthLine = ""; show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, "SENDING iGate BEACON", 0); - #ifndef HELTEC_V3 + #if defined(TTGO_T_LORA_V2_1) || defined(HELTEC_V2) if (Config.sendBatteryVoltage) { sixthLine = " (Batt=" + String(BATTERY_Utils::checkBattery(),2) + "V)"; } @@ -176,8 +176,8 @@ namespace Utils { if (WiFi.status() == WL_CONNECTED && espClient.connected()) { APRS_IS_Utils::checkStatus(); thirdLine = getLocalIP(); - show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, "SENDING iGate BEACON", 1000); - #ifndef HELTEC_V3 + show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, "SENDING iGate BEACON", 1000); + #if defined(TTGO_T_LORA_V2_1) || defined(HELTEC_V2) if (Config.sendBatteryVoltage) { sixthLine = " (Batt=" + String(BATTERY_Utils::checkBattery(),2) + "V)"; } @@ -190,7 +190,7 @@ namespace Utils { show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0); } else { show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, "SENDING iGate BEACON", 0); - #ifndef HELTEC_V3 + #if defined(TTGO_T_LORA_V2_1) || defined(HELTEC_V2) if (Config.sendBatteryVoltage) { sixthLine = " (Batt=" + String(BATTERY_Utils::checkBattery(),2) + "V)"; } @@ -211,7 +211,7 @@ namespace Utils { sixthLine = ""; show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, "SENDING iGate BEACON", 0); - #ifndef HELTEC_V3 + #if defined(TTGO_T_LORA_V2_1) || defined(HELTEC_V2) if (Config.sendBatteryVoltage) { sixthLine = " (Batt=" + String(BATTERY_Utils::checkBattery(),2) + "V)"; }