Help needed with DHT11 temperature and humidity sensor

Posted on
  • Hello,
    I am trying to get DHT11(temperature and humidity) sensor working with Espruino on ESP32. I get the below output, which as per the documentation means no data is being received.

    {"err":true,"checksumError":false,"raw":­"","temp":-1,"rh":-1}
    

    Code

    var dht = require("DHT11").connect(D17);
    
    function onInit() {
        setInterval(function () {
            dht.read(function (a) {
                console.log(JSON.stringify(a));
            });
        }, 3000);
    }
    
    onInit();
    

    Interestingly, with the same wiring DHT11 works fine using "Arduino core for ESP32". Not sure what I am doing wrong in the Espruino.

    This is the board that I am using https://wiki.wemos.cc/products:lolin32:l­olin32
    Pin out - https://arduino-projekte.info/wp-content­/uploads/2017/07/lolin32_pinout.png

    Thanks in advance.

  • Which firmware for ESP32 are you using? I know some older ones had trouble with setWatch, which this module uses.

  • Thanks for the reply. Much appreciated.

    I am using 1v95 firmware. I have also downloaded the latest "espruino_1v95_esp32.bin" from http://www.espruino.com/binaries/travis/­master/
    but no success.

  • @Wilberforce do you have any thoughts on this one? I'm sure DHT11 has been working in the past?

  • Yes - I'm sure someone on here recently used this device with the esp32....

    The settimeout bug you mentioned rebooted the device, so it's not related to this.

  • http://forum.espruino.com/comments/13155­158/

    Perhaps the difference is due to pull ups on the pins?

    Try an external resistor?

  • Hello,
    I originally had a 10k pull-up resistor between the Data and Vcc pins. I have now tried 1K resistor but that has not helped either.

    Interestingly, I have observed that I either get No data or a "Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled." based on which pin I choose.

    e.g.

        pin 15 - {"temp":-1,"rh":-1}
        pin 22 - Guru Meditation Error of type IllegalInstruction occurred on core  0
        pin 16 - Guru Meditation Error of type IllegalInstruction occurred on core  0
    

    I think this person is facing the same issue. http://forum.espruino.com/conversations/­316936/

    Thanks a lot.

  • Where did you get D17 from?

    A quick google here:

    https://github.com/search?utf8=%E2%9C%93­&q=higrow&type=

    The mongoose project uses D22. It could be the same - no way of knowing without trying ...

    You might need to trace from the dht11 to see what pin it is connected to.

  • I believe I have confused you, sorry. I am using an external DHT11(not integrated with ESP32), but I get the same error as the other person(with integrated DHT11) if I connect DHT11 to Pin 22.

  • Looking at the wiring here: http://randomnerdtutorials.com/esp32-dht­11-dht22-temperature-humidity-web-server­-arduino-ide/

    There are wiring to io16. so you would use D16.

  • Thanks for your reply. I have already tried pin D16 (comment #7) and I get an error "Guru Meditation Error of type IllegalInstruction occurred on core 0".

    I am powering DHT11 with 5 volts.

  • I am powering DHT11 with 5 volts.

    Do you have common ground beterrn the device and the signal line? Stick with d15 I'd I think I should not crashing.

  • Thanks to @Gordon, there is now a fix on the ESP32 if the pin > D15, so this should now work for D16 or D22, which ever pin you have connected too.

    The firmware bin file can be fetched here:

    http://www.espruino.com/binaries/travis/­deee7d431ee31825fab762bf2c7ec2e86b994455­/espruino_1v95_esp32.tgz

    This is now working:

    setWatch(function(e) {console.log("Button pressed",e);}, D22, { repeat: true, edge: 'rising' });
    
  • Thanks a lot @Gordon and @Wilberforce. I have tried the new code. Good news is that I no longer get "Guru Meditation error", but I get data like below.

    I understand that DHT11 now works for @Gustav on ESP32. There is as much time that you guys can spend on this, I have read that DHT11 is not the best sensor as well. I am pretty sure this works flawlessly on the official boards. I'll try to get myself one.

    Thanks a lot for all the help. Really appreciate it.

    {"err":true,"checksumError":true,"raw":"­101010100110000000000010111000","temp":-­1,"rh":-1}
    {"err":true,"checksumError":false,"raw":­"","temp":-1,"rh":-1}
    {"err":true,"checksumError":true,"raw":"­1010101001100000000000101110000000001101­0101","temp":-1,"rh":-1}
    {"err":true,"checksumError":false,"raw":­"0","temp":-1,"rh":-1}
    {"err":true,"checksumError":false,"raw":­"0","temp":-1,"rh":-1}
    {"raw":"01010100110000000000010111000000­00011010101","rh":83,"temp":23}
    {"err":true,"checksumError":false,"raw":­"","temp":-1,"rh":-1}
    {"err":true,"checksumError":false,"raw":­"0","temp":-1,"rh":-1}
    {"err":true,"checksumError":true,"raw":"­1010101001000000000000101110000","temp":­-1,"rh":-1}
    {"err":true,"checksumError":false,"raw":­"0","temp":-1,"rh":-1}
    {"err":true,"checksumError":false,"raw":­"","temp":-1,"rh":-1}
    {"err":true,"checksumError":false,"raw":­"","temp":-1,"rh":-1}
    {"raw":"10101010010000000000001011100000­000011010011","rh":169,"temp":11}
    
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Help needed with DHT11 temperature and humidity sensor

Posted by Avatar for Chaapu @Chaapu

Actions