CO2 sensor K30. I have read using I2C using UNO board. Successful. Code is attached.
A4 connect to I2c data. A5 to I2C clock.
PROBLEM: when using Seeeduino Stalker V2.3
I cant read CO@ anymore.
Code is attached.
I need advice
Thank you
…Ahmad
///////////////////////// start code
#include <Wire.h>
int co2Addr = 0x68; // DEFAULT Address of the CO2 sensor, 7bits shifted left.
void setup()
{ Serial.begin(9600); // Open serial connection to report values to host
Wire.begin();
Serial.println(“Start…”);
delay(2000);
}
int readCO2()
{ int co2_value = 0; // We will store the CO2 value inside this variable.
Wire.beginTransmission(co2Addr); // Comm through i2c
Wire.write(0x22);
Wire.write(0x00);
Wire.write(0x08); // CO2
Wire.write(0x2A); // CO2
Wire.endTransmission(co2Addr);
delay(10);
Wire.requestFrom(co2Addr, 4);
byte i = 0;
byte buffer[4] = {0, 0, 0, 0};
while(Wire.available())
{ buffer = Wire.read();
i++;
}
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])
{ // if ok Success!
digitalWrite(13, LOW);
return co2_value;
}
else
{ // if fail
digitalWrite(13, LOW);
return 0;
}
}
void loop()
{ int co2Value ;
delay(1000);
co2Value = readCO2();
delay(1000);
if(co2Value > 0)
{ // if ok
Serial.print("xCO2 Value: “);
Serial.print(co2Value);
Serial.println(” ");
}
else
{ Serial.println(“Chksum/Commfail”); }
delay(2000);
}
////////////////////end code