Advertisement
silver2row

testing SMBUS python3

Jan 10th, 2024
708
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.40 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. import os
  4. import sys
  5. from time import sleep
  6. import smbus
  7.  
  8. bus = smbus.SMBus(1)
  9. addr = 0x28
  10. SENS_STS = 0x01
  11. PRES_REF_H = 0x0B
  12. PRES_REF_L = 0x0C
  13. MEAS_RATE_H = 0x02
  14. MEAS_RATE_L = 0x03
  15. MEAS_CFG = 0x04
  16.  
  17. MEAS_STS = 0x07
  18.  
  19. CO2PPM_H = 0x05
  20. CO2PPM_L = 0x06
  21. OnePlus = (str(CO2PPM_H) + str(CO2PPM_L))
  22. sleep(1)
  23.  
  24. try:
  25.     rack = int(input("Please type a 1 or 0, thank you... "))
  26.     while True:
  27.         if rack >= 0:
  28.             bus.read_byte_data(addr, SENS_STS)
  29.             bus.read_byte_data(addr, PRES_REF_H)
  30.             bus.read_byte_data(addr, PRES_REF_L)
  31.             bus.read_byte_data(addr, MEAS_RATE_H)
  32.             bus.read_byte_data(addr, MEAS_RATE_L)
  33.             bus.read_byte_data(addr, MEAS_CFG)
  34.             bus.read_byte_data(addr, MEAS_STS)
  35.             bus.read_byte_data(addr, CO2PPM_H)
  36.             bus.read_byte_data(addr, CO2PPM_L)
  37.             sleep(0.5)
  38.         else:
  39.             pass
  40.  
  41.         if __name__ == '__main__':
  42.             bus.write_byte_data(addr, PRES_REF_H, 0x03)
  43.             bus.write_byte_data(addr, PRES_REF_L, 0xF5)
  44.             bus.write_byte_data(addr, MEAS_RATE_H, 0x00)
  45.             bus.write_byte_data(addr, MEAS_RATE_L, 0x0A)
  46.             bus.write_byte_data(addr, MEAS_CFG, 0x01)
  47.             sleep(10)
  48.             print("PPM of CO2 in your home is: {}".format(OnePlus))
  49.  
  50. except KeyboardInterrupt:
  51.     print("Done for now!")
  52.     pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement