3

I apologize my last post did not upload properly so I am creating a new question.

I am using the CCS811 Gas Sensor with a Pi 3 Model b. I followed the steps on this page https://learn.adafruit.com/adafruit-ccs811-air-quality-sensor/raspberry-pi-wiring-and-test and it ran without issue during the burn in period. Now I am getting the error below.

I know the sensor works because I tested it with my Arduino Uno and I can get the readings. On my Pi it shows the correct address of the sensor when I run sudo i2cdetect -y 1.

I have wiped the SD card 3 times now and started over on a clean slate all to end up with this error each time. Any help will be greatly appreciated!

Here is the code that I am using to read the data from the sensor:

ccs = Adafruit_CCS811()

while not ccs.available():
        pass
temp = ccs.calculateTemperature()
ccs.tempOffset = temp - 25.0

while(1):
         if ccs.available():
             temp = ccs.calculateTemperature()
             if not ccs.readData():
               print "CO2: ", ccs.geteCO2(), "ppm, TVOC: ", ccs.getTVOC(), "temp: ", temp

else:
  print "ERROR!"
  while(1):
    pass
sleep(2)

Here is the error:

pi@raspberrypi:~/Adafruit_CCS811_python/examples$ sudo python CCS811_example.py
Traceback (most recent call last):
File "CCS811_example.py", line 6, in <module>
ccs =  Adafruit_CCS811()
File "/usr/local/lib/python2.7/dist-packages/Adafruit_CCS811/Adafruit_CCS811.py", line 84, in __init__
raise Exception("Device ID returned is not correct! Please check your wiring.")
Exception: Device ID returned is not correct! Please check your wiring.

Image of project

0

Elsewhere on the Adafruit article about that device is a warning:

This sensor is not well supported on Raspberry Pi. This is because it uses I2C clock stretching which the Pi cannot do without drastically slowing down the I2C speed. CircuitPython and Arduino are supported.

I suspect you are hitting that issue!

It might be worth investigating joan's pgpio library which would I think allow you to use another pair of GPIO pins (with suitable pull-ups for I²C use) as a separate slow bit-banged I²C interface specifically for that device without hitting the issue of the RPi not handling clock stretching (the slave device holds the SCL line in a low state to slow down the data transfer to a rate it can handle, but which requires the master device noticing this and waiting for the SCL line to raise before getting the next bit in the transfer).

The bottom line is, I think, that the data is getting corrupted as it is transferred between the RPi and the CCS811 and the "Device ID returned is not correct!" message is the first sign of this.

  • Another alternative, is to use an spi - i2c bridge chip or slave controller like an arduino. It would be a smart way to offload and isolate the messiness of bit banged i2c from your application code when your performance needs demand it. – crasic Dec 21 '17 at 6:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.