nevermind, seems like there was a bad row on my breadboard. I found it and it works fine now. Thanks for all the great code help from @Boffin and @Eckama
glad you got it working. Anything else you are working on for the imp?
Occasionally the HTU21D became unresponsive when new squirrel code was pushed so I add a SoftReset to the above code. Also note I’ve used a multiplier of 125 in the humidity calculations, not 120 because that’s what’s in my copy of the datasheet.
`class HTU21D {
_i2c = null
static ALSADDR = 0x40
static READTEMP = "\xf3"
static READHUMID = "\xf5"
static RESET = "\xfe"
constructor(i2c) {
_i2c = i2c
_i2c.configure(CLOCK_SPEED_400_KHZ)
}
function GetTemp()
{
_i2c.write(ALSADDR<<1, READTEMP)
imp.sleep(0.05)
local a = _i2c.read(ALSADDR<<1, "", 3)
return (((a[0] << 8) | (a[1] & 0xfc)) * 175.72 / 65536.0) - 46.85
}
function GetHumid()
{
_i2c.write(ALSADDR<<1, READHUMID)
imp.sleep(0.05)
local b = _i2c.read(ALSADDR<<1, "", 3)
return (((b[0] << 8) | (b[1] & 0xf0)) * 125.00 / 65536.0) - 6.00
}
function SoftReset()
{
_i2c.write(ALSADDR<<1, RESET)
imp.sleep(0.15)
}
}
`