unable to read from DS18B20 sensors



  • Hello,

    I want to read temperature from two DS18B20 sensors hooked up to my Core2. The following code does not work on the Core2 but works on NodeMCU after removing the two lines specific for the M5 core2 and changing the data pin from 19 to 2.

    /*
     * minimal sketch to communicate with DS18B20 sensors on a M5Stack Core2
    */
    #include <M5Core2.h>
    #include <OneWire.h>
    #include <DallasTemperature.h> 
    
    #define ONE_WIRE_BUS 19
    OneWire oneWire(ONE_WIRE_BUS); 
    DallasTemperature DS18B20_sensors(&oneWire); 
    int no_sensors = 99;
    
    void setup(){
      M5.begin();
      // locate DS18B20 sensors
      DS18B20_sensors.begin();
      no_sensors = DS18B20_sensors.getDeviceCount();
      Serial.println("Number of connected sensors: " + String(no_sensors));
      delay(5000);  
    }
    
    void loop() {
    }
    

    I have connected the DS18B20 "DQ-pin" to the pin marked as GPIO19 on the bottom of the Core2. Wiring is identical between NodeMCU and Core2 except for the different GPIO pin.

    Serial output is

    20:07:00.206 -> axp: gpio1 init
    20:07:00.206 -> axp: gpio2 init
    20:07:00.206 -> axp: rtc battery charging enabled
    20:07:00.206 -> axp: esp32 power voltage was set to 3.35v
    20:07:00.206 -> axp: lcd backlight voltage was set to 2.80v
    20:07:00.206 -> axp: lcd logic and sdcard voltage preset to 3.3v
    20:07:00.206 -> axp: vibrator voltage preset to 2v
    20:07:00.704 -> E (1458) ledc: ledc_channel_config(369): gpio_num argument is invalid
    20:07:00.704 -> touch: FT6336 ready (fw id 0x10 rel 1, lib 0x300E)
    20:07:01.300 -> OK
    20:07:01.333 -> Number of connected sensors: 0
    
    

    It shows "Number of connected sensors: 0" even though I have connected 2 on the same pins.

    What am I doing wrong?



  • Hello @2ndsteve

    I don't think you're doing anything wrong. On ESP32 there seems to be an issue with the function to count devices. See here.

    A simple solution seems to be calling sensors.begin() twice.

    Thanks
    Felix



  • @felmue This was it: works with work(around)!
    Thanks so much.
    Steve.