diff --git a/include/LiLyGo.h b/include/LiLyGo.h index ec8754c..37e02f0 100644 --- a/include/LiLyGo.h +++ b/include/LiLyGo.h @@ -2,6 +2,8 @@ #define UNUSED_PIN (0) // LilyGo defined +// Check this LiLyGo file LoraSA2\include\utilities.h + #define I2C_SDA 18 #define I2C_SCL 17 #define OLED_RST UNUSED_PIN @@ -27,6 +29,14 @@ #define RADIO_DIO1_PIN 33 #define RADIO_BUSY_PIN 34 +#ifdef USING_SX1280PA +#define RADIO_DIO1_PIN 9 // SX1280 DIO1 = IO9 +#define RADIO_BUSY_PIN 36 // SX1280 BUSY = IO36 +#define RADIO_RX_PIN 21 +#define RADIO_TX_PIN 10 +#define BUTTON_PIN 0 +#endif + // Define for our code #define RST_OLED UNUSED_PIN #define LED BOARD_LED @@ -52,11 +62,16 @@ #include SPIClass *hspi = new SPIClass(2); SX1262 radio = new Module(SS, DIO1, RST_LoRa, BUSY_LoRa, *hspi); -#else +#else // ARDUINO_heltec_wifi_32_lora_V3 +#ifdef USING_SX1280PA +SX1280 radio = new Module(RADIO_CS_PIN, RADIO_DIO1_PIN, RADIO_RST_PIN, RADIO_BUSY_PIN); +#endif // end USING_SX1280PA +#ifdef USING_SX1262 // Default SPI on pins from pins_arduino.h SX1262 radio = new Module(RADIO_CS_PIN, RADIO_DIO1_PIN, RADIO_RST_PIN, RADIO_BUSY_PIN); -#endif -#endif +#endif // end USING_SX1262 +#endif // end ARDUINO_heltec_wifi_32_lora_V3 +#endif // end HELTEC_NO_RADIO_INSTANCE void heltec_loop() {} @@ -107,7 +122,7 @@ PrintSplitter both(Serial, display); Print &both = Serial; #endif // some fake pin -#define BUTTON 38 +#define BUTTON BUTTON_PIN #include "HotButton.h" HotButton button(BUTTON); diff --git a/include/global_config.h b/include/global_config.h index d169fff..f8205e6 100644 --- a/include/global_config.h +++ b/include/global_config.h @@ -1,15 +1,21 @@ #ifndef __GLOBAL_CONFIG_H__ #define __GLOBAL_CONFIG_H__ +#ifndef FREQ_BEGIN // frequency range in MHz to scan #define FREQ_BEGIN 850 +#endif + +#ifndef FREQ_END // TODO: if % RANGE_PER_PAGE != 0 #define FREQ_END 950 +#endif // Measurement bandwidth. Allowed bandwidth values (in kHz) are: // 4.8, 5.8, 7.3, 9.7, 11.7, 14.6, 19.5, 23.4, 29.3, 39.0, 46.9, 58.6, // 78.2, 93.8, 117.3, 156.2, 187.2, 234.3, 312.0, 373.6 and 467.0 #define BANDWIDTH 467.0 +#define BANDWIDTH_SX1280 406. // Detection level from the 33 levels. The higher number is more sensitive #define DEFAULT_DRONE_DETECTION_LEVEL 18 diff --git a/platformio.ini b/platformio.ini index 26992cb..e2a476a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -29,7 +29,7 @@ lib_deps = ropg/Heltec_ESP32_LoRa_v3@^0.9.1 build_flags = -DHELTEC_POWER_BUTTON -[env:lilygo-T3S3-v1-2] +[env:lilygo-T3S3-v1-2-sx1262] platform = espressif32 board = t3_s3_v1_x framework = arduino @@ -51,6 +51,30 @@ build_flags = -DARDUINO_LILYGO_T3_S3_V1_X -DARDUINO_USB_MODE=1 + +[env:lilygo-T3S3-v1-2-xs1280] +platform = espressif32 +board = t3_s3_v1_x +framework = arduino +upload_speed = 921600 +monitor_speed = 115200 +board_build.f_cpu = 240000000 +lib_deps = + ropg/Heltec_ESP32_LoRa_v3@^0.9.1 + RadioLib +build_flags = + -DLILYGO + -DT3_S3_V1_2_SX1280_PA + -DARDUINO_LILYGO_T3S3_SX1280_PA + -DESP32 + -DUSING_SX1280PA + -DFREQ_BEGIN=2400 + -DFREQ_END=2500 + -DARDUINO_ARCH_ESP32 + -DARDUINO_USB_CDC_ON_BOOT=1 + -DARDUINO_LILYGO_T3_S3_V1_X + -DARDUINO_USB_MODE=1 + [env:heltec_wifi_lora_32_V3-test-signal-generator] platform = espressif32 board = heltec_wifi_lora_32_V3 diff --git a/src/main.cpp b/src/main.cpp index 36667a6..a0276d7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,11 +29,18 @@ // #define WIFI_SCANNING_ENABLED true // #define BT_SCANNING_ENABLED true +// Direct access to the low-level SPI communication between RadioLib and the radio module. +#define RADIOLIB_LOW_LEVEL (1) +// In this mode, all methods and member variables of all RadioLib classes will be made +// public and so will be exposed to the user. This allows direct manipulation of the +// library internals. +#define RADIOLIB_GODMODE (1) #ifndef LILYGO #include // This file contains a binary patch for the SX1262 #include "modules/SX126x/patches/SX126x_patch_scan.h" -#elif defined(LILYGO) +#endif // end LILYGO +#if defined(LILYGO) // LiLyGO device does not support the auto download mode, you need to get into the // download mode manually. To do so, press and hold the BOOT button and then press the // RESET button once. After that release the BOOT button. Or OFF->ON together with BOOT @@ -42,7 +49,6 @@ #include "utilities.h" // Our Code #include "LiLyGo.h" - #endif // end LILYGO #define BT_SCAN_DELAY 60 * 1 * 1000 @@ -172,15 +178,15 @@ int SCAN_RANGES[] = {}; // to put everything into one page set RANGE_PER_PAGE = FREQ_END - 800 uint64_t RANGE_PER_PAGE = FREQ_END - FREQ_BEGIN; // FREQ_END - FREQ_BEGIN +// To Enable Multi Screen scan +// uint64_t RANGE_PER_PAGE = 50; +// Default Range on Menu Button Switch + // multiplies STEPS * N to increase scan resolution. #define SCAN_RBW_FACTOR 2 constexpr int OSD_PIXELS_PER_CHAR = (STEPS * SCAN_RBW_FACTOR) / OSD_CHART_WIDTH; -// To Enable Multi Screen scan -// uint64_t RANGE_PER_PAGE = 50; -// Default Range on Menu Button Switch - #define DEFAULT_RANGE_PER_PAGE 50 // Print spectrum values pixels at once or by line @@ -403,14 +409,19 @@ void init_radio() { // initialize SX1262 FSK modem at the initial frequency both.println("Init radio"); +#ifdef USING_SX1280PA + radio.begin(); + state == radio.beginGFSK(FREQ_BEGIN); +#else state == radio.beginFSK(FREQ_BEGIN); - +#endif if (state == RADIOLIB_ERR_NONE) { Serial.println(F("success!")); } else { + display.println("Error:" + String(state)); Serial.print(F("failed, code ")); Serial.println(state); while (true) @@ -432,15 +443,25 @@ void init_radio() #endif both.println("Setting up radio"); +#ifdef USING_SX1280PA + // RADIOLIB_OR_HALT(radio.setBandwidth(RADIOLIB_SX128X_LORA_BW_406_25)); +#else RADIOLIB_OR_HALT(radio.setRxBandwidth(BANDWIDTH)); +#endif // and disable the data shaping RADIOLIB_OR_HALT(radio.setDataShaping(RADIOLIB_SHAPING_NONE)); both.println("Starting scanning..."); - // calibrate only once ,,, at startup - // TODO: check documentation (9.2.1) if we must calibrate in certain ranges +// calibrate only once ,,, at startup +// TODO: check documentation (9.2.1) if we must calibrate in certain ranges +#ifdef USING_SX1280PA + radio.setFrequency(FREQ_BEGIN); + state = radio.startReceive(); +#else radio.setFrequency(FREQ_BEGIN, true); +#endif + delay(50); } @@ -507,7 +528,7 @@ void setup(void) delay(400); display.clear(); - resolution = RANGE / (STEPS * SCAN_RBW_FACTOR); + resolution = (float)RANGE / (STEPS * SCAN_RBW_FACTOR); single_page_scan = (RANGE_PER_PAGE == range); @@ -570,7 +591,12 @@ void setup(void) #ifdef METHOD_RSSI // TODO: try RADIOLIB_SX126X_RX_TIMEOUT_INF +#ifdef USING_SX1280PA + state = radio.startReceive(RADIOLIB_SX128X_RX_TIMEOUT_NONE); +#else state = radio.startReceive(RADIOLIB_SX126X_RX_TIMEOUT_NONE); +#endif + if (state != RADIOLIB_ERR_NONE) { Serial.print(F("Failed to start receive mode, error code: ")); @@ -882,8 +908,9 @@ void loop(void) Serial.println("setFrequency:" + String(freq)); #endif -#ifdef LILYGO - state = radio.setFrequency(freq, false); // false = no calibration need here +#ifdef USING_SX1280PA + state = radio.setFrequency(freq); // 1280 doesn't have calibration + radio.startReceive(RADIOLIB_SX128X_RX_TIMEOUT_INF); #else state = radio.setFrequency(freq, false); // false = no calibration need here #endif @@ -947,7 +974,16 @@ void loop(void) // N of samples for (int r = 0; r < SAMPLES_RSSI; r++) { +#ifdef USING_SX1280PA + // radio.startReceive(); + // get instantaneous RSSI value + // When PR will be merged we can use radi.getRSSI(false); + uint8_t data[3] = {0, 0, 0}; // RssiInst, Status, RFU + radio.mod->SPIreadStream(RADIOLIB_SX128X_CMD_GET_RSSI_INST, data, 3); + rssi = ((float)data[0] / (-2.0)); +#else rssi = radio.getRSSI(false); +#endif int abs_rssi = abs(rssi); // ToDO: check if 4 is correct value for 33 power bins // Now we have more space because we are ignoring low dB values