Skip to content

Instantly share code, notes, and snippets.

@a2f0
Last active May 19, 2019 20:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save a2f0/ce391c81c479f7be25e6fde5cd62e708 to your computer and use it in GitHub Desktop.
Save a2f0/ce391c81c479f7be25e6fde5cd62e708 to your computer and use it in GitHub Desktop.
Figaro CDM7160 continuous I2C read w/busy PIN (Python)
#!/usr/bin/env python
from smbus2 import SMBus, SMBusWrapper, i2c_msg
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
INPUT_PIN = 8 #The BUSY pin.
GPIO.setup(INPUT_PIN, GPIO.IN)
def inputLow(channel):
with SMBusWrapper(1) as bus:
#set the device to continuous read
bus.write_byte(0x69, 0x1, 0x6)
#read back 0x1
byte1 = bus.read_byte(0x69,0)
#read 0x2
status = bus.read_byte(0x69,0)
#read 0x3
low_byte = bus.read_byte(0x69,0)
#read 0x4
high_byte = bus.read_byte(0x69,0)
reading = (high_byte * 256) + low_byte
print("c02 reading: " + str(reading))
def read_loop():
while True:
time.sleep(1)
if __name__ == "__main__":
#set inputLow to fire when the busy pin drops to low.
GPIO.add_event_detect(INPUT_PIN, GPIO.FALLING, callback=inputLow, bouncetime=200)
read_loop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment