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



hi @lucio1960 
here you can find more info about the pin mapping and function naming in Zerynth https://doc.zerynth.com/core.zerynth.stdlib/r1.0.8/pin_mapping.html 

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 http://doc.zerynth.com/board.zerynth.nodemcu2/r1.0.13/

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

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 :)


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 :slight_smile:

…I am waiting for the ESP32… 


Thank you very much Daniele, then I await good news



Any progress on DHT 22 support? 


Hi robmarkcole,
you can find a Zerynth DHT22 module at this link. Just download dht22.py 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?


Hi Andrea, thanks for the link. In the context of a nodeMCU, what is an ICU peripheral?


here it is :slight_smile:


esp8266 works with DHT and Arduino library 


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 :slight_smile:


here how to write a C library for Zerynth https://docs.zerynth.com/latest/official/core.zerynth.stdlib/docs/clang.html