linux-spi.py 635 B

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