Adafruit CCS811 on Arduino UNO Atmel mega 328P

Hello everyone,

my Adafruit CCS811 Sensor keeps sending me the ERROR! message. The wiring seems to be alright. my code looks like this:

/***************************************************************************
This is a library for the CCS811 air

This sketch reads the sensor

Designed specifically to work with the Adafruit CCS811 breakout
----> Adafruit CCS811 Air Quality Sensor Breakout - VOC and eCO2 [STEMMA QT / Qwiic] : ID 3566 : $19.95 : Adafruit Industries, Unique & fun DIY electronics and kits

These sensors use I2C to communicate. The device's I2C address is 0x5A

Adafruit invests time and resources providing this open source code,
please support Adafruit andopen-source hardware by purchasing products
from Adafruit!

Written by Dean Miller for Adafruit Industries.
BSD license, all text above must be included in any redistribution
***************************************************************************/

#include "Adafruit_CCS811.h"

Adafruit_CCS811 ccs;

void setup() {
Serial.begin(9600);

Serial.println("CCS811 test");
Wire.setClock(500);

if(!ccs.begin()){
Serial.println("Failed to start sensor! Please check your wiring.");
while(1);
}

//calibrate temperature sensor
while(!ccs.available());
float temp = ccs.calculateTemperature();
ccs.setTempOffset(temp - 25.0);
}

void loop() {
if(ccs.available()){
float temp = ccs.calculateTemperature();
if(!ccs.readData()){
Serial.print("CO2: ");
Serial.print(ccs.geteCO2());
Serial.print("ppm, TVOC: ");
Serial.print(ccs.getTVOC());
Serial.print("ppb Temp:");
Serial.println(temp);
}
else{
Serial.println("ERROR!");
while(1);
}
}
delay(500);
}

Tried other codes, but keep getting simular errors, related to some I²C issues...
can anyone help me please?

Have you tried an i2c address scanner sketch to see if it can see a chip at that address?

If that's working, take a look at the begin method in the library - there are three different reasons for it to return false. You might add some serial.print statements to let you know which one it is.

Overall though, I'll guess that you either have a wiring issue or a dud CCS811.

Else condition has executed

void loop() {
  if(ccs.available()){
    float temp = ccs.calculateTemperature();
    if(!ccs.readData()){
      Serial.print("CO2: ");
      Serial.print(ccs.geteCO2());
      Serial.print("ppm, TVOC: ");
      Serial.print(ccs.getTVOC());
      Serial.print("ppb   Temp:");
      Serial.println(temp);
    }
    else{
      Serial.println("ERROR!");
      while(1);
    }
  }

Your if statements are wrong, try rewriting them… debug it.

ok, so i tried the I2C address scanner and located the device at 5a.
if i disconnect any cable, i get the "please check wiring" message... so i think it can't be my wiring...

14:45:21.467 -> i2cdetect example
14:45:21.467 ->
14:45:21.467 -> Scanning address range 0x03-0x77
14:45:21.501 ->
14:45:21.501 -> 0 1 2 3 4 5 6 7 8 9 a b c d e f
14:45:21.569 -> 00: -- -- -- -- -- -- -- -- -- -- -- -- --
14:45:21.603 -> 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
14:45:21.671 -> 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
14:45:21.739 -> 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
14:45:21.773 -> 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
14:45:21.841 -> 50: -- -- -- -- -- -- -- -- -- -- 5a -- -- -- -- --
14:45:21.909 -> 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
14:45:21.943 -> 70: -- -- -- -- -- -- -- --
14:45:21.943 ->

if(!ccs.readData()){

You get connection, but you then say.

 void loop() {
  if(ccs.available()){
    float temp = ccs.calculateTemperature();
    if(!ccs.readData()){

I don't see this:

Wire.setClock(500);

In the Adafruit examples. Neither do I see 500 as an acceptable parameter in the documentation for Wire.setClock. Try commenting it out.

#ifndef LIB_ADAFRUIT_CCS811_H
#define LIB_ADAFRUIT_CCS811_H

#if (ARDUINO >= 100)
 #include "Arduino.h"
#else
 #include "WProgram.h"
#endif

#include <Wire.h>

/*=========================================================================
    I2C ADDRESS/BITS
    -----------------------------------------------------------------------*/
    #define CCS811_ADDRESS                (0x5A)
/*=========================================================================*/

Gates:

#ifndef LIB_ADAFRUIT_CCS811_H

#define LIB_ADAFRUIT_CCS811_H

#if (ARDUINO >= 100)
#include “Arduino.h”
#else
#include “WProgram.h”
#endif

#include <Wire.h>

/=========================================================================
    I2C ADDRESS/BITS
    -----------------------------------------------------------------------
/
    #define CCS811_ADDRESS                (0x5A)
/=========================================================================/

i get this error message when i try to run it:

check:1:0: error: unterminated #ifndef

#ifndef LIB_ADAFRUIT_CCS811_H

^

exit status 1
unterminated #ifndef

Also tried including the Wire.setClock(500) line without results

#include “Adafruit_CCS811.h”
#include <Wire.h>

Adafruit_CCS811 ccs;

void setup() {
Serial.begin(9600);
Wire.begin();
Wire.setClock(500);
Serial.println(“CCS811 test”);

if(!ccs.begin()){
Serial.println(“Failed to start sensor! Please check your wiring.”);
while(1);
}

//calibrate temperature sensor
while(!ccs.available());
float temp = ccs.calculateTemperature();
ccs.setTempOffset(temp - 25.0);
}

void loop() {
if(ccs.available()){
float temp = ccs.calculateTemperature();
if(!ccs.readData()){
Serial.print("CO2: ");
Serial.print(ccs.geteCO2());
Serial.print("ppm, TVOC: ");
Serial.print(ccs.getTVOC());
Serial.print(“ppb Temp:”);
Serial.println(temp);
}
else{
Serial.println(“ERROR!”);
while(1);
}
}

delay(500);
}

https://adafruit.github.io/Adafruit_CCS811/html/_adafruit___c_c_s811_8h_source.html

With two statements of an " if " one is anyways going to execute...Which one you do think will execute last....

Look at the Adafruit examples, there are no calls to the wire library in their setup functions. I was suggesting that you get rid of them from yours too.

Gates:
Adafruit CCS811 Arduino Library: Adafruit_CCS811.h Source File

Tried that one, got this error message:

C:\Users\SANPAU~1\AppData\Local\Temp\ccXMK9Pt.ltrans0.ltrans.o: In function `main’:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/main.cpp:43: undefined reference to `setup’

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/main.cpp:46: undefined reference to `loop’

collect2.exe: error: ld returned 1 exit status

exit status 1
Fehler beim Kompilieren für das Board Arduino/Genuino Uno.

wildbill:
Look at the Adafruit examples, there are no calls to the wire library in their setup functions. I was suggesting that you get rid of them from yours too.

you mean, just the “Wire.setClock(500)” line without #include <Wire.h> and Wire.begin();that didn’t work either…

wildbill:
I don’t see this:

Wire.setClock(500);

In the Adafruit examples. Neither do I see 500 as an acceptable parameter in the documentation for Wire.setClock. Try commenting it out.

ok, i deleted the line. no results

What does ccs.readData() return? It's clearly non-zero, but the library says it returns an error code. It may shed some light on what's wrong.

Does the ccs.calculateTemperature() call get anything reasonable?

AMS recommends that you run this sensor for 48 hours when you first receive it to "burn it in", and then 20
minutes in the desired mode every time the sensor is in use. This is because the sensitivity levels of the
sensor will change during early use.

I think that you need an oscilloscope to test that the instrument is working correctly as you re-configured it.

Gates:
AMS recommends that you run this sensor for 48 hours when you first receive it to "burn it in", and then 20
minutes in the desired mode every time the sensor is in use. This is because the sensitivity levels of the
sensor will change during early use.

Once you've done this (if you haven't already), it's probably going to be time to get another one of these sensors to help with your debugging.

wildbill:
What does ccs.readData() return? It's clearly non-zero, but the library says it returns an error code. It may shed some light on what's wrong.

Does the ccs.calculateTemperature() call get anything reasonable?

ok, but how do i find that out?

use something like this PCB Equipment - Stripboard
You attach your devices in a module way, or attach all modules.

I would suggest not attaching all modules at the same time.