From 8c2880d718228674c5f46cb1564fe136c59f2dae Mon Sep 17 00:00:00 2001 From: Francesco Truzzi Date: Sat, 7 Mar 2015 14:57:08 +0100 Subject: [PATCH 1/3] Delete README.md --- lua_modules/hdc1000/README.md | 39 ----------------------------------- 1 file changed, 39 deletions(-) delete mode 100644 lua_modules/hdc1000/README.md diff --git a/lua_modules/hdc1000/README.md b/lua_modules/hdc1000/README.md deleted file mode 100644 index 398cccee..00000000 --- a/lua_modules/hdc1000/README.md +++ /dev/null @@ -1,39 +0,0 @@ -HDC1000 NodeMCU module -======================= - -Here's my NodeMCU module for the TI HDC1000 temperature and humidity sensor. It should work with the HDC1008 too but I haven't tested it. - -### Setup your sensor: -First, require it: - -`HDC1000 = require("HDC1000")` - -Then, initialize it: - -`HDC1000.init(sda, scl)` - -Configure it: - -`HDC1000.config()` - -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: - -`HDC1000.config(address, resolution, heater);` - -"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: - -`temperature = HDC1000.getTemp()` in Celsius degrees. - -`humidity = HDC1000.getHumi()` in % - -### Check your battery - -The following code returns true if the battery voltage is <2.8V, false otherwise. - -`isDead = HDC1000.batteryDead();` - -Happy making! Also, check out my Breakout Board and Arduino library for this chip: http://b.truzzi.me/hdc1000-temperature-and-humidity-sensor-breakout-with-arduino-library/. From 1c54cca234db401bd63ad843e84174e8da19fbcd Mon Sep 17 00:00:00 2001 From: ftruzzi Date: Sat, 7 Mar 2015 15:01:20 +0100 Subject: [PATCH 2/3] Added DRDYn pin support. --- lua_modules/hdc1000/HDC1000-example.lua | 3 +- lua_modules/hdc1000/HDC1000.lua | 16 +++++++-- lua_modules/hdc1000/README.md | 47 +++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 lua_modules/hdc1000/README.md diff --git a/lua_modules/hdc1000/HDC1000-example.lua b/lua_modules/hdc1000/HDC1000-example.lua index df7dbd27..fe301dcb 100644 --- a/lua_modules/hdc1000/HDC1000-example.lua +++ b/lua_modules/hdc1000/HDC1000-example.lua @@ -2,8 +2,9 @@ HDC1000 = require("HDC1000") sda = 1 scl = 2 +drdyn = false -HDC1000.init(sda, scl) +HDC1000.init(sda, scl, drdyn) HDC1000.config() -- default values are used if called with no arguments. prototype is config(address, resolution, heater) print(string.format("Temperature: %.2f °C\nHumidity: %.2f %%", HDC1000.getTemp(), HDC1000.getHumi())) diff --git a/lua_modules/hdc1000/HDC1000.lua b/lua_modules/hdc1000/HDC1000.lua index 80f7e499..51e9a44c 100644 --- a/lua_modules/hdc1000/HDC1000.lua +++ b/lua_modules/hdc1000/HDC1000.lua @@ -25,6 +25,7 @@ _G[modname] = M local id = 0 local i2c = i2c local delay = 20000 +local _drdyn_pin local HDC1000_ADDR = 0x40 @@ -69,7 +70,8 @@ function M.batteryDead() end -- initalize i2c -function M.init(sda, scl) +function M.init(sda, scl, drdyn_pin) + _drdyn_pin = drdyn_pin i2c.setup(id, sda, scl, i2c.SLOW) end @@ -84,14 +86,22 @@ end -- outputs temperature in Celsius degrees function M.getHumi() setReadRegister(HDC1000_HUMI) - tmr.delay(delay) + if(_drdyn_pin ~= false) then + gpio.mode(_drdyn_pin, gpio.INPUT) + while(gpio.read(_drdyn_pin)==1) do + end + else tmr.delay(delay) end return(read16()/65535.0*100) end -- outputs humidity in %RH function M.getTemp() setReadRegister(HDC1000_TEMP) - tmr.delay(delay) + if(_drdyn_pin ~= false) then + gpio.mode(_drdyn_pin, gpio.INPUT) + while(gpio.read(_drdyn_pin)==1) do + end + else tmr.delay(delay) end return(read16()/65535.0*165-40) end diff --git a/lua_modules/hdc1000/README.md b/lua_modules/hdc1000/README.md new file mode 100644 index 00000000..bd57b86e --- /dev/null +++ b/lua_modules/hdc1000/README.md @@ -0,0 +1,47 @@ +HDC1000 NodeMCU module +======================= + +Here's my NodeMCU module for the TI HDC1000 temperature and humidity sensor. It should work with the HDC1008 too but I haven't tested it. + +### Setup your sensor: +First, require it: + +`HDC1000 = require("HDC1000")` + +Then, initialize it: + +<<<<<<< HEAD +`HDC1000.init(sda, scl, drdyn)` + +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. + +`HDC1000.init(sda, scl, false)` +======= +`HDC1000.init(sda, scl)` +>>>>>>> origin/master + +Configure it: + +`HDC1000.config()` + +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: + +`HDC1000.config(address, resolution, heater);` + +"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: + +`temperature = HDC1000.getTemp()` in Celsius degrees. + +`humidity = HDC1000.getHumi()` in % + +### Check your battery + +The following code returns true if the battery voltage is <2.8V, false otherwise. + +`isDead = HDC1000.batteryDead();` + +Happy making! Also, check out my Breakout Board and Arduino library for this chip: http://b.truzzi.me/hdc1000-temperature-and-humidity-sensor-breakout-with-arduino-library/. From c96c8d570a1c710853e58d737172e6d72185ee4d Mon Sep 17 00:00:00 2001 From: Francesco Truzzi Date: Sat, 7 Mar 2015 15:04:42 +0100 Subject: [PATCH 3/3] Update README.md --- lua_modules/hdc1000/README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lua_modules/hdc1000/README.md b/lua_modules/hdc1000/README.md index bd57b86e..aa04897d 100644 --- a/lua_modules/hdc1000/README.md +++ b/lua_modules/hdc1000/README.md @@ -10,15 +10,11 @@ First, require it: Then, initialize it: -<<<<<<< HEAD `HDC1000.init(sda, scl, drdyn)` 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. `HDC1000.init(sda, scl, false)` -======= -`HDC1000.init(sda, scl)` ->>>>>>> origin/master Configure it: