Communication failure between datalogger shield with CO2 sensor

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
mromero
 
Posts: 94
Joined: Fri Mar 18, 2016 12:10 pm

Communication failure between datalogger shield with CO2 sensor

Post by mromero »

Hi, I am trying to create a CO2 datalooger. Using the Metro ATmega328 with a dataloger shield ( both from Adafruit). I have a K33 ICB CO2 sensor from CO2meter.com. All that is connected is the I2C_SDA and I2C_SCL from CO2 meter to SDA and SCL pins on the stacked datalogger shield (see Pic). The CO2 meter is externally powered by a 6V Power supply and the GND of the Power Supply is run to the Metro.

The supplier provided the Arduino _to_I2C code below. which works if i dont have the datalogger shield connected. But if i have the datalogger shield connected the program fails. I tested to make pun the signal goes from the sensor pin through the stacked shield all the way to the arduino and it does.

Any help will be appreaciated.

Code: Select all

// CO2 Meter K-series Example Interface
// Revised by Marv Kausch, 7/2016 at CO2 Meter <co2meter.com>
// Talks via I2C to K30/K22/K33/Logger sensors and displays CO2 values
// 12/31/09
#include <Wire.h>
// We will be using the I2C hardware interface on the Arduino in
// combination with the built-in Wire library to interface.
// Arduino analog input 5 - I2C SCL
// Arduino analog input 4 - I2C SDA
/*
  In this example we will do a basic read of the CO2 value and checksum verification.
  For more advanced applications please see the I2C Comm guide.
*/
int co2Addr = 0x68;
// This is the default address of the CO2 sensor, 7bits shifted left.
void setup() {
  Serial.begin(9600);
  Wire.begin ();
  pinMode(13, OUTPUT); // address of the Arduino LED indicator
  Serial.println("Application Note AN-102: Interface Arduino to K-30");
}
///////////////////////////////////////////////////////////////////
// Function : int readCO2()
// Returns : CO2 Value upon success, 0 upon checksum failure
// Assumes : - Wire library has been imported successfully.
// - LED is connected to IO pin 13
// - CO2 sensor address is defined in co2_addr
///////////////////////////////////////////////////////////////////
int readCO2()
{
  int co2_value = 0;  // We will store the CO2 value inside this variable.

  digitalWrite(13, HIGH);  // turn on LED
  // On most Arduino platforms this pin is used as an indicator light.

  //////////////////////////
  /* Begin Write Sequence */
  //////////////////////////

  Wire.beginTransmission(co2Addr);
  Wire.write(0x22);
  Wire.write(0x00);
  Wire.write(0x08);
  Wire.write(0x2A);

  Wire.endTransmission();

  /////////////////////////
  /* End Write Sequence. */
  /////////////////////////

  /*
    We wait 10ms for the sensor to process our command.
    The sensors's primary duties are to accurately
    measure CO2 values. Waiting 10ms will ensure the
    data is properly written to RAM

  */

  delay(10);

  /////////////////////////
  /* Begin Read Sequence */
  /////////////////////////

  /*
    Since we requested 2 bytes from the sensor we must
    read in 4 bytes. This includes the payload, checksum,
    and command status byte.

  */

  Wire.requestFrom(co2Addr, 4);

  byte i = 0;
  byte buffer[4] = {0, 0, 0, 0};

  /*
    Wire.available() is not nessessary. Implementation is obscure but we leave
    it in here for portability and to future proof our code
  */
  while (Wire.available())
  {
    buffer[i] = Wire.read();
    i++;
  }

  ///////////////////////
  /* End Read Sequence */
  ///////////////////////

  /*
    Using some bitwise manipulation we will shift our buffer
    into an integer for general consumption
  */

  co2_value = 0;
  co2_value |= buffer[1] & 0xFF;
  co2_value = co2_value << 8;
  co2_value |= buffer[2] & 0xFF;


  byte sum = 0; //Checksum Byte
  sum = buffer[0] + buffer[1] + buffer[2]; //Byte addition utilizes overflow

  if (sum == buffer[3])
  {
    // Success!
    digitalWrite(13, LOW);
    return co2_value;
  }
  else
  {
    // Failure!
    /*
      Checksum failure can be due to a number of factors,
      fuzzy electrons, sensor busy, etc.
    */

    digitalWrite(13, LOW);
    return 0;
  }
}
void loop() {

 // int co2Value = readCO2();// orig
 // int co2Value = readCO2()*10;// what i was told to do. this gives half of what the dev kit prewired one reads.
   int co2Value = (readCO2()*10);
  
  if (co2Value > 0)
  {
    Serial.print("CO2 Value: ");
    Serial.println(co2Value);
  }
  else
  {
    Serial.println("Checksum failed / Communication failure");
  }
  delay(2000);
}  
Attachments
errorwithDL shield.JPG
errorwithDL shield.JPG (60.87 KiB) Viewed 166 times
CO2sensor to arduino.JPG
CO2sensor to arduino.JPG (184.19 KiB) Viewed 166 times
CO2 connection.JPG
CO2 connection.JPG (63.92 KiB) Viewed 166 times

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Communication failure between datalogger shield with CO2 sensor

Post by adafruit_support_bill »

Code: Select all

int co2Addr = 0x68;
// This is the default address of the CO2 sensor, 7bits shifted left.
Looks like your CO2 sensor has the same i2c address as the RTC. If it is possible to change the address on your CO2 sensor, that would avoid the conflict.

https://learn.adafruit.com/i2c-addresse ... 68-3119934

User avatar
mromero
 
Posts: 94
Joined: Fri Mar 18, 2016 12:10 pm

Re: Communication failure between datalogger shield with CO2 sensor

Post by mromero »

First thanks for the reply about the RTC conflict with CO2 sensor on address 0x68.

the project i hope to create will have :
1x BME280 (0x77)
1x Datalogger shield where clock (0x68)
2x CO2 sensors (0x68) which i hope to connect using
1x TCA9548A I2C Multiplexer(0x70)

My question before i try to wire this is will running the CO2 sensors thru the I2C multiplexer so the arduino sees the 0x70 address of the multiplexer resolve the address conflict?

The address list said 0x68 only so im assuming i cannot assign a different address to the clock?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Communication failure between datalogger shield with CO2 sensor

Post by adafruit_support_bill »

The clock address is fixed at 0x68. Unfortunately, a multiplexer won't help in this case because the RTC is directly connected to the i2c bus on the shield. So it will always respond to address 0x68 - regardless of which multiplexer channel is selected.

You could possibly remedy that by cutting some traces on the board and re-routing the RTC connections through the multiplexer.

It also looks like your CO2 module has several other interface options you could use, including serial, analog or PWM.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”