Class Instantiate OneWire and Dallas ESP32 Arduino IDE

I have the following simple example which compiles but does not run on ESP32 using Arduino IDE 2.02-nightly.

Any ideas how to fix?

// Sensor Class *****************
#include <OneWire.h>
#include <DallasTemperature.h>

// .. Class Definition
class sensors {
  public:
    sensors();
    OneWire myOneWire;
    DallasTemperature ds;
};
// .. Constructor
sensors::sensors() : myOneWire(10), ds(&myOneWire) {}

// Main Code
sensors mySensors;
void setup() {
  Serial.begin(115200);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println(millis());
  delay(100);
}

The ESP serial console gives the following and continuously restarts itself.

12:06:09.193 -> 
12:06:09.193 -> rst:0x10 (RTCWDT_RTC_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
12:06:09.225 -> configsip: 0, SPIWP:0xee
12:06:09.225 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
12:06:09.225 -> mode:DIO, clock div:1
12:06:09.225 -> load:0x3fff0030,len:1344
12:06:09.225 -> load:0x40078000,len:13864
12:06:09.225 -> load:0x40080400,len:3608
12:06:09.225 -> entry 0x400805f0
12:06:17.985 -> ets Jul 29 2019 12:21:46
12:06:17.985 -> 
12:06:17.985 -> rst:0x10 (RTCWDT_RTC_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
12:06:17.985 -> configsip: 0, SPIWP:0xee
12:06:17.985 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
12:06:17.985 -> mode:DIO, clock div:1
12:06:17.985 -> load:0x3fff0030,len:1344
12:06:17.985 -> load:0x40078000,len:13864
12:06:17.985 -> load:0x40080400,len:3608
12:06:17.985 -> entry 0x400805f0
12:06:26.745 -> ets Jul 29 2019 12:21:46

It works for me with:
Adafruit ESP32 Feather
Arduino IDE 1.8.15
ESP32 Core 2.0.2
OneWire 2.3.7
DallasTemperature 3.9.0

Thanks for running it. I tried different hardware and it worked.

I was using an Ali bought TTGO T5 v2.3.1

Welcome

myOneWire(10)

This will call pinMode before setup is called, this is most likely your problem. You have to add a begin method to your class, which shall be called in setup

OneWire have an empty constructor and a begin( pin ) method, use this instead :slight_smile:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.