Electric Dollar Store
The LM75B is a temperature-to-digital converter with an I²C interface. The temperature register is an 11-bit signed quantity, giving a resolution of 0.125 °C.
import sys
import time
from i2cdriver import I2CDriver, EDS
if __name__ == '__main__':
i2 = I2CDriver(sys.argv[1])
d = EDS.Temp(i2)
for i in range(20):
celsius = d.read()
fahrenheit = celsius * 9/5 + 32
sys.stdout.write("%.1f C %.1f F\n" % (celsius, fahrenheit))
time.sleep(.1)
#include <Wire.h>
float temp_read()
{
Wire.requestFrom(0x48, 2);
byte h = Wire.read();
byte l = Wire.read();
return ((h << 3) | (l >> 5)) * 0.125;
}
void setup() {
Serial.begin(115200);
Wire.begin();
}
void loop() {
Serial.println(temp_read());
delay(20);
}
from machine import I2C
import struct
import time
class Temp:
""" TEMP is an LM75B temperature sensor """
def __init__(self, i2, a = 0x48):
self.i2 = i2
self.a = a
def regrd(self, r):
return struct.unpack(">h", self.i2.readfrom_mem(self.a, 0, 2))[0]
def read(self):
return (self.regrd(0) >> 5) * 0.125
def main():
i2 = I2C(1, freq = 100000)
print(i2.scan())
d = Temp(i2)
while True:
print("%.3f C" % d.read())
time.sleep(.05)
Default I²C address | 0x48 (0b1001000 ) |
Current consumption (typ.) | 5 mA |
Vcc | 3.3 V |