Go Down

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

robtillaart

Hi robtillaart,
...
    Hmm...I'll take a look at the uin16_tCO2(). Is there a way to make it go up to around 650,000 ppm, which is the max for this particular sensor?
definitely there is, however I (still) do not have such sensor so I can try to provide a patch that you should test. (did work earlier in this thread ;)
Rob Tillaart

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

robtillaart

in the main sketch change this
Code: [Select]
void loop()
{
  Serial.println("Loop");
  float t = czr.Celsius();
  float f = czr.Fahrenheit();
  float h = czr.Humidity();
  uint32_t c = czr.CO2();
 
  Serial.print("Celcius = ");Serial.println(t);
  Serial.print("Fahrenheit = ");Serial.println(f);
  Serial.print("Humidity = ");Serial.println(h);
  Serial.print("CO2 = ");Serial.println(c);
 
  delay(3000);
}



in cozir.h change this
Code: [Select]
uint32_t CO2();


in cozir.cpp change this
Code: [Select]
uint32_t COZIR::CO2()
{
  return Request("Z");
}

and

Code: [Select]

uint32_t COZIR::Request(const char* s)
{
  Command(s);
  // empty buffer
  buffer[0] = '\0';
  // read answer; there may be a 100ms delay!
  // TODO: PROPER TIMEOUT CODE.
  delay(200);
  int idx = 0;
  while(CZR_Serial.available())
  {
    buffer[idx++] = CZR_Serial.read();
  }
  buffer[idx] = '\0';

  uint32_t rv = 0;
  switch(buffer[0])
  {
    case 'T' :
rv = atoi(&buffer[5]);
            if (buffer[4] == 1) rv += 1000;
// negative values are mapped above 1000..1250 => capture this in Celsius()
break;
default :
rv = atol(&buffer[2]);
break;
  }
  return rv;
}


and change the version number to 0.1.04 if it works  :)


Rob Tillaart

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

Dew321

Hi robtillart,


      Thank you for your advice! The wrap-around is fixed now for the sensor. Also, would you know how exactly the CalibrateFreshAir() function works within this library? Does it calibrate by setting the measured air of the environment to 450 ppm and then basing measurements relative to that, or does it do it some other way?
       I am also looking to try to incorporate a small heating element into the arduino, perhaps through the use of nichrome wire. Would you know any possible sources for code that is able to regulate the temperature of the wire, or any references in general?

       Thanks again for all your help :)

robtillaart

Hi robtillart,

      Thank you for your advice! The wrap-around is fixed now for the sensor.
good to hear!,
I'll make a 0.1.04 version of the library today.


Quote
Also, would you know how exactly the CalibrateFreshAir() function works within this library? Does it calibrate by setting the measured air of the environment to 450 ppm and then basing measurements relative to that, or does it do it some other way?
As said earlier in the thread, I do not have such sensor, so nada hands on experience.


Quote
I am also looking to try to incorporate a small heating element into the arduino, perhaps through the use of nichrome wire. Would you know any possible sources for code that is able to regulate the temperature of the wire, or any references in general?
What is the temperature range you want to control?
How accurate / precise should it be?

You might need a PID controller.


Rob Tillaart

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

robtillaart

Added the cozir lib to github so it is tracked also outside this thread.
URL: - https://github.com/RobTillaart/Arduino/tree/master/libraries -

current version is 0.1.04,
+ added larger range for CO2()
Rob Tillaart

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

ukcircus

Hi Rob,

Thanks for your work on this library, its helped my project along really nicely. I just installed the 1.04 version and decided to test it with your sketch1.ino file with an UNO (Arduino 1.06). It is now throwing up some errors at me:

/Users/Ukcircus/Documents/Arduino/libraries/cozir/cozir.cpp:232: error: prototype for 'uint32_t COZIR::Request(const char*)' does not match any in class 'COZIR'
/Users/Ukcircus/Documents/Arduino/libraries/cozir/Cozir.h:100: error: candidate is: uint16_t COZIR::Request(const char*)

Version 1.0 of the library still works fine. Unfortunately I don't have enough experience with libraries to really troubleshoot this myself. Any advice?

Thanks

robtillaart

My mistake

you need to     

uint16_t Request(const char* );

into

uint32_t Request(const char* );


in the .h file

I will update github asap
Rob Tillaart

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

robtillaart

updated .h in https://github.com/RobTillaart/Arduino/tree/master/libraries/Cozir
Rob Tillaart

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

ukcircus


robtillaart

You're welcome, if there are more questions let me know.
Rob Tillaart

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

Dew321

Hi RobTillart,

     Do you know of any good PID controllers for regulating the temperature of a heating element and of how to tune the variables? We are currently using the one by brett beauregard (http://playground.arduino.cc/Code/PIDLibrary) but we are having trouble with it, especially with the tuning variables.

       Thanks

robtillaart

Hi Dew321,

these pages about PID tuning might be helpful - http://www.pcbheaven.com/wikipages/PID_Theory/?p=1 -
Rob Tillaart

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

Dew321

Thank you Rob!

    I'm currently using the arduino to heat up a nichrome wire by attaching alligator clips from the arduino wire to the nichrome wire, and then using PWM (through the analogwrite function) to regulate the temperature. However, when I set to analogwrite function to around 80 or more, the serial port will suddenly disconnect. I have verified this, as it works when the alligator clips connecting the nichrome wire to the arduino wire are not attached to it but will disconnect right when the clip meets the wire.
        Would you happen to know why this occurs and how to prevent it? It seems to happen only when I am using the co2 sensor and the heating element on the arduino board at the same time (i put the code regulating both in the same sketch, and it works fine at lower values in the analogwrite)

     

CrossRoads

Gonna smoke your output pin. They are only good for 40mA absolute max. With low analogwrite levels there may be some recovery time between narrow  high pulses - but as they get wider you are really overstressing things, if you haven't damaged the pin already.
The USB port is only good for 500mA, that is likely part of the issue as well.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Dew321

Hi CrossRoads,

     Thank you for your help! Sorry for the cross posts; won't do those again. As for the problem, I fixed it by simply  connecting a 4 battery pack (4 AA batteries--6 v), which got rid of it. 

Go Up