Temp, Humidity CO2 sensor and library.

Dear Rob Tillart,
I tried to run this code http://www.co2meters.com/Documentation/AppNotes/AN128-%20Cozir_Arduino.pdf -

I tried to send the command " z\r\n" to get the co2 values but it didn’t work for me so i removed the while condition and it started displaying co2 values

//while(buffer[ind-1] != 0x0A)
{
if(mySerial.available())
{
buffer[ind] = mySerial.read();
ind++;
}
//}

Now when I included the cozir.h file and tried to run this code (posted by @DirtGambit) nothing is displaying on serial monitor. I tried this arduino 1.0.3 as well.

#include <SoftwareSerial.h>
#include “cozir.h”

SoftwareSerial nss(3,2);
COZIR czr(nss);

void setup()
{
Serial.begin(9600);
delay(3000);
//czr.SetOperatingMode(CZR_POLLING);
//czr.SetOperatingMode(CZR_STREAMING);
}

void loop()
{
float t = czr.Celsius();
float f = czr.Fahrenheit();
float h = czr.Humidity();
int c = czr.CO2();
int digi = czr.GetDigiFilter();
Serial.print("Celcius : ");Serial.println(t);
Serial.print("Fahrenheit : ");Serial.println(f);
Serial.print("Humidity : ");Serial.println(h);
Serial.print("CO2 : ");Serial.println(c);
Serial.print("Digital Filter : ");Serial.println(digi);
}

I can't say as I do not have a sensor to verify problems, sorry :( (reaction on post - 2 :)

Try this echo script

#include <SoftwareSerial.h>

SoftwareSerial nss(3,2);

void setup()
{
  Serial.begin(9600); 
  nss.begin(9600);
  delay(3000);
}

void loop()
{
  if (nss.available()) 
  {
    Serial.write(nss.read());
  }
}

does it show anything?

lemme try i ll let u know in a while

yes it displayed this

ÿÿ

I have connected sensor RX -> with Arduino pin#3 and sensor TX _> with pin #2

I added Serial.println("test");

it displayed this text on monitor... strangely I have to re insert the wire connecting the sensor's RX with microcontroller pin#3 in order to display the text on the serial monitor.

ajaved200: yes it displayed this

ÿÿ

I have connected sensor RX -> with Arduino pin#3 and sensor TX _> with pin #2

that means you have made a hard wired connection between the hardware Serial and the software serial. The if statement in the code should do the copying but only if there is data available on the SW serial. the yy indicates there is nothing to read() (In fact it is ASCII char 255 or -1)

#include <SoftwareSerial.h>

SoftwareSerial nss(3,2);

void setup()
{
  Serial.begin(9600); 
  nss.begin(9600);
  delay(3000);
  nss.println("z")
}

void loop()
{
  if (nss.available() > 0) 
  {
    Serial.write(nss.read());
  }
}

slightly different, added a “z” to tickle the sensor, and an explicit >0 test
can you try?

I tried this as well… still showing “ÿ”

robtillaart:

#include <SoftwareSerial.h>

SoftwareSerial nss(3,2);

void setup()
{
  Serial.begin(9600);
  nss.begin(9600);
  delay(3000);
  nss.println(“z”)
}

void loop()
{
  if (nss.available() > 0)
  {
    Serial.write(nss.read());
  }
}




slightly different, added a "z" to tickle the sensor, and an explicit >0 test 
can you try?

Which version of the IDE are you using? Which board? UNO/MEGA? The COZIR is connected to pin 2 and 3 I assumed....Right?

I am using audrino UNO and yess cozir is connected with pin 2 and pin 3

i tried with audrino v 1.0.5 and v 1.0.3 as well

I'm out of options now, as said before I do not have such sensor to replicate your project, sorry

I can understand. Thanks a lot for your help.

I posted the Cozir library to github for convenience (and a project that I was working on).

For anyone is using a Pinoccio (https://pinocc.io), which uses the ATmega2560 chip:

I used SCK as pin 11 and MISO as pin 12

SoftwareSerial nss(11,12);

https://github.com/Pinoccio/core-pinoccio/blob/master/avr/variants/pinoccio/pins_arduino.h#L48-L49

Interestingly as soon as I take a reading in my loop:

lcd.setCursor(0,0);lcd.print("CO2 : "); lcd.print(czr.CO2());

My ads1115 running on the i2c bus stops taking readings!

If I rem this line out, it works fine??

The CO2 reading works fine anyway.

nterestingly as soon as I take a reading in my loop: lcd.setCursor(0,0);lcd.print("CO2 : "); lcd.print(czr.CO2()); My ads1115 running on the i2c bus stops taking readings! If I rem this line out, it works fine?? The CO2 reading works fine anyway.

The I2C communication might be corrupted by the LCD communication. How is the LCD connected?

do you have pull ups on the I2C lines?

Wow, you are a great help to the community!

Yes I am using an i2c LCD but like I say, it works fine if I remark out any lines that read the cozir, but as soon as I take a reading from the cozir, the communication with the adc on the i2c bus stops!

My sketch takes a reading from the adc first, this works and is displayed on the lcd (and the serial monitor), then a CO2 which works fine, on the next loop (as a CO2 reading has now been taken) the adc (ads1115) returns nothing!

Very strange.

I thought the pullup resistors are internal to the atmega, I am using an Uno.

Should I disable them? I think they are software turn offable.