DrDiettrich:
I wonder: if both modules are connected, the code works if it only uses one of these? If so, this indicates incompatible libraries. Quite unlikely...
Which addresses does I2Csniffer find?
0xA5 = CCS811, 0x27 = PCF8574 but the I2C sniffer only finds 0xA5!
Code used for the sniffer:
// --------------------------------------
// i2c_scanner
//
// Version 1
// This program (or code that looks like it)
// can be found in many places.
// For example on the Arduino.cc forum.
// The original author is not known.
// Version 2, Juni 2012, Using Arduino 1.0.1
// Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26 2013
// V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
// by Arduino.cc user Krodal.
// Changes by louarnold removed.
// Scanning addresses changed from 0...127 to 1...119,
// according to the i2c scanner by Nick Gammon
// http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
// As version 4, but address scans now to 127.
// A sensor seems to use address 120.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(9600);
Serial.println("\nI2C Scanner");
}
void loop()
{
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknow error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(5000); // wait 5 seconds for next scan
}
The changed code I use for reading the CCS811 and blinking the IO pins of the PCF8574:
#include <Wire.h> // I2C library
#include "PCF8574.h"
#include "SparkFunCCS811.h"
#define CCS811_ADDR 0x5A //Alternate I2C Address
CCS811 mySensor(CCS811_ADDR);
// Set i2c address
PCF8574 pcf8574(0x27, 5, 4);
void setup()
{
Serial.begin(9600);
Wire.begin();
Serial.println("CCS811 Basic Example");
CCS811Core::status returnCode = mySensor.begin();
if (returnCode != CCS811Core::SENSOR_SUCCESS)
{
Serial.println(".begin() returned with an error.");
while (1); //Hang if there was a problem.
}
pcf8574.begin();
for (int i = 0; i < 8; i++) {
pcf8574.pinMode(i, OUTPUT);
}
}
void loop()
{
//Check to see if data is ready with .dataAvailable()
if (mySensor.dataAvailable())
{
//If so, have the sensor read and calculate the results.
//Get them later
mySensor.readAlgorithmResults();
Serial.print("CO2[");
//Returns calculated CO2 reading
Serial.print(mySensor.getCO2());
Serial.print("] tVOC[");
//Returns calculated TVOC reading
Serial.print(mySensor.getTVOC());
Serial.print("] millis[");
//Simply the time since program start
Serial.print(millis());
Serial.print("]");
Serial.println();
}
//getInteralAirQuality();
pcf8574.digitalWrite(P0, HIGH);
pcf8574.digitalWrite(P1, HIGH);
pcf8574.digitalWrite(P2, HIGH);
pcf8574.digitalWrite(P3, HIGH);
pcf8574.digitalWrite(P4, HIGH);
pcf8574.digitalWrite(P5, HIGH);
pcf8574.digitalWrite(P6, HIGH);
pcf8574.digitalWrite(P7, HIGH);
delay(1000);
pcf8574.digitalWrite(P0, LOW);
pcf8574.digitalWrite(P1, LOW);
pcf8574.digitalWrite(P2, LOW);
pcf8574.digitalWrite(P3, LOW);
pcf8574.digitalWrite(P4, LOW);
pcf8574.digitalWrite(P5, LOW);
pcf8574.digitalWrite(P6, LOW);
pcf8574.digitalWrite(P7, LOW);
delay(1000);
}
Result: The PCF I/O pins blink but the CCS811 does not read, no errors given.
Code for reading the CCS811 only:
/******************************************************************************
Read basic CO2 and TVOCs on alternate Wire ports
Marshall Taylor @ SparkFun Electronics
Nathan Seidle @ SparkFun Electronics
April 4, 2017
https://github.com/sparkfun/CCS811_Air_Quality_Breakout
https://github.com/sparkfun/SparkFun_CCS811_Arduino_Library
Read the TVOC and CO2 values from the SparkFun CSS811 breakout board
This shows how to begin communication with the sensor on a different Wire port.
Helpful if you have platform that is a slave to a larger system and need
a dedicated Wire port or if you need to talk to many sensors at the same time.
A new sensor requires at 48-burn in. Once burned in a sensor requires
20 minutes of run in before readings are considered good.
Hardware Connections (Breakoutboard to Arduino):
3.3V to 3.3V pin
GND to GND pin
SDA to A4
SCL to A5
Resources:
Uses Wire.h for i2c operation
Development environment specifics:
Arduino IDE 1.8.1
This code is released under the [MIT License](http://opensource.org/licenses/MIT).
Please review the LICENSE.md file included with this example. If you have any questions
or concerns with licensing, please contact techsupport@sparkfun.com.
Distributed as-is; no warranty is given.
******************************************************************************/
#include <Wire.h>
#include "SparkFunCCS811.h"
//#define CCS811_ADDR 0x5B //Default I2C Address
#define CCS811_ADDR 0x5A //Alternate I2C Address
CCS811 mySensor(CCS811_ADDR);
void setup()
{
Serial.begin(9600);
Serial.println("CCS811 Basic Example");
Wire.begin(); //Compilation will fail here if your hardware doesn't support additional Wire ports
//It is recommended to check return status on .begin(), but it is not
//required.
CCS811Core::status returnCode = mySensor.begin();
if (returnCode != CCS811Core::SENSOR_SUCCESS)
{
Serial.println(".begin() returned with an error.");
while (1); //Hang if there was a problem.
}
}
void loop()
{
//Check to see if data is ready with .dataAvailable()
if (mySensor.dataAvailable())
{
//If so, have the sensor read and calculate the results.
//Get them later
mySensor.readAlgorithmResults();
Serial.print("CO2[");
//Returns calculated CO2 reading
Serial.print(mySensor.getCO2());
Serial.print("] tVOC[");
//Returns calculated TVOC reading
Serial.print(mySensor.getTVOC());
Serial.print("] millis[");
//Simply the time since program start
Serial.print(millis());
Serial.print("]");
Serial.println();
}
delay(10); //Don't spam the I2C bus
}
Result: Works as expected, reading both eCO2 and VOC.
Code used for setting the I/O pins on the PCF:
#include <Wire.h> // I2C library
#include "PCF8574.h"
// Set i2c address
PCF8574 pcf8574(0x27, 5, 4);
void setup()
{
Serial.begin(115200);
Wire.begin();
pcf8574.begin();
for (int i = 0; i < 8; i++) {
pcf8574.pinMode(i, OUTPUT);
}
}
void loop()
{
//getInteralAirQuality();
pcf8574.digitalWrite(P0, HIGH);
pcf8574.digitalWrite(P1, HIGH);
pcf8574.digitalWrite(P2, HIGH);
pcf8574.digitalWrite(P3, HIGH);
pcf8574.digitalWrite(P4, HIGH);
pcf8574.digitalWrite(P5, HIGH);
pcf8574.digitalWrite(P6, HIGH);
pcf8574.digitalWrite(P7, HIGH);
delay(1000);
pcf8574.digitalWrite(P0, LOW);
pcf8574.digitalWrite(P1, LOW);
pcf8574.digitalWrite(P2, LOW);
pcf8574.digitalWrite(P3, LOW);
pcf8574.digitalWrite(P4, LOW);
pcf8574.digitalWrite(P5, LOW);
pcf8574.digitalWrite(P6, LOW);
pcf8574.digitalWrite(P7, LOW);
delay(1000);
}
Result: Working as expected, all pins go HIGH to LOW continuously.