Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- import os
- import sys
- from time import sleep
- import smbus
- bus = smbus.SMBus(1)
- addr = 0x28
- SENS_STS = 0x01
- PRES_REF_H = 0x0B
- PRES_REF_L = 0x0C
- MEAS_RATE_H = 0x02
- MEAS_RATE_L = 0x03
- MEAS_CFG = 0x04
- MEAS_STS = 0x07
- CO2PPM_H = 0x05
- CO2PPM_L = 0x06
- OnePlus = (str(CO2PPM_H) + str(CO2PPM_L))
- sleep(1)
- try:
- rack = int(input("Please type a 1 or 0, thank you... "))
- while True:
- if rack >= 0:
- bus.read_byte_data(addr, SENS_STS)
- bus.read_byte_data(addr, PRES_REF_H)
- bus.read_byte_data(addr, PRES_REF_L)
- bus.read_byte_data(addr, MEAS_RATE_H)
- bus.read_byte_data(addr, MEAS_RATE_L)
- bus.read_byte_data(addr, MEAS_CFG)
- bus.read_byte_data(addr, MEAS_STS)
- bus.read_byte_data(addr, CO2PPM_H)
- bus.read_byte_data(addr, CO2PPM_L)
- sleep(0.5)
- else:
- pass
- if __name__ == '__main__':
- bus.write_byte_data(addr, PRES_REF_H, 0x03)
- bus.write_byte_data(addr, PRES_REF_L, 0xF5)
- bus.write_byte_data(addr, MEAS_RATE_H, 0x00)
- bus.write_byte_data(addr, MEAS_RATE_L, 0x0A)
- bus.write_byte_data(addr, MEAS_CFG, 0x01)
- sleep(10)
- print("PPM of CO2 in your home is: {}".format(OnePlus))
- except KeyboardInterrupt:
- print("Done for now!")
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement