Advertisement
silver2row

trying i2c_infineon...

Jan 10th, 2024
793
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.49 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.  
  11. SENS_STS = 0x01
  12. PRES_REF_H = 0x0B
  13. PRES_REF_L = 0x0C
  14. MEAS_RATE_H = 0x02
  15. MEAS_RATE_L = 0x03
  16. MEAS_CFG = 0x04
  17.  
  18. MEAS_STS = 0x07
  19.  
  20. CO2PPM_H = 0x05
  21. CO2PPM_L = 0x06
  22. sleep(1)
  23.  
  24. try:
  25.     if __name__ == '__main__':
  26.         rack = int(input("Please type a 1 or 0, thank you... "))
  27.         while True:
  28.             if rack >= 0:
  29.                 bus.read_byte_data(addr, SENS_STS)
  30.                 bus.read_byte_data(addr, PRES_REF_H)
  31.                 bus.read_byte_data(addr, PRES_REF_L)
  32.                 bus.read_byte_data(addr, MEAS_RATE_H)
  33.                 bus.read_byte_data(addr, MEAS_RATE_L)
  34.                 bus.read_byte_data(addr, MEAS_CFG)
  35.                 bus.read_byte_data(addr, MEAS_STS)
  36.                 bus.read_byte_data(addr, CO2PPM_H)
  37.                 bus.read_byte_data(addr, CO2PPM_L)
  38.                 sleep(0.5)
  39.             else:
  40.                 pass
  41.  
  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.         OnePlus = bus.read_byte_data(addr, CO2PPM_H) << 8
  49.         OnePlus |= bus.read_byte_data(addr, CO2PPM_H)
  50.         print("PPM of CO2 in your home is: {}".format(OnePlus))
  51.  
  52. except KeyboardInterrupt:
  53.     print("Done for now!")
  54.     pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement