DHT11 sensor dose not work on ESP8266 VM

Issue #252 resolved
Tom Ming created an issue

Hi @John Maloney ,

I attach a DHT11 sensor to pin D6 with D1 mini board,It can not read temperature and humidity ,the Microblocks IDE shows errors as below. But the sensor works well with ESP32 board.

BTW ,The errors reported on Chrome console

Bad message start byte; should be 250 or 251 but is: 13 
emModule.js:18 
emModule.js:18  ets Jan  8 2013,rst cause:4, boot mode:(3,6)
emModule.js:18 
emModule.js:18 wdt reset
emModule.js:18 lo 
emModule.js:18 Bad message start byte; should be 250 or 251 but is: 97 
emModule.js:18 ad 0x4010f000, len 3460, room 16 
emModule.js:18 tail 4
emModule.js:18 chksum 0xcc
emModule.js:18 load 0x3fff20b8, len 40, room 4 
emModule.js:18 tail 4
emModule.js:18 chksum 0xc9
emModule.js:18 csum 0xc9
emModule.js:18 v0005b4f0
emModule.js:18 ~ld
emModule.js:18 󔿘 
emModule.js:18 Welcome to MicroBlocks! 
emModule.js:18 Restored 9 scripts 
emModule.js:18 Started 

Comments (12)

  1. John Maloney repo owner

    The “Bad message start byte” error is normal when ESP boards are reset or powered up. The reason is the the ESP operating system always outputs a bunch of text at startup and that text is not in the form of a board-to-IDE message. But that’s okay – the IDE discards it and skipts to the first real message. Most userss don’t have the console open so they don’t even see the ESP startup message, but we print it because sometimes it provides useful information when debugging.

    So that message is not related to the DHT11 failure.

    A couple of things to check:

    1. the DHT11 should be powered by the 3.3v pin on the D1 mini, NOT the 5v pin, because the GPIO pins use 3.3v
    2. you might try using a different pin such as D1, D2, or D4
    3. use the pin number marked on the board, not the ESP8266 GPIO pin numbers you might see on a pinout

    Note: MicroBlocks remaps the ESP8266 pins to match the numbers printed on the board. The mapping is in ioPrims.cpp:

    #elif defined(ESP8266) || defined(ARDUINO_ESP8266_WEMOS_D1MINI)
    
        #define BOARD_TYPE "ESP8266"
        #define DIGITAL_PINS 9
        #define ANALOG_PINS 1
        #define TOTAL_PINS 18 // A0 is pin 17
        static const int analogPin[] = {A0};
        static const char digitalPin[9] = {16, 5, 4, 0, 2, 14, 12, 13, 15};
        #define PIN_LED LED_BUILTIN
        #define PIN_BUTTON_A 0
        #define INVERT_USER_LED true
    

    The mapping is given by the digitalPin array. The pin marked D0 is GPIO16, the one marked D1 is GPIO5, etc.

  2. Tom Ming reporter

    Hi @John Maloney ,

    I understand the pin numbers on D1 mini board, eg. D8 mapping to GPIO15.

    I try it again according to your suggestions,but still failure.

    But I could get readings with [Arduino DHT-sensor-library](https://github.com/adafruit/DHT-sensor-library) , the sensor and the board are OK.

    According to the error message 'ets Jan 8 2013,rst cause:4' ,maybe the problem is caused by watch dog RESET of ESP8266.

    Thx.

    Tom Ming

  3. John Maloney repo owner

    Okay, I will see if I can reproduce the problem. DHT signal timing is very critical and requires VM support . There could be an issue with that code on the D1 mini.

  4. Tom Ming reporter

    @John Maloney

    OK, Thx.

    @Wenjie Wu will test it as well.

    Here are the D1 mini board and the DHT11 sensor, that I used.

  5. Dariusz Dorożalski

    Isn't it true that the DHT11 requires a forced pullup state or an external resistor on DATA?

  6. John Maloney repo owner

    Yes, but the pullup is usually built into boards like the one pictured. (And I see two resistors on that board, so pretty sure it has one.) The same DHT module works for him on other boards.

    This could be a timing issue or possibly an electronic issue. If I can reproduce the problem I can look at the signal with an oscilloscope to see what’s going on. But it may be a few days before I can look into it.

  7. John Maloney repo owner

    I found the problem. Just pushed fix to Bitbucket. It will be in the next Pilot release.

  8. Log in to comment