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
2 changes: 2 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ 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

; ----------------- TESTING ---------------------

Expand Down
36 changes: 36 additions & 0 deletions src/helpers/sensors/EnvironmentSensorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ static Adafruit_VL53L0X VL53L0X;
static RAK12035_SoilMoisture RAK12035;
#endif

#if ENV_INCLUDE_DS18B20
#ifndef TELEM_DS18B20_PIN
#define TELEM_DS18B20_PIN 7 // OneWire data pin for DS18B20 temperature sensors
#endif
#include <OneWire.h>
#include <DallasTemperature.h>
static OneWire oneWire(TELEM_DS18B20_PIN);
static DallasTemperature DS18B20(&oneWire);
#endif

#if ENV_INCLUDE_GPS && defined(RAK_BOARD) && !defined(RAK_WISMESH_TAG)
#define RAK_WISBLOCK_GPS
#endif
Expand Down Expand Up @@ -475,6 +485,20 @@ static void query_rak12035(uint8_t ch, uint8_t sub_ch, CayenneLPP& lpp) {
}
#endif

#if ENV_INCLUDE_DS18B20
// OneWire bus, not I2C: not in SENSOR_TABLE. Each device on the bus gets its own channel.
static uint8_t init_ds18b20() {
DS18B20.begin();
return DS18B20.getDeviceCount();
}
static void query_ds18b20(uint8_t ch, uint8_t sub_ch, CayenneLPP& lpp) {
// Entries are queried in order, so one conversion request serves all devices.
if (sub_ch == 0) DS18B20.requestTemperatures();
float temp = DS18B20.getTempCByIndex(sub_ch);
if (temp != DEVICE_DISCONNECTED_C) lpp.addTemperature(ch, temp);
}
#endif

#if ENV_INCLUDE_BME680_BSEC
static void bsec_load_state() {
using namespace Adafruit_LittleFS_Namespace;
Expand Down Expand Up @@ -672,6 +696,18 @@ bool EnvironmentSensorManager::begin() {
}
}

#if ENV_INCLUDE_DS18B20
uint8_t ds_count = init_ds18b20();
if (ds_count == 0) {
MESH_DEBUG_PRINTLN("DS18B20 not detected on OneWire pin %d", TELEM_DS18B20_PIN);
} else {
MESH_DEBUG_PRINTLN("Found %d DS18B20 on OneWire pin %d", ds_count, TELEM_DS18B20_PIN);
for (uint8_t sub = 0; sub < ds_count && _active_sensor_count < MAX_ACTIVE_SENSORS; sub++) {
_active_sensors[_active_sensor_count++] = { query_ds18b20, sub };
}
}
#endif

return true;
}

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 @@ -232,6 +232,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