Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. import smbus
  2. import time
  3. import struct
  4.  
  5. bus=smbus.SMBus(1)
  6.  
  7. address = 0x27
  8.  
  9. bus.write_byte_data(address, 0, 1)
  10.  
  11. time.sleep(0.2)
  12.  
  13. data_bytes = bus.read_i2c_block_data(address, 0, 4)
  14. print(data_bytes)
  15.  
  16. data_bytes[0] = data_bytes[0] & 0x3f
  17. temperature = data_bytes[2]<<8 | data_bytes[3]
  18. humidity = data_bytes[0]<<8 | data_bytes[1]
  19. temperature = temperature / 4
  20. print(float("{0:.2f}".format(humidity* 6.10e-3)))
  21. print(float("{0:.2f}".format(temperature* 1.007e-2 - 40.0)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement