File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 )
Original file line number Diff line number Diff line change 1+ # NodeMCU EC-12, LM75 Temperature sensor, and MicroPython
You can’t perform that action at this time.
0 commit comments