-
-
Save voodootikigod/7b2f4076bf1b0d519708 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Temperature and Humidity Monitor using Honeywell HIH6130 sensor | |
//hardware.configure(I2C1_89); | |
local i2c = hardware.i2c89; | |
i2c.configure(CLOCK_SPEED_100_KHZ); | |
local out_temp = OutputPort("Temperature"); | |
local out_humid = OutputPort("Humidity"); | |
imp.configure("Temp/Humid", [],[out_temp, out_humid]); | |
address <- 0x27; | |
local function getsample() { | |
// Start conversion | |
i2c.write(address, ""); | |
// Wait at least 36ms | |
imp.sleep(0.05); | |
// Read out temperature and humidity, zero length subaddress means the write | |
// subaddr phase will be totally skipped and we'll just do the read | |
local th = i2c.read(address, "", 4); | |
server.log(th); | |
// note data will be marked as stale because each read kicks off another | |
// cycle as we always do a write-before-read on i2c | |
// hence, we need to mask top bits of humidity byte | |
// Form temp and humidity | |
local temperature = ((((th[2] << 6 ) | (th[3] >> 2)) * 165) / 16383.0) - 40; | |
local humidity = ((((th[0] & 0x3F) << 8 ) | (th[1] )) / 163.83 ); | |
// log and print | |
server.log(format("temperature %.2fC humidity %.2f%%",temperature, humidity)); | |
server.show(format("%.2fC %.2f%%", temperature, humidity)); | |
//Send data to server | |
out_temp.set(temperature); | |
out_humid.set(humidity); | |
} | |
// Need to do this just once to configure ATSHA: nora only! | |
//hardware.configureimpee({ pin3v3 = 1 }); | |
//hardware.configureimpee({ polarity3v3 = 1 }); | |
// Get a sample, then sleep | |
getsample(); | |
server.sleepfor((5*60)-3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment