Examples for NODEMCU V2 + DHT22/HTS221

Hello everyone,

I am starting to learn ZERYNTH STUDIO.

I connected the board NODEMCU V2 and verified the sample programs as BLINK. All right.

At this point I would like to connect the DHT22 or HTS221 sensor and read the temperature / humidity on the terminal or 20x4 LCD.

Unfortunately the sample program loaded me an error (see listing).

Unfortunately I can not understand how I can fix the code for the board NODEMCU V2.

Someone in the Forum could direct me to a NODEMCU V2 program connected to a DHT22. I also find a HTS221 sensor for my project.

Thank you

DHT22.JPG 119.5K


  • floydfloyd Member
    hi @lucio1960 ;
    here you can find more info about the pin mapping and function naming in Zerynth ;

    in your particular case you are trying to access a feature ICU (Input Capture Unit) that isn't available on pin D3 of the NODEMCU V2. ICU is required by the DHT22 sensor lib for reading the sensor incoming data.

    Unfortunately the ESP8266 doesn't support ICU thus, the DHT22 driver can't work on this board.

    more info here on the feature available on the ESP8266 NODEMCU V2 board here

    In future we could release an emulated version of the ICU driver for the ESP8266 based on interrupts that will enable this feature also on the NODEMCU V2.

    We'll keep you posted
    Daniele Mazzei
    Zerynth Chief System Architect
  • Hello Daniele,

    this is a big limit that should be fixed ASAP because the DHT22 sensor is the absolute King of the makers who want to make a project with a temperature and humidity sensors.

    In the past I have not had problems with some applications NODEMCU V2 and DHT22 both ARDUINO IDE with MBED ARM.

    ZERYNTH 2.0.1 should definitely fill that gap :)
  • floydfloyd Member
    hello @lucio1960 ;
    i am afraid, this isn't a limit of Zerynth but of the ESP8266 hardware  >:)
    The driver for the DHT22 has been developed using ICU, one of the latest and most powerful feature of the new MCU families that unfortunately isn't supported by the ESP8266. 

    In Arduino and MBED you probably used an interrupts based driver for the DHT22 that works fine for most of the cases but is very far from the state of the art of pro embedded technology.

    btw, we'll do our best to workaround this :)

    ...I am waiting for the ESP32... 
    Daniele Mazzei
    Zerynth Chief System Architect
  • Thank you very much Daniele, then I await good news

  • Any progress on DHT 22 support? 
  • anbaanba Member
    Hi robmarkcole,
    you can find a Zerynth DHT22 module at this link. Just download and put it in your project folder.
    The same module will be available as a community library in Zerynth Studio Package Manager pretty soon.

    It must be noted that this DHT22 module requires an ICU peripheral, no workaround has been implemented (... at the moment).
    Was that what you were looking for?
    Andrea Baù
    Zerynth Support Team
  • Hi Andrea, thanks for the link. In the context of a nodeMCU, what is an ICU peripheral?
  • Hi makerns,

    Every source code related to the Zerynth ecosystem is optimized for the embedded world; our version of DHT library is based on the ICU (Input Capture Unit) peripheral, feature strictly linked to the microcontroller hardware timers.

    Unfortunately, ESP8266 has not this feature but very soon it will be available on the ESP8266 successor, ESP32.

    There is a way a little bit complex to enable ESP8266 to interact with DHT sensor, it regards to query the sensor by polling with the correct timing.
    To do that you have to write manually the correct timing for interacting with the sensor; sensor timing works with microseconds as time unit and every Python script in Zerynth allow you to use at most milliseconds as time unit because of the RTOS installed inside the Zerynth Virtual Machine.

    The only solution is to implement this feature in C language that permits you to execute time operation with microseconds as time unit.

    Hope this can help you :)
    Matteo Cipriani
    Zerynth Support Team
  • floydfloyd Member
    Daniele Mazzei
    Zerynth Chief System Architect
Sign In or Register to comment.

ZERYNTH Community

@ 2016, all rights reserved.