Go Down

Topic: Temp, Humidity CO2 sensor and library. (Read 138888 times) previous topic - next topic

ajaved200

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);   
}

robtillaart

#61
Oct 21, 2014, 06:16 pm Last Edit: Oct 21, 2014, 06:20 pm by robtillaart
I can't say as I do not have a sensor to verify problems, sorry :(
(reaction on post - 2 :)
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robtillaart

Try this echo script
Code: [Select]

#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?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

ajaved200

lemme try i ll let u know in a while

ajaved200

yes it displayed this


ÿÿ

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

ajaved200

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.

robtillaart

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)
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robtillaart

Code: [Select]
#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?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

ajaved200


I tried this as well.. still showing "ÿ"


Code: [Select]
#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?

robtillaart

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

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

ajaved200

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

ajaved200

i tried with audrino v 1.0.5 and v 1.0.3 as well

robtillaart

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

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

ajaved200

I can understand. Thanks a lot for your help.

roder

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

https://github.com/roder/cozir

Go Up