I’ve been trying for several days to get my Hilitchi DS18B20 to be recognized by my ESP V3.2 board with no luck.
Here are the libraries and versions I currently have installed:
- OneWire: 2.3
- DallasTemperature: 4.0.3
- Heltec ESP32 Dev-Boards: 2.1.4
- Adafruit BME280 Library: 2.3.0
- Adafruit BusIO: 1.17.2
- Adafruit GFX Library: 1.12.1
- Adafruit Unified Sensor: 1.1.15
- OneWireNg: 0.14.0
- U8g2: 2.35.30
Here is my simple code that I’m using to just try to read from the sensor:
#include "LoRaWan_APP.h" // LoRa driver for Heltec boards
#include "Arduino.h"
#include <OneWire.h> // For 1-Wire communication with DS18B20
#include <DallasTemperature.h> // DS18B20 temperature sensor library
// ===============================
// DS18B20 Temperature Sensor Setup
// ===============================
#define ONE_WIRE_BUS 7 // GPIO pin connected to DS18B20 data line
OneWire oneWire(ONE_WIRE_BUS); // Create OneWire instance
DallasTemperature sensors(&oneWire); // Pass OneWire to Dallas library
void setup() {
Serial.begin(115200);
Serial.println("DS18B20 Test with Heltec Board Library");
// Initialize MCU and peripherals (Heltec board specifics)
Mcu.begin(HELTEC_BOARD, SLOW_CLK_TPYE);
// Initialize the temperature sensor
sensors.begin();
Serial.println("DS18B20 initialized");
// Debug: Check device count
Serial.print("Number of devices found: ");
Serial.println(sensors.getDeviceCount());
}
void loop() {
Serial.println("Requesting temperatures...");
sensors.requestTemperatures();
delay(750); // Wait for conversion to complete
Serial.println("Getting temperature...");
float temperatureC = sensors.getTempCByIndex(0);
float temperatureF = sensors.getTempFByIndex(0);
Serial.print("Raw C value: ");
Serial.println(temperatureC);
Serial.print("Raw F value: ");
Serial.println(temperatureF);
if (temperatureC == DEVICE_DISCONNECTED_C) {
Serial.println("ERROR: Device disconnected!");
} else if (temperatureC == -127.00) {
Serial.println("ERROR: Invalid reading!");
} else {
Serial.print(temperatureC);
Serial.println("ºC");
Serial.print(temperatureF);
Serial.println("ºF");
}
delay(5000);
}
My Serial Monitor reports this when I run this code with the sensor hooked up:
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x1 (POWERON),boot:0x2b (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3818,len:0x508
load:0x403c9700,len:0x4
load:0x403c9704,len:0xad0
load:0x403cc700,len:0x29e4
entry 0x403c9880
DS18B20 Test with Heltec Board Library
DS18B20 initialized
Number of devices found: 0
Requesting temperatures...
Getting temperature...
Raw C value: -127.00
Raw F value: -196.60
ERROR: Device disconnected!
Any help would be greatly appreciated, I’m lost at this point.