2015-05-17 10:57:43 +02:00
# LM92 module
This module adds basic support for the LM92 +-0.33C 12bit+sign temperature sensor. More details in the [datasheet ](http://www.ti.com/lit/ds/symlink/lm92.pdf ).
Works:
2016-01-06 19:05:32 +01:00
- 06/01/2016: Add get/set comparison registers. Thyst, Tlow, Thigh and Tcrit
2015-05-17 10:57:43 +02:00
- getting the temperature
- entering the chip's to shutdown mode (350uA -> 5uA power consumption)
- waking up the chip from shutdown
2018-04-06 17:35:11 +02:00
## Require
2015-05-17 10:57:43 +02:00
```lua
LM92 = require("lm92")
```
## Release
```lua
LM92 = nil
package.loaded["lm92"]=nil
```
2018-04-06 17:35:11 +02:00
## setup()
#### Description
2018-03-12 07:56:07 +01:00
Setting the address for lm92.
2015-05-17 10:57:43 +02:00
2018-04-06 17:35:11 +02:00
#### Syntax
2018-03-12 07:56:07 +01:00
setup(sda, scl, address)
2015-05-17 10:57:43 +02:00
2018-04-06 17:35:11 +02:00
#### Parameters
2015-05-17 10:57:43 +02:00
address: 0x48~0x4b, i2c address (depends on tha A0~A1 pins)
2018-04-06 17:35:11 +02:00
#### Returns
2015-05-17 10:57:43 +02:00
nil
2018-04-06 17:35:11 +02:00
#### Example
2015-05-17 10:57:43 +02:00
```lua
LM92 = require("lm92")
gpio0 = 3
gpio2 = 4
sda = gpio0
scl = gpio2
addr = 0x48
2018-03-12 07:56:07 +01:00
i2c.setup(0, sda, scl, i2c.SLOW) -- call i2c.setup() only once
LM92.setup(addr)
2015-05-17 10:57:43 +02:00
```
2018-04-06 17:35:11 +02:00
## getTemperature()
#### Description
2015-05-17 10:57:43 +02:00
Returns the temperature register's content.
2018-04-06 17:35:11 +02:00
#### Syntax
2015-05-17 10:57:43 +02:00
getTemperature()
2018-04-06 17:35:11 +02:00
#### Parameters
2015-05-17 10:57:43 +02:00
-
2018-04-06 17:35:11 +02:00
#### Returns
2015-05-17 10:57:43 +02:00
Temperature in degree Celsius.
2018-04-06 17:35:11 +02:00
#### Example
2015-05-17 10:57:43 +02:00
```lua
t = LM92.getTemperature()
print("Got temperature: "..t.." C")
```
2018-04-06 17:35:11 +02:00
## wakeup()
#### Description
2015-05-17 10:57:43 +02:00
Makes the chip exit the low power shutdown mode.
2018-04-06 17:35:11 +02:00
#### Syntax
2015-05-17 10:57:43 +02:00
wakeup()
2018-04-06 17:35:11 +02:00
#### Parameters
2015-05-17 10:57:43 +02:00
-
2018-04-06 17:35:11 +02:00
#### Returns
2015-05-17 10:57:43 +02:00
-
2018-04-06 17:35:11 +02:00
#### Example
2015-05-17 10:57:43 +02:00
```lua
LM92.wakeup()
tmr.delay( 1 * 1000 * 1000 )
```
2018-04-06 17:35:11 +02:00
## shutdown()
#### Description
2015-05-17 10:57:43 +02:00
Makes the chip enter the low power shutdown mode.
2018-04-06 17:35:11 +02:00
#### Syntax
2015-05-17 10:57:43 +02:00
shutdown()
2018-04-06 17:35:11 +02:00
#### Parameters
2015-05-17 10:57:43 +02:00
-
2018-04-06 17:35:11 +02:00
#### Returns
2015-05-17 10:57:43 +02:00
-
2018-04-06 17:35:11 +02:00
#### Example
2015-05-17 10:57:43 +02:00
```lua
LM92.shutdown()
```
2016-01-06 19:05:32 +01:00
2018-04-06 17:35:11 +02:00
## setThyst()
#### Description
2016-01-06 19:05:32 +01:00
Set hysteresis Temperature.
2018-04-06 17:35:11 +02:00
#### Syntax
2016-01-06 19:05:32 +01:00
setThyst(data_wr)
2018-04-06 17:35:11 +02:00
#### Parameters
2016-01-06 19:05:32 +01:00
data_wr: 130~-55 ºC, hysteresis Temperature
2018-04-06 17:35:11 +02:00
#### Returns
2016-01-06 19:05:32 +01:00
nil
2018-04-06 17:35:11 +02:00
#### Example
2016-01-06 19:05:32 +01:00
```lua
LM92.setThyst(3)
```
2018-04-06 17:35:11 +02:00
## setTcrit()
#### Description
2016-01-06 19:05:32 +01:00
Set Critical Temperature.
2018-04-06 17:35:11 +02:00
#### Syntax
2016-01-06 19:05:32 +01:00
setTcrit(data_wr)
2018-04-06 17:35:11 +02:00
#### Parameters
2016-01-06 19:05:32 +01:00
data_wr: 130~-55 ºC, Critical Temperature
2018-04-06 17:35:11 +02:00
#### Returns
2016-01-06 19:05:32 +01:00
nil
2018-04-06 17:35:11 +02:00
#### Example
2016-01-06 19:05:32 +01:00
```lua
LM92.setTcrit(100.625)
```
2018-04-06 17:35:11 +02:00
## setTlow()
#### Description
2016-01-06 19:05:32 +01:00
Set Low Window Temperature.
2018-04-06 17:35:11 +02:00
#### Syntax
2016-01-06 19:05:32 +01:00
setTlow(data_wr)
####Parameters
data_wr: 130~-55 ºC, Low Window Temperature
2018-04-06 17:35:11 +02:00
#### Returns
2016-01-06 19:05:32 +01:00
nil
2018-04-06 17:35:11 +02:00
#### Example
2016-01-06 19:05:32 +01:00
```lua
LM92.setTlow(32.25)
```
2018-04-06 17:35:11 +02:00
## setThigh()
2016-01-06 19:05:32 +01:00
####Description
Set High Window Temperature.
2018-04-06 17:35:11 +02:00
#### Syntax
2016-01-06 19:05:32 +01:00
setThigh(data_wr)
2018-04-06 17:35:11 +02:00
#### Parameters
2016-01-06 19:05:32 +01:00
data_wr: 130~-55 ºC, High Window Temperature
2018-04-06 17:35:11 +02:00
#### Returns
2016-01-06 19:05:32 +01:00
nil
####Example
```lua
LM92.setThigh(27.5)
```
2018-04-06 17:35:11 +02:00
## getThyst()
#### Description
2016-01-06 19:05:32 +01:00
Get hysteresis Temperature.
2018-04-06 17:35:11 +02:00
#### Syntax
2016-01-06 19:05:32 +01:00
getThyst()
2018-04-06 17:35:11 +02:00
#### Parameters
2016-01-06 19:05:32 +01:00
--
2018-04-06 17:35:11 +02:00
#### Returns
2016-01-06 19:05:32 +01:00
Hysteresis Temperature in degree Celsius.
2018-04-06 17:35:11 +02:00
#### Example
2016-01-06 19:05:32 +01:00
```lua
t = LM92.getThyst()
print("Got hysteresis temperature: "..t.." C")
```
2018-04-06 17:35:11 +02:00
## getTcrit()
#### Description
2016-01-06 19:05:32 +01:00
Get Critical Temperature.
2018-04-06 17:35:11 +02:00
#### Syntax
2016-01-06 19:05:32 +01:00
getTcrit()
2018-04-06 17:35:11 +02:00
#### Parameters
2016-01-06 19:05:32 +01:00
--
2018-04-06 17:35:11 +02:00
#### Returns
2016-01-06 19:05:32 +01:00
Critical Temperature in degree Celsius.
2018-04-06 17:35:11 +02:00
#### Example
2016-01-06 19:05:32 +01:00
```lua
t = LM92.getTcrit()
print("Got Critical temperature: "..t.." C")
```
2018-04-06 17:35:11 +02:00
## getTlow()
#### Description
2016-01-06 19:05:32 +01:00
Get Low Window Temperature.
2018-04-06 17:35:11 +02:00
#### Syntax
2016-01-06 19:05:32 +01:00
getTlow()
2018-04-06 17:35:11 +02:00
#### Parameters
2016-01-06 19:05:32 +01:00
--
2018-04-06 17:35:11 +02:00
#### Returns
2016-01-06 19:05:32 +01:00
Low Window Temperature in degree Celsius.
2018-04-06 17:35:11 +02:00
#### Example
2016-01-06 19:05:32 +01:00
```lua
t = LM92.getTlow()
print("Got Low Window temperature: "..t.." C")
```
2018-04-06 17:35:11 +02:00
## getThigh()
#### Description
2016-01-06 19:05:32 +01:00
Get High Window Temperature.
2018-04-06 17:35:11 +02:00
#### Syntax
2016-01-06 19:05:32 +01:00
getThigh()
2018-04-06 17:35:11 +02:00
#### Parameters
2016-01-06 19:05:32 +01:00
--
2018-04-06 17:35:11 +02:00
#### Returns
2016-01-06 19:05:32 +01:00
High Window Temperature in degree Celsius.
2018-04-06 17:35:11 +02:00
#### Example
2016-01-06 19:05:32 +01:00
```lua
t = LM92.getThigh()
print("Got High Window temperature: "..t.." C")
```
2018-04-06 17:35:11 +02:00
## Full example
```lua
2016-01-06 19:05:32 +01:00
--node.compile("lm92.lua")
LM92 = require("lm92")
gpio0 = 3
gpio2 = 4
sda = gpio0
scl = gpio2
addr = 0x48
2018-03-12 07:56:07 +01:00
i2c.setup(0, sda, scl, i2c.SLOW) -- call i2c.setup() only once
LM92.setup(addr)
2016-01-06 19:05:32 +01:00
t = LM92.getTemperature()
print("Got temperature: "..t.." C")
--Seting comparison temperatures
LM92.setThyst(3)
LM92.setTcrit(40.75)
LM92.setTlow(28.5)
LM92.setThigh(31.625)
t = LM92.getThyst()
print("Got hyster: "..t.." C")
t = LM92.getTcrit()
print("Got Crit: "..t.." C")
t = LM92.getTlow()
print("Got Low: "..t.." C")
t = LM92.getThigh()
print("Got High: "..t.." C")
2018-04-06 17:35:11 +02:00
```
2016-01-06 19:05:32 +01:00
2015-05-17 10:57:43 +02:00
#### TODO:
- add full support of the features, including interrupt and critical alert support