SHT30-D and SHT31-D Humidity Sensors
The Sensirion SHT31-D [1] sensor reads humidity and temperature with an accuracy of ±2% over the range 0 to 100% RH, and ±0.2 °C over the range 0 to 90°C.
The functionally equivalent Sensirion SHT30-D sensor has an accuracy of ±3% over the range 10% to 90% RH, and ±0.3 °C over the range 0 to 65°C.
They will operate on between 2.4 V and 5.5 V.
A breakout board is available from Adafruit [2]:

They provide two I2C addresses; the default is #x44 or 68.
Reading the humidity and temperature
The following routine reads both the temperature and humidity:
(defun sht31-temp-humid ()
(let ((rdword
(lambda (s)
(logior (ash (read-byte s) 8) (read-byte s)))))
; High repeatability mode
(with-i2c (s #x44)
(write-byte #x24 s)
(write-byte #x00 s)
(delay 20)
(restart-i2c s 5)
(let* ((temp (rdword s))
(checksum (read-byte s))
(humid (rdword s)))
(list
(- (/ (* temp 175) 65535) 45)
(/ (* humid 100) 65535))))))
It returns the values as a list of two floating-point numbers. For example:
> (sht31-temp-humid) (20.132 38.1659)
The last two lines of the routine could probably be rewritten to return 16-bit fixed-point values, to make it compatible with 8/16-bit uLisp platforms.
Enabling the heater
The sensor also incorporates a heater, to combat condensation. Here's a routine to enable or disable the heater:
(defun sht31-heater (on)
(with-i2c (s #x44)
(write-byte #x30 s)
(write-byte (if on #x6D #x66) s)))
To turn the heater on call:
(sht31-heater t)
or to turn if off call:
(sht31-heater nil)
- ^ SHT-3xD Datasheet on Adafruit.
- ^ Adafruit Sensirion SHT31-D Temperature & Humidity Sensor Breakout on Adafruit.
