diff --git a/platformio.ini b/platformio.ini index 7c63ad7ad..fe2f5e28a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -181,6 +181,8 @@ lib_deps = dfrobot/DFRobot_BMM150@1.0.0 # renovate: datasource=custom.pio depName=Adafruit_TSL2561 packageName=adafruit/library/Adafruit TSL2561 adafruit/Adafruit TSL2561@1.1.2 + # renovate: datasource=custom.pio depName=BH1750_WE packageName=wollewald/BH1750_WE@^1.1.10 + wollewald/BH1750_WE@^1.1.10 ; (not included in native / portduino) [environmental_extra] diff --git a/src/detect/ScanI2C.h b/src/detect/ScanI2C.h index 2e602338c..e7bdf58c5 100644 --- a/src/detect/ScanI2C.h +++ b/src/detect/ScanI2C.h @@ -82,7 +82,8 @@ class ScanI2C BHI260AP, BMM150, TSL2561, - DRV2605 + DRV2605, + BH1750 } DeviceType; // typedef uint8_t DeviceAddress; diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index da2a57fee..59d93d74f 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -485,7 +485,25 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize) SCAN_SIMPLE_CASE(LTR390UV_ADDR, LTR390UV, "LTR390UV", (uint8_t)addr.address); SCAN_SIMPLE_CASE(PCT2075_ADDR, PCT2075, "PCT2075", (uint8_t)addr.address); SCAN_SIMPLE_CASE(CST328_ADDR, CST328, "CST328", (uint8_t)addr.address); - SCAN_SIMPLE_CASE(LTR553ALS_ADDR, LTR553ALS, "LTR553ALS", (uint8_t)addr.address); + case LTR553ALS_ADDR: + registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x86), 1); // Part ID register + if (registerValue == 0x92) { // LTR553ALS Part ID + type = LTR553ALS; + logFoundDevice("LTR553ALS", (uint8_t)addr.address); + } else { + // Test BH1750 - send power on command + i2cBus->beginTransmission(addr.address); + i2cBus->write(0x01); // Power On command + uint8_t bh1750_error = i2cBus->endTransmission(); + if (bh1750_error == 0) { + type = BH1750; + logFoundDevice("BH1750", (uint8_t)addr.address); + } else { + LOG_INFO("Device found at address 0x%x was not able to be enumerated", (uint8_t)addr.address); + } + } + break; + SCAN_SIMPLE_CASE(BHI260AP_ADDR, BHI260AP, "BHI260AP", (uint8_t)addr.address); SCAN_SIMPLE_CASE(SCD4X_ADDR, SCD4X, "SCD4X", (uint8_t)addr.address); SCAN_SIMPLE_CASE(BMM150_ADDR, BMM150, "BMM150", (uint8_t)addr.address); diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index 2337af808..a923ab457 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -134,6 +134,10 @@ extern void drawCommonHeader(OLEDDisplay *display, int16_t x, int16_t y, const c #include "Sensor/TSL2561Sensor.h" #endif +#if __has_include() +#include "Sensor/BH1750Sensor.h" +#endif + #define FAILED_STATE_SENSOR_READ_MULTIPLIER 10 #define DISPLAY_RECEIVEID_MEASUREMENTS_ON_SCREEN true @@ -262,6 +266,9 @@ void EnvironmentTelemetryModule::i2cScanFinished(ScanI2C *i2cScanner) #if __has_include() addSensor(i2cScanner, ScanI2C::DeviceType::NAU7802); #endif +#if __has_include() + addSensor(i2cScanner, ScanI2C::DeviceType::BH1750); +#endif #endif } diff --git a/src/modules/Telemetry/Sensor/BH1750Sensor.cpp b/src/modules/Telemetry/Sensor/BH1750Sensor.cpp new file mode 100644 index 000000000..b8790dcd5 --- /dev/null +++ b/src/modules/Telemetry/Sensor/BH1750Sensor.cpp @@ -0,0 +1,54 @@ +#include "configuration.h" + +#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && __has_include() + +#include "../mesh/generated/meshtastic/telemetry.pb.h" +#include "BH1750Sensor.h" +#include "TelemetrySensor.h" +#include + +#ifndef BH1750_SENSOR_MODE +#define BH1750_SENSOR_MODE BH1750Mode::CHM +#endif + +BH1750Sensor::BH1750Sensor() : TelemetrySensor(meshtastic_TelemetrySensorType_BH1750, "BH1750") {} + +bool BH1750Sensor::initDevice(TwoWire *bus, ScanI2C::FoundDevice *dev) +{ + LOG_INFO("Init sensor: %s with mode %d", sensorName, BH1750_SENSOR_MODE); + + bh1750 = BH1750_WE(bus, dev->address.address); + status = bh1750.init(); + if (!status) { + return status; + } + + bh1750.setMode(BH1750_SENSOR_MODE); + + initI2CSensor(); + return status; +} + +bool BH1750Sensor::getMetrics(meshtastic_Telemetry *measurement) +{ + + /* An OTH and OTH_2 measurement takes ~120 ms. I suggest to wait + 140 ms to be on the safe side. + An OTL measurement takes about 16 ms. I suggest to wait 20 ms + to be on the safe side. */ + if (BH1750_SENSOR_MODE == BH1750Mode::OTH || BH1750_SENSOR_MODE == BH1750Mode::OTH_2) { + bh1750.setMode(BH1750_SENSOR_MODE); + delay(140); // wait for measurement to be completed + } else if (BH1750_SENSOR_MODE == BH1750Mode::OTL) { + bh1750.setMode(BH1750_SENSOR_MODE); + delay(20); + } + + measurement->variant.environment_metrics.has_lux = true; + float lightIntensity = bh1750.getLux(); + + measurement->variant.environment_metrics.lux = lightIntensity; + return true; +} + +#endif diff --git a/src/modules/Telemetry/Sensor/BH1750Sensor.h b/src/modules/Telemetry/Sensor/BH1750Sensor.h new file mode 100644 index 000000000..d9a4ded95 --- /dev/null +++ b/src/modules/Telemetry/Sensor/BH1750Sensor.h @@ -0,0 +1,21 @@ +#pragma once +#include "configuration.h" + +#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && __has_include() + +#include "../mesh/generated/meshtastic/telemetry.pb.h" +#include "TelemetrySensor.h" +#include + +class BH1750Sensor : public TelemetrySensor +{ + private: + BH1750_WE bh1750; + + public: + BH1750Sensor(); + virtual bool getMetrics(meshtastic_Telemetry *measurement) override; + virtual bool initDevice(TwoWire *bus, ScanI2C::FoundDevice *dev) override; +}; + +#endif diff --git a/variants/esp32s3/tbeam-s3-core/rfswitch.h b/variants/esp32s3/tbeam-s3-core/rfswitch.h new file mode 100644 index 000000000..19080cec6 --- /dev/null +++ b/variants/esp32s3/tbeam-s3-core/rfswitch.h @@ -0,0 +1,11 @@ +#include "RadioLib.h" + +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, +}; \ No newline at end of file diff --git a/variants/esp32s3/tbeam-s3-core/variant.h b/variants/esp32s3/tbeam-s3-core/variant.h index 40ba0307a..1d99fbf14 100644 --- a/variants/esp32s3/tbeam-s3-core/variant.h +++ b/variants/esp32s3/tbeam-s3-core/variant.h @@ -15,6 +15,7 @@ // not found then probe for SX1262 #define USE_SX1262 #define USE_SX1268 +#define USE_LR1121 #define LORA_DIO0 -1 // a No connect on the SX1262 module #define LORA_RESET 5 @@ -34,6 +35,19 @@ // code) #endif +// LR1121 +#ifdef USE_LR1121 +#define LR1121_IRQ_PIN 1 +#define LR1121_NRESET_PIN LORA_RESET +#define LR1121_BUSY_PIN 4 +#define LR1121_SPI_NSS_PIN 10 +#define LR1121_SPI_SCK_PIN 12 +#define LR1121_SPI_MOSI_PIN 11 +#define LR1121_SPI_MISO_PIN 13 +#define LR11X0_DIO3_TCXO_VOLTAGE 3.0 +#define LR11X0_DIO_AS_RF_SWITCH +#endif + // Leave undefined to disable our PMU IRQ handler. DO NOT ENABLE THIS because the pmuirq can cause sperious interrupts // and waking from light sleep // #define PMU_IRQ 40 @@ -64,4 +78,4 @@ // has 32768 Hz crystal #define HAS_32768HZ 1 -#define USE_SH1106 +#define USE_SH1106 \ No newline at end of file diff --git a/variants/nrf52840/heltec_mesh_pocket/variant.h b/variants/nrf52840/heltec_mesh_pocket/variant.h index 79f47bd0e..e765dab66 100644 --- a/variants/nrf52840/heltec_mesh_pocket/variant.h +++ b/variants/nrf52840/heltec_mesh_pocket/variant.h @@ -120,7 +120,7 @@ No longer populated on PCB #undef AREF_VOLTAGE #define AREF_VOLTAGE 3.0 #define VBAT_AR_INTERNAL AR_INTERNAL_3_0 -#define ADC_MULTIPLIER (4.90F) +#define ADC_MULTIPLIER (4.6425F) #undef HAS_GPS #define HAS_GPS 0 @@ -129,4 +129,4 @@ No longer populated on PCB } #endif -#endif \ No newline at end of file +#endif