linux-i2c.py 579 B

12345678910111213141516171819202122
  1. #!/usr/bin/env python3
  2. import bme280
  3. import sys
  4. import time
  5. if len(sys.argv) >= 2:
  6. i2cBus = int(sys.argv[1])
  7. else:
  8. i2cBus = 0
  9. with bme280.BME280(i2cBus=i2cBus) as bme:
  10. while True:
  11. t, h, p = bme.readForced(filter=bme280.FILTER_4,
  12. tempOversampling=bme280.OVSMPL_4,
  13. humidityOversampling=bme280.OVSMPL_16,
  14. pressureOversampling=bme280.OVSMPL_4)
  15. print("t=%.2f h=%.2f p=%.1f" % (t, h * 1e2, p * 1e-2))
  16. time.sleep(0.5)
  17. # vim: ts=4 sw=4 expandtab