File tree 4 files changed +69
-2
lines changed
4 files changed +69
-2
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,6 @@ __pycache__/
8
8
9
9
# Distribution / packaging
10
10
.Python
11
- build /
12
11
develop-eggs /
13
12
dist /
14
13
downloads /
Original file line number Diff line number Diff line change 1
1
# esp-sht3x-micropython
2
- A SHT3x (SHT30/31/35) Lib for esp8266/esp32 with micropython.
2
+ A SHT3x (SHT30/31/35) Lib for esp8266/esp32 with MicroPython.
3
+
4
+ If you are using pyboard or another board, please modify the usage of ` Pin ` and ` I2C ` .
5
+
6
+ ## Usage
7
+
8
+ ``` python
9
+ from sht3x import SHT3x_Sensor
10
+
11
+ sht3x_sensor = SHT3x_Sensor(freq = 100000 , sdapin = 5 , sclpin = 4 )
12
+ measure_data = sht3x_sensor.read_temp_humd()
13
+ # measure_data = [22.9759, 73.8277]
14
+ # The default decimal place is 4 digits
15
+ temp = measure_data[0 ]
16
+ humd = measure_data[1 ]
17
+
18
+ print (' Temp:' , temp)
19
+ # Temp: 22.9759
20
+ print (' Humd:' , humd)
21
+ # Humd: 73.8277
22
+ ```
23
+
24
+ ## Notice
25
+
26
+ The default temperature is Celsius. If you need Fahrenheit, please change it in ` sht3x.py ` .
27
+
28
+ Just uncomment the following code.
29
+
30
+ ``` python
31
+ # temperature = (315.0 * float(temperature_raw) / 65535.0) - 49
32
+ ```
33
+
34
+ And comment the following code.
35
+
36
+ ``` python
37
+ temperature = (175.0 * float (temperature_raw) / 65535.0 ) - 45
38
+ ```
39
+
40
+ The ` build/sh3x.mpy ` is a compiled bytecode file, and only can be used in ` MicroPython v1.12+ ` .
Original file line number Diff line number Diff line change
1
+ import sys
2
+ import utime
3
+ from machine import Pin
4
+ from machine import I2C
5
+
6
+ class SHT3x_Sensor :
7
+
8
+ def __init__ (self , freq , sdapin , sclpin ):
9
+ self .i2c = I2C (freq = freq , sda = Pin (sdapin ), scl = Pin (sclpin ))
10
+ addrs = self .i2c .scan ()
11
+ if not addrs :
12
+ raise Exception ('no SHT3X found at bus on SDA pin %d SCL pin %d' % (sdapin , sclpin ))
13
+ self .addr = addrs .pop ()
14
+
15
+ def read_temp_humd (self ):
16
+ status = self .i2c .writeto (self .addr ,b'\x24 \x00 ' )
17
+ # delay (20 slow)
18
+ utime .sleep (1 )
19
+ # read 6 bytes
20
+ databytes = self .i2c .readfrom (self .addr , 6 )
21
+ dataset = [databytes [0 ],databytes [1 ]]
22
+ dataset = [databytes [3 ],databytes [4 ]]
23
+ temperature_raw = databytes [0 ] << 8 | databytes [1 ]
24
+ temperature = (175.0 * float (temperature_raw ) / 65535.0 ) - 45
25
+ # fahreheit
26
+ # temperature = (315.0 * float(temperature_raw) / 65535.0) - 49
27
+ humidity_raw = databytes [3 ] << 8 | databytes [4 ]
28
+ humidity = (100.0 * float (humidity_raw ) / 65535.0 )
29
+ sensor_data = [temperature , humidity ]
30
+ return sensor_data
You can’t perform that action at this time.
0 commit comments