Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import smbus
- import time
- import struct
- bus=smbus.SMBus(1)
- address = 0x27
- bus.write_byte_data(address, 0, 1)
- time.sleep(0.2)
- data_bytes = bus.read_i2c_block_data(address, 0, 4)
- print(data_bytes)
- data_bytes[0] = data_bytes[0] & 0x3f
- temperature = data_bytes[2]<<8 | data_bytes[3]
- humidity = data_bytes[0]<<8 | data_bytes[1]
- temperature = temperature / 4
- print(float("{0:.2f}".format(humidity* 6.10e-3)))
- print(float("{0:.2f}".format(temperature* 1.007e-2 - 40.0)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement