Skip to content

Commit

Permalink
Merge pull request #5 from matthias-bs/20241227-feat-lilygo-t3s3
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-bs authored Dec 27, 2024
2 parents 7d5b830 + c06ce29 commit ab81c53
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 45 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
#- esp32:esp32:ttgo-lora32:Revision=TTGO_LoRa32_V1
#- esp32:esp32:ttgo-lora32:Revision=TTGO_LoRa32_V2
- esp32:esp32:ttgo-lora32:Revision=TTGO_LoRa32_v21new
- esp32:esp32:lilygo_t3s3:Revision=Radio_LR1121
- esp32:esp32:heltec_wireless_stick
- esp32:esp32:heltec_wifi_lora_32_V2
- esp32:esp32:featheresp32
Expand Down Expand Up @@ -82,9 +83,9 @@ jobs:
run:
|
declare -a required_libs=(
"RadioLib@6.4.2"
"BresserWeatherSensorReceiver@0.23.0"
"ArduinoJson@7.0.3")
"RadioLib@7.1.1"
"BresserWeatherSensorReceiver@0.29.0"
"ArduinoJson@7.2.1")
for i in "${required_libs[@]}"
do
arduino-cli lib install "$i"
Expand Down
86 changes: 68 additions & 18 deletions SensorTransmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
// 20231113 Added JSON string input from serial console
// Added TRANSCEIVER_CHIP
// 20231114 Added enum Encoders
// 20241227 Added LilyGo T3 S3 SX1262/SX1276/LR1121
//
// ToDo:
// -
Expand All @@ -50,7 +51,7 @@

#include <Arduino.h>

#define NUM_SENSORS 1 //!< WeatherSensor - no. of sensors
#define MAX_SENSORS_DEFAULT 1 //!< WeatherSensor - no. of sensors
#define WIND_DATA_FLOATINGPOINT //!< WeatherSensor - wind data type

//!< Select one of the following data sources
Expand Down Expand Up @@ -138,11 +139,38 @@ enum struct Encoders {
#pragma message("ARDUINO_TTGO_LoRa32_V21new defined; using on-board transceiver")
#define USE_SX1276

#elif defined(ARDUINO_heltec_wireless_stick)
#elif defined(ARDUINO_LILYGO_T3S3_SX1262)
// https://github.com/espressif/arduino-esp32/blob/master/variants/lilygo_t3_s3_sx1262/pins_arduino.h
#pragma message("ARDUINO_LILYGO_T3S3_SX1262 defined; using on-board transceiver")
#define USE_SX1262
#define PIN_RECEIVER_CS LORA_CS
#define PIN_RECEIVER_IRQ LORA_IRQ
#define PIN_RECEIVER_GPIO LORA_BUSY
#define PIN_RECEIVER_RST LORA_RST

#elif defined(ARDUINO_LILYGO_T3S3_SX1276)
// https://github.com/espressif/arduino-esp32/blob/master/variants/lilygo_t3_s3_sx127x/pins_arduino.h
#pragma message("ARDUINO_LILYGO_T3S3_SX1276 defined; using on-board transceiver")
#define USE_SX1276
#define PIN_RECEIVER_CS LORA_CS
#define PIN_RECEIVER_IRQ LORA_IRQ
#define PIN_RECEIVER_GPIO LORA_BUSY
#define PIN_RECEIVER_RST LORA_RST

#elif defined(ARDUINO_LILYGO_T3S3_LR1121)
// https://github.com/espressif/arduino-esp32/blob/master/variants/lilygo_t3_s3_lr1121/pins_arduino.h
#pragma message("ARDUINO_LILYGO_T3S3_LR1121 defined; using on-board transceiver")
#define USE_LR1121
#define PIN_RECEIVER_CS LORA_CS
#define PIN_RECEIVER_IRQ LORA_IRQ
#define PIN_RECEIVER_GPIO LORA_BUSY
#define PIN_RECEIVER_RST LORA_RST

#elif defined(ARDUINO_HELTEC_WIRELESS_STICK)
#pragma message("ARDUINO_heltec_wireless_stick defined; using on-board transceiver")
#define USE_SX1276

#elif defined(ARDUINO_heltec_wifi_lora_32_V2)
#elif defined(ARDUINO_HELTEC_WIFI_LORA_32_V2)
#pragma message("ARDUINO_heltec_wifi_lora_32_V2 defined; using on-board transceiver")
#define USE_SX1276

Expand All @@ -164,7 +192,7 @@ enum struct Encoders {
#define USE_SX1276
#pragma message("Required wiring: A to RST, B to DIO1, D to DIO0, E to CS")

#elif defined(ARDUINO_ESP32_DEV)
#elif defined(ARDUINO_DFROBOT_FIREBEETLE_ESP32)
//#define LORAWAN_NODE
#define FIREBEETLE_ESP32_COVER_LORA

Expand All @@ -178,35 +206,57 @@ enum struct Encoders {
#define USE_SX1276

#else
#pragma message("ARDUINO_ESP32_DEV defined; select either LORAWAN_NODE or FIREBEETLE_ESP32_COVER_LORA manually!")
#pragma message("ARDUINO_DFROBOT_FIREBEETLE_ESP32 defined; select either LORAWAN_NODE or FIREBEETLE_ESP32_COVER_LORA manually!")

#endif
#endif

#elif defined(ESP32)
#pragma message("ESP32 defined; this is a generic (i.e. non-specific) target")
#pragma message("Cross check if the selected GPIO pins are really available on your board.")
#pragma message("Connect a radio module with a supported chip.")
#pragma message("Select the chip by setting the appropriate define.")
#define USE_SX1276
//#define USE_SX1262
//#define USE_CC1101
//#define USE_LR1121
// Generic pinning for ESP32 development boards
#define PIN_RECEIVER_CS 27
#define PIN_RECEIVER_IRQ 21
#define PIN_RECEIVER_GPIO 33
#define PIN_RECEIVER_RST 32

// ------------------------------------------------------------------------------------------------
// --- Radio Transceiver ---
// ------------------------------------------------------------------------------------------------
// Select type of receiver module (if not yet defined based on the assumptions above)
#if ( !defined(USE_CC1101) && !defined(USE_SX1276) )
#define USE_CC1101
#elif defined(ESP8266)
#pragma message("ESP8266 defined; this is a generic (i.e. non-specific) target")
#pragma message("Cross check if the selected GPIO pins are really available on your board.")
#pragma message("Connect a radio module with a supported chip.")
#pragma message("Select the chip by setting the appropriate define.")
//#define USE_SX1276
#endif
//#define USE_SX1262
#define USE_CC1101
//#define USE_LR1121

// Generic pinning for ESP8266 development boards (e.g. LOLIN/WEMOS D1 mini)
#define PIN_RECEIVER_CS 15
#define PIN_RECEIVER_IRQ 4
#define PIN_RECEIVER_GPIO 5
#define PIN_RECEIVER_RST 2

#if ( (defined(USE_CC1101) && defined(USE_SX1276)) || \
(defined(USE_SX1276) && defined(USE_SX1262)) || \
(defined(USE_SX1262) && defined(USE_CC1101)) )
#error "Either USE_CC1101 OR USE_SX1276 OR USE_SX1262 must be defined!"
#endif


// ------------------------------------------------------------------------------------------------
// --- Radio Transceiver ---
// ------------------------------------------------------------------------------------------------
#if defined(USE_CC1101)
#define TRANSCEIVER_CHIP "[CC1101]"
#elif defined(USE_SX1276)
#define TRANSCEIVER_CHIP "[SX1276]"
#elif defined(USE_SX1262)
#define TRANSCEIVER_CHIP "[SX1262]"
#elif defined(USE_LR1121)
#define TRANSCEIVER_CHIP "[LR1121]"
#else
#error "Either USE_CC1101, USE_SX1276 or USE_SX1262 must be defined!"
#error "Either USE_CC1101, USE_SX1276, USE_SX1262 or USE_LR1121 must be defined!"
#endif

// Arduino default SPI pins
Expand Down
84 changes: 61 additions & 23 deletions SensorTransmitter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
// 20240129 Fixed lightning counter encoding
// 20240209 Added CO2 and HCHO/VOC sensors
// 20240210 Added missing CO2 and HCHO/VOC sensor encoding
// 20241227 Added LilyGo T3 S3 SX1262/SX1276/LR1121
//
// ToDo:
// -
Expand All @@ -68,35 +69,74 @@
#include <ArduinoJson.h> // https://github.com/bblanchon/ArduinoJson

#if defined(USE_CC1101)
CC1101 radio = new Module(PIN_TRANSCEIVER_CS, PIN_TRANSCEIVER_IRQ, RADIOLIB_NC, PIN_TRANSCEIVER_GPIO);
#endif
#if defined(USE_SX1276)
static CC1101 radio = new Module(PIN_TRANSCEIVER_CS, PIN_TRANSCEIVER_IRQ, RADIOLIB_NC, PIN_TRANSCEIVER_GPIO);
#elif defined(USE_SX1276)
// SX1276 has the following connections:
// NSS pin: PIN_TRANSCEIVER_CS
// DIO0 pin: PIN_TRANSCEIVER_IRQ
// RESET pin: PIN_TRANSCEIVER_RST
// DIO1 pin: PIN_TRANSCEIVER_GPIO
SX1276 radio = new Module(PIN_TRANSCEIVER_CS, PIN_TRANSCEIVER_IRQ, PIN_TRANSCEIVER_RST, PIN_TRANSCEIVER_GPIO);
static SX1276 radio = new Module(PIN_TRANSCEIVER_CS, PIN_TRANSCEIVER_IRQ, PIN_TRANSCEIVER_RST, PIN_TRANSCEIVER_GPIO);
#elif defined(USE_SX1262)
static SX1262 radio = new Module(PIN_TRANSCEIVER_CS, PIN_TRANSCEIVER_IRQ, PIN_TRANSCEIVER_RST, PIN_TRANSCEIVER_GPIO);
#elif defined(USE_LR1121)
static LR1121 radio = new Module(PIN_TRANSCEIVER_CS, PIN_TRANSCEIVER_IRQ, PIN_TRANSCEIVER_RST, PIN_TRANSCEIVER_GPIO);
#endif

#if defined(ARDUINO_LILYGO_T3S3_SX1262) || defined(ARDUINO_LILYGO_T3S3_SX1276) || defined(ARDUINO_LILYGO_T3S3_LR1121)
static SPIClass *spi = nullptr;
#endif

#if defined(ARDUINO_LILYGO_T3S3_LR1121)
static const uint32_t rfswitch_dio_pins[] = {
RADIOLIB_LR11X0_DIO5, RADIOLIB_LR11X0_DIO6,
RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC
};

static const Module::RfSwitchMode_t rfswitch_table[] = {
// mode DIO5 DIO6
{ LR11x0::MODE_STBY, { LOW, LOW } },
{ LR11x0::MODE_RX, { HIGH, LOW } },
{ LR11x0::MODE_TX, { LOW, HIGH } },
{ LR11x0::MODE_TX_HP, { LOW, HIGH } },
{ LR11x0::MODE_TX_HF, { LOW, LOW } },
{ LR11x0::MODE_GNSS, { LOW, LOW } },
{ LR11x0::MODE_WIFI, { LOW, LOW } },
END_OF_MODE_TABLE,
};
#endif

void setup()
{
Serial.begin(115200);

// initialize SX1276
#if defined(ARDUINO_LILYGO_T3S3_SX1262) || defined(ARDUINO_LILYGO_T3S3_SX1276) || defined(ARDUINO_LILYGO_T3S3_LR1121)
spi = new SPIClass(SPI);
spi->begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS);
radio = new Module(PIN_RECEIVER_CS, PIN_RECEIVER_IRQ, PIN_RECEIVER_RST, PIN_RECEIVER_GPIO, *spi);
#endif



// initialize radio
log_i("%s Initializing ... ", TRANSCEIVER_CHIP);
// carrier frequency: 868.3 MHz
// bit rate: 8.22 kbps
// frequency deviation: 57.136417 kHz
// Rx bandwidth: 270.0 kHz (CC1101) / 250 kHz (SX1276)
// output power: 10 dBm
// preamble length: 40 bits
// Preamble: AA AA AA AA AA
// Sync: 2D D4
// carrier frequency: 868.3 MHz
// bit rate: 8.22 kbps
// frequency deviation: 57.136417 kHz
// Rx bandwidth: 270.0 kHz (CC1101) / 250 kHz (SX1276)
// output power: 10 dBm
// preamble length: 40 bits
// Preamble: AA AA AA AA AA
// Sync: 2D D4
#ifdef USE_CC1101
int state = radio.begin(868.3, 8.21, 57.136417, 270, 10, 32);
#else
#elif defined(USE_SX1276)
int state = radio.beginFSK(868.3, 8.21, 57.136417, 250, 10, 32);
#elif defined(USE_SX1262)
int state = radio.beginFSK(868.3, 8.21, 57.136417, 234.3, 10, 32);
#else
// defined(USE_LR1121)
int state = radio.beginGFSK(868.3, 8.21, 57.136417, 234.3, 10, 32);
#endif
if (state == RADIOLIB_ERR_NONE)
{
Expand All @@ -109,15 +149,13 @@ void setup()
;
}

// some modules have an external RF switch
// controlled via two pins (RX enable, TX enable)
// to enable automatic control of the switch,
// call the following method
// RX enable: 4
// TX enable: 5
/*
radio.setRfSwitchPins(4, 5);
*/
#if defined(ARDUINO_LILYGO_T3S3_LR1121)
// set RF switch control configuration
radio.setRfSwitchTable(rfswitch_dio_pins, rfswitch_table);

// LR1121 TCXO Voltage 2.85~3.15V
radio.setTCXO(3.0);
#endif
}

// counter to keep track of transmitted packets
Expand Down
2 changes: 1 addition & 1 deletion logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#ifndef LOGGING_H
#define LOGGING_H

#if defined(ESP8266) || defined(ARDUINO_ARCH_RP2040)
#if defined(ESP8266) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_AVR)

#if defined(ARDUINO_ARCH_RP2040) && defined(DEBUG_RP2040_PORT)
#define DEBUG_PORT DEBUG_RP2040_PORT
Expand Down

0 comments on commit ab81c53

Please # to comment.