Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ lib_deps = ${arduino_base.lib_deps}
[sensor_base]
build_flags =
-D ENV_INCLUDE_GPS=1
-D ENV_INCLUDE_DS18B20=1
-D ENV_INCLUDE_AHTX0=1
-D ENV_INCLUDE_BME280=1
-D ENV_INCLUDE_BMP280=1
Expand Down Expand Up @@ -149,3 +150,5 @@ lib_deps =
stevemarple/MicroNMEA @ ^2.0.6
adafruit/Adafruit BME680 Library @ ^2.0.4
adafruit/Adafruit BMP085 Library @ ^1.2.4
paulstoffregen/OneWire @ ^2.3.8
milesburton/DallasTemperature @ ^4.0.6
31 changes: 31 additions & 0 deletions src/helpers/sensors/EnvironmentSensorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ static Adafruit_BMP085 BMP085;
static Adafruit_AHTX0 AHTX0;
#endif

#if ENV_INCLUDE_DS18B20
#include <OneWire.h>
#include <DallasTemperature.h>
#ifndef TELEM_DS18B20_PIN
#define TELEM_DS18B20_PIN 7
#endif
OneWire oneWire(TELEM_DS18B20_PIN);
static DallasTemperature sensors(&oneWire);
#endif

#if ENV_INCLUDE_BME280
#ifndef TELEM_BME280_ADDRESS
#define TELEM_BME280_ADDRESS 0x76 // BME280 environmental sensor I2C address
Expand Down Expand Up @@ -179,6 +189,17 @@ bool EnvironmentSensorManager::begin() {
}
#endif

#if ENV_INCLUDE_DS18B20
sensors.begin();
uint8_t resetResult = oneWire.reset();
if (resetResult == 1) {
DS18B20_initialized = true;
} else {
DS18B20_initialized = false;
MESH_DEBUG_PRINTLN("OneWire bus is unresponsive!");
}
#endif

#if ENV_INCLUDE_BME680
if (BME680.begin(TELEM_BME680_ADDRESS, TELEM_WIRE)) {
MESH_DEBUG_PRINTLN("Found BME680 at address: %02X", TELEM_BME680_ADDRESS);
Expand Down Expand Up @@ -352,6 +373,16 @@ bool EnvironmentSensorManager::querySensors(uint8_t requester_permissions, Cayen
}
#endif

#if ENV_INCLUDE_DS18B20
if (DS18B20_initialized) {
sensors.requestTemperatures();
for (uint8_t i = 0; i < sensors.getDeviceCount(); i++) {
telemetry.addTemperature(next_available_channel, sensors.getTempCByIndex(i));
next_available_channel++;
}
}
#endif

#if ENV_INCLUDE_BME680
if (BME680_initialized) {
if (BME680.performReading()) {
Expand Down
1 change: 1 addition & 0 deletions src/helpers/sensors/EnvironmentSensorManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class EnvironmentSensorManager : public SensorManager {
bool SHT4X_initialized = false;
bool BME680_initialized = false;
bool BMP085_initialized = false;
bool DS18B20_initialized = false;

bool gps_detected = false;
bool gps_active = false;
Expand Down
2 changes: 2 additions & 0 deletions variants/xiao_s3_wio/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ build_flags =
-D ADVERT_LAT=0.0
-D ADVERT_LON=0.0
-D ADMIN_PASSWORD='"password"'
-D ENV_INCLUDE_DS18B20=1
-D TELEM_DS18B20_PIN=3
; -D MESH_PACKET_LOGGING=1
; -D MESH_DEBUG=1
lib_deps =
Expand Down