From eb94280bd56597a81ea649d448d99d57faa95539 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Wed, 15 Aug 2018 14:33:33 -0400 Subject: [PATCH 1/2] Tweaked example code. Tested on Feather M4. --- examples/ccs811_simpletest.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/examples/ccs811_simpletest.py b/examples/ccs811_simpletest.py index 1c00563..2932ac6 100644 --- a/examples/ccs811_simpletest.py +++ b/examples/ccs811_simpletest.py @@ -1,20 +1,18 @@ import time - -from board import SCL, SDA +import board import busio - import adafruit_ccs811 -i2c_bus = busio.I2C(SCL, SDA) - -ccs = adafruit_ccs811.CCS811(i2c_bus) +i2c_bus = busio.I2C(board.SCL, board.SDA) +ccs811 = adafruit_ccs811.CCS811(i2c_bus) -#wait for the sensor to be ready and calibrate the thermistor -while not ccs.data_ready: +# Wait for the sensor to be ready and calibrate the thermistor +while not ccs811.data_ready: pass -temp = ccs.temperature -ccs.temp_offset = temp - 25.0 +temp = ccs811.temperature +ccs811.temp_offset = temp - 25.0 while True: - print("CO2: ", ccs.eco2, " TVOC:", ccs.tvoc, " temp:", ccs.temperature) - time.sleep(.5) + print("CO2: %1.0f PPM, TVOC: %1.0f PPM, Temp: %0.1f C" % + (ccs811.eco2, ccs811.tvoc, ccs811.temperature)) + time.sleep(0.5) From e82148976bbf5fb36d07698b0965bd25aa2a25ee Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Wed, 15 Aug 2018 14:53:38 -0400 Subject: [PATCH 2/2] Refactor i2c and print statement --- examples/ccs811_simpletest.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/ccs811_simpletest.py b/examples/ccs811_simpletest.py index 2932ac6..8706110 100644 --- a/examples/ccs811_simpletest.py +++ b/examples/ccs811_simpletest.py @@ -3,8 +3,8 @@ import busio import adafruit_ccs811 -i2c_bus = busio.I2C(board.SCL, board.SDA) -ccs811 = adafruit_ccs811.CCS811(i2c_bus) +i2c = busio.I2C(board.SCL, board.SDA) +ccs811 = adafruit_ccs811.CCS811(i2c) # Wait for the sensor to be ready and calibrate the thermistor while not ccs811.data_ready: @@ -13,6 +13,6 @@ ccs811.temp_offset = temp - 25.0 while True: - print("CO2: %1.0f PPM, TVOC: %1.0f PPM, Temp: %0.1f C" % - (ccs811.eco2, ccs811.tvoc, ccs811.temperature)) + print("CO2: {} PPM, TVOC: {} PPM, Temp: {} C" + .format(ccs811.eco2, ccs811.tvoc, ccs811.temperature)) time.sleep(0.5)