init
This commit is contained in:
53
Humidity.py
Normal file
53
Humidity.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import smbus2
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
|
||||
"""
|
||||
>>> bus = smbus2.SMBus(1)
|
||||
>>> ans = bus.write_byte(0x44, 0xFD)
|
||||
>>> smbus2.i2c_msg.read(0x44,6)
|
||||
i2c_msg(68,1,b'\x00\x00\x00\x00\x00\x00')
|
||||
>>> taa=smbus2.i2c_msg.read(0x44,6)
|
||||
>>> bus.i2c_rdwr(taa)
|
||||
>>> data = list(taa)
|
||||
>>> print(data)
|
||||
[112, 174, 89, 60, 78, 165]
|
||||
"""
|
||||
|
||||
def main():
|
||||
i2cbus = smbus2.SMBus(1)
|
||||
addressSHT40 = 0x44
|
||||
meas_sht40(i2cbus, 0x44)
|
||||
|
||||
|
||||
|
||||
def meas_sht40(bus, addressSHT40):
|
||||
CMD_measure = 0xFD #cmd de mesure
|
||||
#bus.write_byte(0x00, 0x06)
|
||||
#time.sleep(1.1)
|
||||
bus.write_byte(0x44, 0x39)
|
||||
time.sleep(1.1)
|
||||
while 1:
|
||||
time.sleep(1.1)
|
||||
#data = bus.read_i2c_block_data(0x44, 0, 6) #Lecture des 6 octets
|
||||
data = []
|
||||
|
||||
bus.write_byte(0x44, 0xFD)
|
||||
byte = bus.read_block_data(0x44,3)
|
||||
data.append(byte)
|
||||
print(f"Octet {i}: {byte:#04x}")
|
||||
time.sleep(1.15)
|
||||
|
||||
#print(data)
|
||||
|
||||
"""
|
||||
temp_raw = (data[0] << 8) + data[1]
|
||||
humidity_raw = (data[3] <<8) + data[4]
|
||||
"""
|
||||
temperature = 10000*(data/65535.0)
|
||||
#temperature = -45 + 175*data/65535
|
||||
#print(temperature)
|
||||
|
||||
|
||||
if __name__=="__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user