Skip to content

Tweaked example code. Tested on Feather M4. #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 15, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions examples/ccs811_simpletest.py
Original file line number Diff line number Diff line change
@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i2c_bus or just i2c?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had i2c. Must have pasted the wrong update at some point in going back and forth between code.py and simpletest.

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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use .format here instead of %? I think % is considered the "old" way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I didn't realise it was considered to be the old way. I'll refactor it.

time.sleep(0.5)