Go Down

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

nitrojet

OK, I now get

Cozir HardwareSerial: 0.1.06

in the serial monitor.


robtillaart

now lets add one line to the constructor - setting the baudrate

Code: [Select]

COZIR::COZIR(HardwareSerial& hws) : CZR_Serial(hws)
{
    hws.begin(9600);
    # init();
}


please check the output.
Rob Tillaart

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

nitrojet

I get

C:\Users\Acer\Documents\Arduino\libraries\cozir\cozir.cpp:32:7: error: invalid preprocessing directive #init
     # init();
       ^
Error compiling.

but if I do this

Code: [Select]
COZIR::COZIR(HardwareSerial& hws) : CZR_Serial(hws)
{
    hws.begin(9600);
//    # init();
}


I get this

Cozir HardwareSerial: 0.1.06


robtillaart

Sorry # is python comment my mistake

nest step is to add the init step
Code: [Select]

COZIR::COZIR(HardwareSerial& hws) : CZR_Serial(hws)
{
    hws.begin(9600);
    init();
}
Rob Tillaart

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

robtillaart

might be time to write a Cozir simulator ... (should not be too hard)
Rob Tillaart

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

nitrojet

Ok, I have done that, but surely we are back to how it was and I now have nothing in the serial monitor.

I really appreciate the time you are spending on this.

robtillaart

please make the following changes to the library

Code: [Select]

void COZIR::init()
{
    SetOperatingMode(CZR_POLLING);
    // delay for initialization
    delay(1200);
}

void COZIR::SetOperatingMode(uint8_t mode)
{
    sprintf(buffer, "K %u", mode);

    Serial.println(buffer);
    Serial.flush();

    Command(buffer);
}

void COZIR::Command(const char* s)
{
    // TODO
    // CZR_Serial.println(s);

    Serial.println("1");
    Serial.flush();

    CZR_Serial.print(s);

    Serial.println("2");
    Serial.flush();

    CZR_Serial.print("\r\n");

    Serial.println("3");
    Serial.flush();
}


setting the operating mode does send a string "k 2\r\n" to the device. With the above changes we should see where it blocks. My assumption is it will print the "1" and then stops.
 
Rob Tillaart

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

nitrojet

Interestingly enough, I modified the library as you said and it returns

bäÿ

in the serial monitor!

robtillaart

OK, clearly the initialization fails ... time to think ...
Rob Tillaart

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

nitrojet

Is there a way that I can just use serial.read to just check the cozir is plugged in correctly?


Regards

nitrojet

How about I test this on an Uno first to find where the problem is, however I would need to output the data as an LED light up or lcd screen as obviously the uno only has one hardware serial

Toledor

#131
Feb 13, 2015, 02:40 pm Last Edit: Feb 13, 2015, 02:50 pm by Toledor
Some of the problems people have been having is due to not calibrating the sensor at first use

Here is a step by step
uncomment czr.SetOperatingMode(CZR_POLLING);
Upload Sketch
comment czr.SetOperatingMode(CZR_POLLING);
and uncomment czr.CalibrateFreshAir();
Upload Sketch
comment czr.CalibrateFreshAir();
Upload sketch
Thanks so much DirtGambit and Rob, thanks to this, my sensor is finally functional!

There is one small issue though: after I upload DirtGambit's sketch or switch off/on the Uno, I have to disconnect the wire in pin 3, that is connected to the sensor's Rx. Does anyone understand why? Nevermind, there is just a delay of nearly 13 seconds before the first values are shown and I was impatient.

kslstn

Hi all, I put some sketches for the CoZIR sensor on GitHub. Most notably a logger for measurement. Because I ran in quite a few problems before I got my sensor working, I took DirtGambit's code and split it up into different tools with comments about how I got things to work. Another reason to split it up into separate files is that this way you can just upload, say the Calibrate sketch to calibrate the sensor and then upload another sketch again to do something else with the sensor. That way you don't have to comment and uncomment lines in one file all the time.

I hope the sketches are useful to other novice users like myself!

My next tool will be getting measurements to show on an LCD panel, after that I want to make a program that logs measurements to an SD card.

Dew123

Hi everyone,

     A few posts back I think I posted about the distortions in the readings from the CO2 sensor when it is placed in an environment with a hotter temperature. We talked to the CO2meter company, and we found that to fix the discrepancy we needed to keep a continuous flow of air across the sensor with a mini vacuum pump, since increasing the temp/pressure will alter the turbulence of the air flow (also, if you put the sensor into a sealed chamber and heat it, the co2 levels will increase because of the pressure increase, making the CO2 molecules move around more quickly and registered more frequently by the NDIR sensor)
      If you use a small vacuum pump (like one from Parker, 3.3V and around $30) it should eliminate any factors caused by pressure and temperature. Just some advice.

   
      Also, would anyone happen to know how to create a running slope without keeping the array/buffer from maxing out? (kinda like a running average, except you measure the slope continuously as you get more data points). Would a circular buffer work for this kind of thing, so that it will only take the average slope between like 5 points at a time?

      Thanks for your hellp

Dew321

Hi Everyone,

    Oops, it seems that I used another account when posting the previous post. However, would anyone know how to calculate the rate of change of generated values using arduino (for example, calculating the rate of change of a CO2 increase or decrease)? Would it be possible to use an array without it maxing out in values over time (like it would clear itself periodically?)

     Thanks

Go Up