EP-0031: Difference between revisions
Line 50: | Line 50: | ||
==Examples== | ==Examples== | ||
*Shell scripts:<br> | *Shell scripts:<br> | ||
You can create a file called lm75.sh and edit as following:<br> | |||
<code>#!/bin/bash<br> | <code>#!/bin/bash<br> | ||
while true<br> | while true<br> | ||
Line 56: | Line 57: | ||
sleep 1<br> | sleep 1<br> | ||
done</code><br> | done</code><br> | ||
and set an execute right to this file:<br> | |||
<code>chmod +x lm75.sh && bash lm75.sh</code><br> | |||
---- | ---- | ||
*C code: You can login to your Raspberry Pi and open a terminal, and then download the zip package from this link below: | *C code: You can login to your Raspberry Pi and open a terminal, and then download the zip package from this link below: | ||
Line 70: | Line 73: | ||
<br style="clear:both;"> | <br style="clear:both;"> | ||
---- | ---- | ||
*Python running in command line: | *Python running in command line:<br> | ||
* | **Create a file called LM75.py as below: | ||
<pre> | |||
import time | |||
import smbus | |||
LM75_ADDRESS = 0x48 | |||
LM75_TEMP_REGISTER = 0 | |||
LM75_CONF_REGISTER = 1 | |||
LM75_THYST_REGISTER = 2 | |||
LM75_TOS_REGISTER = 3 | |||
LM75_CONF_SHUTDOWN = 0 | |||
LM75_CONF_OS_COMP_INT = 1 | |||
LM75_CONF_OS_POL = 2 | |||
LM75_CONF_OS_F_QUE = 3 | |||
class LM75(object): | |||
def __init__(self, mode=LM75_CONF_OS_COMP_INT, address=LM75_ADDRESS, busnum=1): | |||
self._mode = mode | |||
self._address = address | |||
self._bus = smbus.SMBus(busnum) | |||
def regdata2float (self, regdata): | |||
return (regdata / 32.0) / 8.0 | |||
def toFah(self, temp): | |||
return (temp * (9.0/5.0)) + 32.0 | |||
def getTemp(self): | |||
raw = self._bus.read_word_data(self._address, LM75_TEMP_REGISTER) & 0xFFFF | |||
raw = ((raw << 8) & 0xFF00) + (raw >> 8) | |||
return self.toFah(self.regdata2float(raw)) | |||
</pre> | |||
and then create another file called test.py:<br> | |||
<pre> | |||
import LM75 | |||
sensor = LM75.LM75() | |||
print sensor.getTemp() | |||
</pre> | |||
**execute by this command: <br> | |||
<code>python test.py</code> | |||
[[File:Lm75python.png|thumb|left|600px]] | |||
<br style="clear:both;"> | |||
---- | |||
==Purchase Links== | |||
[[File:shopping_car.png|left|21px]][http://www.52pi.com 52Pi Store] |
Revision as of 16:00, 22 June 2016
=Raspberry Pi LM75B Temperature Sensor v1.0 SKU:EP-0031
Product Feature
- 9bit high resolution ADC in chip
- Temperature resolution of 0.125°C.
- I2C bus plug and play
- Compatible with all kind of development board.
Port
- Raspberry Pi GPIO pins
Product Parameters
- Working voltage: 1.8V-5.5V, accuracy can be up to 0.5 when working voltage is higher than 3v.
- Temperatures range from−55°C to +125°C
- Supply current of 3.5µA in shutdown mode for power conservation
- Temperature accuracy of: ±2°C from−25°C to +100°C
- Temperature accuracy of: ±3°C from−55°C to +125°C
Typical Application
- Industrial controllers
- Environmental monitoring
- Smart home
- Interactive devices
How to wire it up
How to use it
- i2c-tools package is required, so you should install it before you get temperature as following command:
sudo apt-get update && sudo apt-get -y install i2c-tools
- Enable I2c function by editing /boot/config.txt,make sure it contain this two parameter as following:
device_tree=bcm2710-rpi-3-b.dtb
dtparam=i2c_arm=on
- Or you can use this command to enable I2C:
- Or you can use this command to enable I2C:
sudo raspi-config
- Select as this picture, then you can enable I2C easily.
- Please Remember to reboot your Raspberry Pi.
- After rebooting, please open a terminal and input this command to get temperature:
i2cget -y 1 0x48 0x00 w |awk '{printf("%0.1f C\n",(a=((("0x"substr($1,5,2)substr($1,3,1))*0.0625)+0.1) )>128?a-256:a)}'
Examples
- Shell scripts:
You can create a file called lm75.sh and edit as following:
#!/bin/bash
while true
do
i2cget -y 1 0x48 0x00 w | awk '{printf("%.1f C.\n", (a=((("0x"substr($1,5,2)substr($1,3,1))*0.0625)+0.1) )>128?a-256:a)}'
sleep 1
done
and set an execute right to this file:
chmod +x lm75.sh && bash lm75.sh
- C code: You can login to your Raspberry Pi and open a terminal, and then download the zip package from this link below:
File:LM75 C.tar.gz.zip
unzip it and compile it.
unzip LM75_C.tar.gz.zip
tar -xf LM75_C.tar.gz
cd LM75_C/
make
./test.o
- Python running in command line:
- Create a file called LM75.py as below:
import time import smbus LM75_ADDRESS = 0x48 LM75_TEMP_REGISTER = 0 LM75_CONF_REGISTER = 1 LM75_THYST_REGISTER = 2 LM75_TOS_REGISTER = 3 LM75_CONF_SHUTDOWN = 0 LM75_CONF_OS_COMP_INT = 1 LM75_CONF_OS_POL = 2 LM75_CONF_OS_F_QUE = 3 class LM75(object): def __init__(self, mode=LM75_CONF_OS_COMP_INT, address=LM75_ADDRESS, busnum=1): self._mode = mode self._address = address self._bus = smbus.SMBus(busnum) def regdata2float (self, regdata): return (regdata / 32.0) / 8.0 def toFah(self, temp): return (temp * (9.0/5.0)) + 32.0 def getTemp(self): raw = self._bus.read_word_data(self._address, LM75_TEMP_REGISTER) & 0xFFFF raw = ((raw << 8) & 0xFF00) + (raw >> 8) return self.toFah(self.regdata2float(raw))
and then create another file called test.py:
import LM75 sensor = LM75.LM75() print sensor.getTemp()
- execute by this command:
- execute by this command:
python test.py