adafruit / Adafruit_CircuitPython_CCS811

circuit python driver for CCS811 air quality sensor
MIT License
34 stars 24 forks source link

NameError: name 'adafruit_ccs811' is not defined #14

Closed bphermansson closed 6 years ago

bphermansson commented 6 years ago

I have put the CircuitPython bundle in the lib folder of my ItsyBitsy M0 Express. In the bundle theres a driver for the CCS811. I then try the following code:

import busio
import adafruit_CCS811
from board import *
i2c_bus = busio.I2C(SCL, SDA)
ccs =  adafruit_ccs811.CCS811(i2c_bus)

But I get an error:

File "code.py", line 5, in <module>
NameError: name 'adafruit_ccs811' is not defined

Why?

deshipu commented 6 years ago

It's adafruit_CCS811 not adafruit_ccs811 -- capitalization matters.

deshipu commented 6 years ago

Then again, all other libraries use lowercase names, so we should probably fix that.

deshipu commented 6 years ago

Try this instead:

import busio
import adafruit_ccs811
from board import *
i2c_bus = busio.I2C(SCL, SDA)
ccs =  adafruit_ccs811.CCS811(i2c_bus)
tannewt commented 6 years ago

@bphermansson Please reopen if that doesn't help.

bphermansson commented 6 years ago

That works but gives another problem, my CCS811 is found at 0x5b, nor 0x5a, so the code fails anyway.

deshipu commented 6 years ago

Then you have to specify the I²C address:

ccs = adafruit_ccs811.CCS811(i2c_bus, address=0x5b)
bphermansson commented 6 years ago

ccs = adafruit_ccs811.CCS811(i2c_bus, address=0x5b)

File "code.py", line 5, in TypeError: unexpected keyword argument 'address'

deshipu commented 6 years ago

Sorry, they used "addr" for some reason.

bphermansson commented 6 years ago

Ok thanks for a quick answer, finally it works!