Go Down

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

robtillaart

try this code, it is delay-free and prints to serial only one in ten, and to SD every meansurement

Code: (dummy) [Select]

#include <SoftwareSerial.h>

SoftwareSerial nss(11,10);

char buffer[32];
int idx = 0;
int count = 0;

void setup()
{
    Serial.begin(9600);
    nss.begin(9600);

    delay(3000);
}

void loop()
{
    if (nss.available())
    {
        char c = nss.read();
        buffer[idx] = c
        idx++;
        buffer[idx] = 0; // keep the buffer \0 terminated
        if (c == '\n')
        {
            count++;
            write_to_SD_(buffer);
            if (count == 10)
            {
                 Serial.println(buffer);
                 count = 0;
            }
            idx = 0;
        }
    }
   
   
}
Rob Tillaart

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

kalllelll

Thanks very much robtillaart, I appreciate your help very much! It works very well. For unknown reasons I had to change serial.print into serial.write at the end

oxiii

To everyone still struggling with the readings, here's my piece of advice:

Of course this is under your responsibility. I hereby dismiss any responsibility for any direct or indirect damages.

I've been stuck for some time trying to figure out why neither the analog nor the serial connection seemed to work over my Mega clone. I read through the datasheet and manual and followed to the detail to no avail. I was using the 3v3 power pin to power up this Cozir-WR sensor. I then tried stepping up the sensor serial output through a transistor to 5v in case the Arduino couldn't tell the highs and nothing. In point of fact I was advised to try the 5v but I was reluctant as I wouldn't want to break this rather expensive part. Big thanks for your continued support, BTW (I don't know your username here, sorry). I eventually found this chart: http://www.co2meters.com/Documentation/Datasheets/Sensor-Comparison-Chart.pdf and decided to give the 5v power source a go. The analog pin was working beautifully. I then tried the serial but it wasn't. I thought I'd try switching the wires and that did it! I then tried the 3v3 source again but it stopped working.

So, try the 5v source and try switching the Rx and Tx pin wires, because either the sensor's or some other documentation are wrong. After all, isn't a Tx supposed to go into an Rx?

Good luck!

robtillaart

> So, try the 5v source and try switching the Rx and Tx pin wires, because either the sensor's or some other documentation are wrong. After all, isn't a Tx supposed to go into an Rx?

Serial is full of obscurities. IIRC it depends if the device is a serial DTE or DCE. The TX of a DTE is connected to the TX of a DCE, so no crossing of  Tx and Rx. if you connect 2 DTE's or 2 DCE 's the you need to cross Tx and Rx (null modem connection).
[is quite some time ago]

DTE stands for Data Terminal Equipment, and. DCE stands for Data Communications Equipment.
Rob Tillaart

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

Zoey_P

Hello,I use your library and code to run my sensor,but I get nothing.It seems that the sensor doesn't work but connection is right..Well,I just start to learn arduino...I don't know which step is wrong,can you help me?Thank you !!!

robtillaart

Please post your code used, COZIR library version number and a picture/drawing of your schematics.
Which board are you using?
Which version of the IDE?

Please note I do not have such sensor although I was involved in creating the library.
Rob Tillaart

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

yogeshsingh

i am using cozir ambient form past 3 month .
It was working as a charm in streaming mode.

Now,
I am using sensor in polling mode and after getting the data
i put it in power save mode that is K 0\r\n
(say after 5 min getting the value of co2)

Most of the time it give co2 value as 0(zero) or anything greater than 5001.
as i am using ambient which is not suppose to value greater greater than 5001.
Even if it wok for some cycle it get stuck after 10 to 12 cycle and to get value value i have to reset
the controller.

Is there any solution to this or somebody else also face this problem.

Erik455

I am getting these errors:
cozir_scetch.cpp.o: In function `loop':
C:\Users\Erik\Documents\Arduino/cozir_scetch.ino:18: undefined reference to `COZIR::Celsius()'
C:\Users\Erik\Documents\Arduino/cozir_scetch.ino:19: undefined reference to `COZIR::Fahrenheit()'
C:\Users\Erik\Documents\Arduino/cozir_scetch.ino:20: undefined reference to `COZIR::Humidity()'
C:\Users\Erik\Documents\Arduino/cozir_scetch.ino:21: undefined reference to `COZIR::CO2()'
cozir_scetch.cpp.o: In function `__static_initialization_and_destruction_0':
C:\Users\Erik\Documents\Arduino/cozir_scetch.ino:6: undefined reference to `COZIR::COZIR(SoftwareSerial&)'
collect2.exe: error: ld returned 1 exit status

robtillaart

Welcome Erik,

you need to tell more, and at least post the code (in code tags == </> button).
Also tell how & where you did install the library
Rob Tillaart

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

Erik455

Thanks Rob! I used the files on https://github.com/RobTillaart/Arduino/tree/master/libraries/Cozir.

But now I use the original version (0.1.01) of cozir.h and everything works.

robtillaart

Didn't the last version work?

(I don't have the sensor, mainly helped to stabilize and optimize the lib)
Rob Tillaart

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

cope

I have a Cozir ambient sensor and the CO2, temperature and relative humidity output is working fine thanks to all the input I got from this thread. The problem is that the CO2 values are too high so I want to 'calibrate' the sensor in fresh air. Now I have a problem to implement this in a sketch. I see the CalibrateFreshAir() function in the cpp file but I have no idea how to use this (no cpp knowledge). Is there someone that could explain to me how to go on?
Thanks in advance,
Cor

cope

I would like to share another observation. I am running the sketch I use for measuring CO2, temperature and relative humidity with the old 1.01 library. So I thought to upgrade to 6.01beta.
It turns out that the SetOperatingMode function does not work as it should. I only can get things going again by making SetOperatingMode public, comment out SetOperatingMode in the Cozir.cpp and place the call again in the sketch.
Does anybody know if am I doing something wrong here, and what?
--Cor--

34R7

@ cope :

get this in your setup
Code: [Select]
// czr.SetOperatingMode(CZR_POLLING);
 //czr.SetOperatingMode(CZR_STREAMING);
// czr.CalibrateFreshAir();


1. uncomment the operating mode you want -> upload
2. comment the operating mode again and uncomment CalibrateFreshAir() ->upload
3. comment CalibrateFreshAir() ->upload
 and it should work

cope

Thanks a lot for your support. It turned out that I had to give the czr.CalibrateFreshAir() command twice. It did not always work with one command.
But it works now, thanks again.
-- Cor --

Go Up