Skip to content

Commit d22b7c2

Browse files
committed
initial commit
0 parents  commit d22b7c2

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

LM75.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from machine import Pin, I2C
2+
from math import floor
3+
from time import sleep
4+
5+
D1 = Pin(5) # SCL, GPIO5
6+
D2 = Pin(4) # SDA, GPIO4
7+
8+
9+
class LM75(object):
10+
ADDRESS = 0x48
11+
FREQUENCY = 100000
12+
13+
def __init__(self):
14+
self.i2c = I2C(scl=D1, sda=D2, freq=self.FREQUENCY)
15+
16+
def get_output(self):
17+
"""Return raw output from the LM75 sensor."""
18+
output = self.i2c.readfrom(self.ADDRESS, 2)
19+
return output[0], output[1]
20+
21+
def get_temp(self):
22+
"""Return a tuple of (temp_c, point)."""
23+
temp = self.get_output()
24+
return int(temp[0]), int(temp[1])
25+
26+
27+
def print_temp():
28+
sensor = LM75()
29+
while True:
30+
temperature, point = sensor.get_temp()
31+
print("%s.%s" % (temperature, floor(point / 23)))
32+
sleep(1)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# NodeMCU EC-12, LM75 Temperature sensor, and MicroPython

wiring.png

107 KB
Loading

0 commit comments

Comments
 (0)