Si7021 Module¶
| Since | Origin / Contributor | Maintainer | Source |
|---|---|---|---|
| 2017-04-19 | fetchbot | fetchbot | si7021.c |
This module provides access to the Si7021 humidity and temperature sensor.
si7021.firmware()¶
Read the internal firmware revision of the Si7021 sensor.
Syntax¶
si7021.firmware()
Parameters¶
none
Returns¶
fwrev Firmware version
* 0xFF Firmware version 1.0
* 0x20 Firmware version 2.0
Example¶
local sda, scl = 6, 5
i2c.setup(0, sda, scl, i2c.SLOW) -- call i2c.setup() only once
si7021.setup()
fwrev = si7021.firmware()
print(string.format("FW: %X\r\n", fwrev))
si7021.read()¶
Syntax¶
si7021.read()
Parameters¶
none
Returns¶
humhumidity (see note below)temptemperature (see note below)hum_dechumidity decimaltemp_dectemperature decimal
Note
If using float firmware then hum and temp are floating point numbers. On an integer firmware, the final values have to be concatenated from hum and hum_dec / temp and temp_dec.
Example¶
local sda, scl = 6, 5
i2c.setup(0, sda, scl, i2c.SLOW) -- call i2c.setup() only once
si7021.setup()
hum, temp, hum_dec, temp_dec = si7021.read()
-- Integer firmware using this example
print(string.format("Humidity:\t\t%d.%03d\nTemperature:\t%d.%03d\n", hum, hum_dec, temp, temp_dec))
-- Float firmware using this example
print("Humidity: "..hum.."\n".."Temperature: "..temp)
si7021.serial()¶
Read the individualized 64-bit electronic serial number of the Si7021 sensor.
Syntax¶
si7021.serial()
Parameters¶
none
Returns¶
sna32-bit serial number part asnb32-bit serial number part b, upper byte contains the device identification0x00or0xFFengineering samples0x0D13Si70130x1420Si70200x1521Si7021
Example¶
local sda, scl = 6, 5
i2c.setup(0, sda, scl, i2c.SLOW) -- call i2c.setup() only once
si7021.setup()
sna, snb = si7021.serial()
print(string.format("SN:\t\t%X%X\nDevice:\tSi70%d", sna, snb, bit.rshift(snb,24)))
si7021.setting()¶
Settings for the sensors configuration register to adjust measurement resolution, on-chip heater and read the supply voltage status.
Syntax¶
si7021.setting(RESOLUTION[, HEATER, HEATER_SETTING])
Parameters¶
RESOLUTIONsi7021.RH12_TEMP14Relative Humidity 12 bit - Temperature 14 bit (default)si7021.RH08_TEMP12Relative Humidity 8 bit - Temperature 12 bitsi7021.RH10_TEMP13Relative Humidity 10 bit - Temperature 13 bitsi7021.RH11_TEMP11Relative Humidity 11 bit - Temperature 11 bit
HEATERoptionalsi7021.HEATER_ENABLEOn-chip Heater Enablesi7021.HEATER_DISABLEOn-chip Heater Disable (default)
HEATER_SETTINGoptional0x00-0x0F3.09 mA - 94.20 mA
Returns¶
resolution0Relative Humidity 12 bit - Temperature 14 bit1Relative Humidity 8 bit - Temperature 12 bit2Relative Humidity 10 bit - Temperature 13 bit3Relative Humidity 11 bit - Temperature 11 bit
vdds0VDD OK (1.9V - 3.6V)1VDD LOW (1.8V - 1.9V)
heater0Disabled1Enabled
heater_setting0-15
Example¶
local id, sda, scl = 0, 6, 5
i2c.setup(id, sda, scl, i2c.SLOW) -- call i2c.setup() only once
si7021.setup()
res, vdds, heater, heater_set = si7021.setting(si7021.RH12_TEMP14)
res, vdds, heater, heater_set = si7021.setting(si7021.RH12_TEMP14, si7021.HEATER_ENABLE, 0x01)
si7021.setup()¶
Initializes the device on fixed I²C device address (0x40).
Syntax¶
si7021.setup()
Parameters¶
none
Returns¶
nil
Example¶
local sda, scl = 6, 5
i2c.setup(0, sda, scl, i2c.SLOW) -- call i2c.setup() only once
si7021.setup()