I have a waterproofed DS18B20 sensor which I cannot get a temp reading from. What’s strange is the device address from the sensor is returned just not the temperature. I would think if communication is established enough to read the address, temperature should be returned as well correct?
Using single drop with 4.7k pull up resistor and powering directly with 3V from the Boron and Argon devices I have. Sensor is returning the 85 error code.
Below is the single drop example code from the DS18B20 library which I’m using. Substituting in a spare waterproofed sensor works fine and returns address and temp. Is my original DS18B20 sensor bad or is there something I can do to further troubleshoot?
#include <DS18B20.h>
#include <math.h>
SYSTEM_MODE(SEMI_AUTOMATIC);
SYSTEM_THREAD(ENABLED);
const int MAXRETRY = 4;
const uint32_t msSAMPLE_INTERVAL = 2500;
const int16_t dsData = A0;
// Sets Pin A0 as data pin and the only sensor on bus
DS18B20 ds18b20(dsData, true);
char szInfo[64];
double celsius;
double fahrenheit;
uint32_t msLastMetric;
uint32_t msLastSample;
uint8_t dsAddress[8];
void setup() {
Serial.begin(9600);
Particle.disconnect();
WiFi.off();
delay(2000);
ds18b20.search(dsAddress);
printAddress(dsAddress);
delay(1000);
}
void loop() {
if (millis() - msLastSample >= msSAMPLE_INTERVAL){
msLastSample = millis();
getTemp();
}
}
void getTemp(){
float _temp;
int i = 0;
do {
_temp = ds18b20.getTemperature();
}while (!ds18b20.crcCheck() && MAXRETRY > i++);
if (i < MAXRETRY) {
celsius = _temp;
// fahrenheit = ds18b20.convertToFahrenheit(_temp);
Serial.println(_temp);
}
else {
celsius = fahrenheit = NAN;
Serial.println("Invalid reading");
}
}
void printAddress(uint8_t deviceAddress[8])
{
for (uint8_t i = 0; i < 8; i++)
{
Serial.print("0x");
if (deviceAddress[i] < 0x10) Serial.print("0");
Serial.print(deviceAddress[i], HEX);
if (i < 7) Serial.print(", ");
}
Serial.println("");
}