sdp610Array.py 657 B

123456789101112131415161718192021222324252627282930313233343536
  1. import smbus
  2. import time
  3. class Spd610Array():
  4. i2cAddresses = (
  5. 0x21,
  6. 0x41,
  7. 0x61,
  8. 0x31,
  9. 0x39,
  10. 0x29,
  11. 0x35,
  12. 0x40
  13. )
  14. def __init__(self):
  15. self.bus = smbus.SMBus(0)
  16. def readValue(self, addr):
  17. self.bus.write_byte_data(addr, 0, 0xF1)
  18. block = self.bus.read_i2c_block_data(addr, 0, 3)
  19. value = (block[0] * 256 + block[1]) / 240.0
  20. crc = block[2]
  21. return value
  22. def getValues(self):
  23. values = ()
  24. for addr in self.i2cAddresses:
  25. values.append(self.readValue(addr))
  26. return values
  27. if __name__ == "__main__":
  28. sdp = Spd610Array()
  29. while True:
  30. print(sdp.getValues())
  31. time.sleep(1)