in electronics

NodeMCU library for the TI HDC1000 sensor!

It’s been a while since I received my NodeMCU development board but I have only been able to get my hands on it lately.

I soon downloaded the ESP uploader and after reading some Lua docs (and finding out some weird things such as that the “not equal” operator is actually “~=” ) I started writing my own code for the board.

Writing and uploading software to the board is easy and fast. The only concern is that after flashing the NoceMCU firmware you are not left with a lot of memory available.

So I wrote a NodeMCU library (they call them modules) for the TI HDC1000. The code has been merged to the dev branch of the nodemcu firmware and it should go to the master soon, but I’ve set up a repo too (click!).

Download and upload the library

Click here to download the latest library.

You then need to connect to your ESP8266 dev board and upload the “HDC1000.lua” file to it. This is pretty straightforward using ESPlorer.

After connecting to your board, upload the "HDC1000.lua" file.

After connecting to your board, upload the “HDC1000.lua” file.

Setup your sensor

First, require it:

Then, initialize it:

If you don’t want to use the DRDYn pin, set it to false: a 20ms delay will be automatically set after each read request.

 

Reading temperature with the DRDYn pin off.

Reading temperature with the DRDYn pin off.

Reading temperature with the DRDYn pin on.

Reading temperature with the DRDYn pin on.

Configure it:

Default options set the address to 0x40 and enable both temperature and humidity readings at 14-bit resolution, with the integrated heater on. You can change them by initializing your sensor like this:

“resolution” can be set to 14 bits for both temperature and humidity (0x00 – default) 11 bits for temperature (0x40), 11 bits for humidity (0x01), 8 bits for humidity (0x20) “heater” can be set to ON (0x20 – default) or OFF (0x00)

Read some values

You can read temperature and humidity by using the following commands:

in Celsius degrees.

in %RH

Check your battery

The following code returns true if the battery voltage is <2.8V, false otherwise.

Complete example code

 

Share on FacebookTweet about this on TwitterShare on Google+Share on RedditEmail this to someoneFlattr the authorShare on Tumblr

Write a Comment

Comment

 

Loading Disqus Comments ...
Loading Facebook Comments ...