0.3.3 Cozir

This commit is contained in:
rob tillaart 2022-02-21 19:40:59 +01:00
parent 8d4f41738a
commit 8abd8cd3bd
30 changed files with 1073 additions and 242 deletions

View File

@ -8,25 +8,32 @@
# Cozir
Arduino library for COZIR range of temperature, humidity and CO2 sensors.
Arduino library for COZIR range CO2 sensors.
## Description
The Cozir library is **experimental** as I do not have a sensor to test the library.
The polling mode as used in the examples seems to work quite well as this is tested by DirtGambit.
This library supports only the Serial interface. An I2C based library will be written
when I have access to a Cozir sensor that supports I2C.
Idea is to make the interface identical if possible.
The Cozir library is **experimental** as not all functionality is tested.
The polling mode as used in the examples is tested in the past by DirtGambit.
**CO2meter.com** sponsored a **COZIR GC0034** to start hands on testing (2022-02).
This sensor does not support all commands, but as the pattern of the commands
is similar the non-tested are expected to work as well.
This version of the library supports only the **Serial** interface.
Preferred is a hardware Serial port to connect the sensor but software Serial
does work too.
#### Notes
- the **CozirDemoHWSerial.ino** example needs to run on a MEGA or a Teensy,
at least a board with more than one Serial port.
- Read the datasheet before using this library.
It helps to understand the working of the Cozir sensor.
It helps to understand the working of the COZIR sensor.
- Be aware that not all microprocessors have a SoftwareSerial library or one
limited in performance. Polling at 9600 baud can be pretty blocking.
- the hardware serial based examples needs to be run on a MEGA or a Teensy,
at least a board with more than one Serial port.
- If the device is in **CZR_COMMAND** mode it does not respond too polling calls.
It needs to be set to **CZR_POLLING** mode.
- Not all COZIR devices support all calls of this library.
## Interface
@ -36,25 +43,33 @@ Read the datasheet (again).
### Constructor and initialisation
- **COZIR(Stream \* str)** constructor.
- **void init()** sets operatingMode to CZR_POLLING.
- **COZIR(Stream \* str)** constructor, gets a serial stream as reference.
- **void init()** sets operatingMode to **CZR_POLLING**
- **bool isInitialized()** returns true if enough time has passed after the call to **init()** for the sensor.
The sensor needs a few seconds to get correct values.
### Operating mode
- **void setOperatingMode(uint8_t mode)** set the operating mode either to **CZR_COMMAND**, **CZR_POLLING** or **CZR_STREAMING**
- **uint8_t getOperatingMode()** returns the mode set, **CZR_STREAMING** is the default.
- **uint8_t getOperatingMode()** returns the mode set, **CZR_STREAMING** is the factory default.
Please note that **init()** sets the operating mode to **CZR_POLLING**.
### Core
- **float celsius()** idem.
### Core functions
The COZIR CO2 sensors all support:
- **uint32_t CO2()** returns the CO2 concentration in PPM (!! might need PPMfactor).
- **uint16_t getPPMFactor()** returns 1, 10, 100.
Normally the value returned is 1 but one should check at the first read and when there is a big jump in values returned.
Also when time interval between reads is large it might be useful to check the PPM factor.
Some COZIR sensors also support:
- **float celsius()** returns temperature of the sensor.
- **float fahrenheit()** idem, 'wrapper' around **celsius()**
- **float humidity()** idem.
- **float humidity()** idem, 'wrapper' around **celsius()**
- **float light()** idem.
- **uint32_t CO2()** idem.
- **uint16_t getPPMFactor()** returns 1, 10, 100 See Page 14.
### Calibration
@ -62,15 +77,15 @@ Please note that **init()** sets the operating mode to **CZR_POLLING**.
Read datasheet before using these functions:
- **uint16_t fineTuneZeroPoint(uint16_t v1, uint16_t v2)**
- **uint16_t calibrateFreshAir()**
- **uint16_t calibrateFreshAir()** typically 400 PPM.
- **uint16_t calibrateNitrogen()**
- **uint16_t calibrateKnownGas(uint16_t value)**
- **uint16_t calibrateKnownGas(uint16_t value)**
#### Calibration NOT Recommended
Following 3 functions are **NOT RECOMMENDED** by the datasheet.
Feel free to uncomment and use at your own risk.
Feel free to uncomment in the code and use at your own risk.
Read datasheet before using these functions:
- **uint16_t calibrateManual(uint16_t value)**
@ -78,62 +93,72 @@ Read datasheet before using these functions:
- **uint16_t getSpanCalibrate()**
### Digifilter
### DigiFilter
use with care, read datasheet before use.
| value | meaning |
|:-----:|:--------------------------------|
| 0 | Special, see datasheet page ... |
| 1 | fast, but can be noisy |
| 32 | default, good average |
| 255 | slow, max smoothed |
| value | meaning |
|:-----:|:---------------------------------------------------|
| 0 | Special, see datasheet |
| 1 | fast, shows every single sample, raw, can be noisy |
| 32 | default, good average |
| 255 | very slow, max smoothed |
- **void setDigiFilter(uint8_t value)**
- **uint8_t getDigiFilter()**
- **void setDigiFilter(uint8_t value)** The larger the value the more smoothed the signal is.
Larger values also means that the output does not follow fast changes.
So depending on your needs you need to find an optimal value for the project.
It might even so that you alternate between smooth and fast or adapt depending on
the actual CO2 value.
- **uint8_t getDigiFilter()** returns set value.
### Streaming MODE
Warning: Not tested ,
Warning: hardware serial is needed to improve the capture of all output correctly.
- **void setOutputFields(uint16_t fields)** Sets the fields in the output stream as a 16 bit mask. See table below.
- **void clearOutputFields()** clears all the fields.
- **uint16_t getOutputFields()** returns the 16 bit mask of set output fields.
- **bool inOutputFields(uint16_t field)** returns true if the field is set.
- **void getRecentFields()** After a call to getRecentFields() you must read the serial stream yourself.
- **void getRecentFields()** After a call to getRecentFields() you must read and parse the serial stream yourself.
The internal buffer of this Class cannot handle the possible large output. Lines can be over 100 bytes long!
The fields must be set as a bit mask, the order of the fields in the output is undetermined.
So one need to parse the output of the sensor carefully.
| Field | Value | Notes |
|:------------------|:-------|:---------|
| CZR_LIGHT | 0x2000 | |
| CZR_HUMIDITY | 0x1000 | |
| CZR_FILTLED | 0x0800 | |
| CZR_RAWLED | 0x0400 | |
| CZR_MAXLED | 0x0200 | |
| CZR_ZEROPOINT | 0x0100 | |
| CZR_RAWTEMP | 0x0080 | |
| CZR_FILTTEMP | 0x0040 | |
| CZR_FILTLEDSIGNAL | 0x0020 | |
| CZR_RAWLEDSIGNAL | 0x0010 | |
| CZR_SENSTEMP | 0x0008 | |
| CZR_FILTCO2 | 0x0004 | |
| CZR_RAWCO2 | 0x0002 | |
| CZR_NONE | 0x0001 | reset |
| CZR_HTC | 0x1082 | shortcut |
| CZR_ALL | 0x3FFE | debug |
Note: NOT all sensors support all fields, check the datasheet of the sensor used.
| Field | Value HEX | Value DEC | Notes |
|:------------------|:---------:|:---------:|:----------------|
| CZR_LIGHT | 0X2000 | 8192 | |
| CZR_HUMIDITY | 0X1000 | 4096 | |
| CZR_FILTLED | 0X0800 | 2048 | |
| CZR_RAWLED | 0X0400 | 1024 | |
| CZR_MAXLED | 0X0200 | 512 | |
| CZR_ZEROPOINT | 0X0100 | 256 | |
| CZR_RAWTEMP | 0X0080 | 128 | |
| CZR_FILTTEMP | 0X0040 | 64 | |
| CZR_FILTLEDSIGNAL | 0X0020 | 32 | |
| CZR_RAWLEDSIGNAL | 0X0010 | 16 | |
| CZR_SENSTEMP | 0X0008 | 8 | |
| CZR_FILTCO2 | 0X0004 | 4 | |
| CZR_RAWCO2 | 0X0002 | 2 | |
| CZR_NONE | 0X0001 | 1 | reset |
| | | | |
| CZR_DEFAULT | 0X0006 | 6 | factory default |
| CZR_HTC | 0X1082 | 4226 | shortcut |
| CZR_ALL | 0X3FFE | 16383 | debug |
Default value is 6 = CZR_FILTCO2 + CZR_RAWCO2
### EEPROM
Read datasheet Page 11-12 about the addresses and their meaning.
Use with care.
Note: not all COZIR devices support EEPROM.
Check datasheet for the capabilities of your device.
In 0.3.0 the EEPROM function have been replaced by specific accessor
functions. Read datasheet for the details.
In 0.3.0 the EEPROM function have been replaced by specific accessor functions.
Read datasheet about the addresses and their meaning. Use with care.
- **void setAutoCalibrationPreload(uint16_t value)**
- **uint16_t getAutoCalibrationPreload()**
@ -152,7 +177,7 @@ functions. Read datasheet for the details.
#### EEPROM addresses used by above functions.
Read datasheet for the details.
Read datasheet for the details and defaults of sensor at hand.
| Name | Address | Default | Notes |
|:---------|:-------:|:-------:|:---------|
@ -182,26 +207,32 @@ The user should read (and parse) the serial output as it can become large.
Also the user must reset the operating mode either to **CZR_POLLING** or **CZR_STREAMING**
## Future
- improve documentation
- test test test test and buy a sensor
- add a **setEEPROMFactoryDefault()**?
- example two Cozir sensors
- example Cozir with I2C display?
- build a Arduino COZIR simulator for testing.
- add other sensors underneath?
- ...
- Cozir I2C class for newer generation
~ same functional interface
- multiWire / pin a la PCF8574
## Operation
See examples.
## Test sensor
## Future
People who have a spare sensor for me, or are willing to run tests, please contact me.
- improve documentation
- matrix functions vs sensor ?
- test
- test streaming mode
- test table / matrix ?
- add examples
- example COZIR with I2C display?
- example streaming mode parsing.
- COZIR I2C class for newer generation
~ same functional interface
- multiWire / pin a la PCF8574 lib
#### won't for now
- add a **setEEPROMFactoryDefault()**?
- unknown if all sensors have same values
- build a Arduino COZIR simulator for testing.
- add other sensors underneath?

View File

@ -0,0 +1,70 @@
# Cozir Changelog
## 0.3.3 2022-02-21
- update readme,
- update + add examples
- tested with GC0034
- changed return value of **setOperatingMode()** to bool.
- refactor
## 0.3.2 2021-12-14
- update library.json
- license, minor edits
## 0.3.1 2021-10-20
- update Arduino-CI,
- badges in readme.md
## 0.3.0 2021-08-08
- Major update - breaks interface (names mainly)
- add **isInitialized()**
- add **getOperatingMode()**
- add **getOutputFields()**
- add **inOutputFields()**
- add **kelvin()**
- add EEPROM functions
- class methods camelCase
- extend unit tests
## 0.2.6 2021-01-31
- fix #4 use Mode0 for versions and configuration
## 0.2.5 2020-12-26
- fix software Serial + version number (oops)
## 0.2.2 2020-12-17
- add Arduino-CI + unit tests
## 0.2.1 2020-06-05
- fix library.json
## 0.2.0 2020-03-30
- some refactor and own repo
## 0.1.06
- added support for HardwareSerial for MEGA
- removed support for NewSoftSerial
- stop pre 1.0 support)
## 0.1.05
- fixed bug uint16_t request() to uint32_t request() in .h file
## 0.1.04
- changed CO2 to support larger values (Rob T)
## 0.1.03
- added setOperatingMode
## 0.1.02
- added support Arduino 1.x
## 0.1.01
- initial version

View File

@ -1,33 +1,13 @@
//
// FILE: Cozir.cpp
// AUTHOR: DirtGambit & Rob Tillaart
// VERSION: 0.3.2
// VERSION: 0.3.3
// PURPOSE: library for COZIR range of sensors for Arduino
// Polling Mode
// URL: https://github.com/RobTillaart/Cozir
// http://forum.arduino.cc/index.php?topic=91467.0
//
// HISTORY:
// 0.3.2 2021-12-14 update library.json, license, minor edits
// 0.3.1 2021-10-20 update Arduino-CI, badges in readme.md
// 0.3.0 2021-08-08 Major update - breaks interface (names mainly)
// add isInitialized(), add getOperatingMode(),
// add getOutputFields(), add inOutputFields(),
// add kelvin(), add EEPROM functions
// class methods camelCase
// extend unit tests
// 0.2.6 2021-01-31 fix #4 use Mode0 for versions and configuration
// 0.2.5 2020-12-26 fix software Serial + version number (oops)
// 0.2.2 2020-12-17 add Arduino-CI + unit tests
// 0.2.1 2020-06-05 fix library.json
// 0.2.0 2020-03-30 some refactor and own repo
// 0.1.06 added support for HardwareSerial for MEGA (Rob T)
// removed support for NewSoftSerial ==> stop pre 1.0 support)
// 0.1.05 fixed bug: uint16_t request() to uint32_t request() in .h file (Rob T)
// 0.1.04 changed CO2 to support larger values (Rob T)
// 0.1.03 added setOperatingMode
// 0.1.02 added support Arduino 1.x
// 0.1.01 initial version
// HISTORY: see changelog.md
//
// READ DATASHEET BEFORE USE OF THIS LIB !
//
@ -41,7 +21,8 @@
// EEPROM ADRESSES
// P 11-12 manual
// P 11-12 manual WHICH
//
// Name Address Default value/ notes
#define CZR_AHHI 0x00 // reserved
#define CZR_ANLO 0x01 // reserved
@ -93,11 +74,13 @@ bool COZIR::isInitialized()
// CZR_POLLING and CZR_STREAMING use an equally amount
// of power as both sample continuously...
//
void COZIR::setOperatingMode(uint8_t mode)
bool COZIR::setOperatingMode(uint8_t mode)
{
if (mode > CZR_POLLING) return false;
_operatingMode = mode;
sprintf(_buffer, "K %u", mode);
_command(_buffer);
return true;
}
@ -113,7 +96,7 @@ void COZIR::setOperatingMode(uint8_t mode)
float COZIR::celsius()
{
uint16_t rv = _request("T");
return 0.1 * (rv - 1000.0); // P17 negative values
return 0.1 * (rv - 1000.0);
}
@ -147,7 +130,7 @@ uint16_t COZIR::getPPMFactor()
// FineTuneZeroPoint()
// a reading of v1 will be reported as v2
// sort of mapping
// sort of mapping / offset
// check datasheet for detailed description
uint16_t COZIR::fineTuneZeroPoint(uint16_t v1, uint16_t v2)
{
@ -217,7 +200,12 @@ uint8_t COZIR::getDigiFilter()
// you need to set the STREAMING mode explicitly
// SetOperatingMode(CZR_STREAMING);
//
// in STREAMING mode you must parse the output of serial yourself
// in STREAMING mode you must parse the output of serial yourself.
// stream looks like [space field space value]* \n
//
// - find separator ('\n')
// - read until next separator ('\n') in a buffer,
// - parse buffer [field space value]
//
void COZIR::setOutputFields(uint16_t fields)
{
@ -373,14 +361,11 @@ uint32_t COZIR::_request(const char* str)
// read the answer from serial.
// TODO: PROPER TIMEOUT CODE.
// - might be a big delay
// - what is longest answer possible?
// - what is longest answer possible? CZR_REQUEST_TIMEOUT?
uint8_t idx = 0;
uint32_t start = millis();
// while (millis() - start < CZR_REQUEST_TIMEOUT)
delay(CZR_REQUEST_TIMEOUT);
while (true)
while (millis() - start < CZR_REQUEST_TIMEOUT)
{
// delay(1);
if (_ser->available())
{
char c = _ser->read();
@ -389,6 +374,8 @@ uint32_t COZIR::_request(const char* str)
if (c == '\n') break;
}
}
// Serial.print("buffer: ");
// Serial.println(_buffer);
uint32_t rv = atol(&_buffer[2]);
if (idx > 2) return rv;
return 0;

View File

@ -2,7 +2,7 @@
//
// FILE: Cozir.h
// AUTHOR: DirtGambit & Rob Tillaart
// VERSION: 0.3.2
// VERSION: 0.3.3
// PURPOSE: library for COZIR range of sensors for Arduino
// Polling Mode
// URL: https://github.com/RobTillaart/Cozir
@ -15,7 +15,7 @@
#include "Arduino.h"
#define COZIR_LIB_VERSION (F("0.3.2"))
#define COZIR_LIB_VERSION (F("0.3.3"))
// OUTPUTFIELDS
@ -38,6 +38,8 @@
#define CZR_NONE 0x0001
// factory default
#define CZR_DEFAULT (CZR_FILTCO2 | CZR_RAWCO2)
// easy default setting for streaming
#define CZR_HTC (CZR_HUMIDITY | CZR_RAWTEMP | CZR_RAWCO2)
// not in datasheet for debug only
@ -58,10 +60,11 @@ public:
bool isInitialized();
// warning: CZR_STREAMING is experimental, minimal tested.
void setOperatingMode(uint8_t mode);
bool setOperatingMode(uint8_t mode);
uint8_t getOperatingMode() { return _operatingMode; };
// POLLING MODE
float celsius();
float fahrenheit() { return (celsius() * 1.8) + 32; };
float kelvin() { return celsius() + 273.15; };
@ -71,42 +74,43 @@ public:
uint16_t getPPMFactor(); // P14 . command return 1, 10 or 100
// Calibration function, read datasheet before use
// CALIBRATION
// read datasheet before use
uint16_t fineTuneZeroPoint(uint16_t v1, uint16_t v2);
uint16_t calibrateFreshAir();
uint16_t calibrateNitrogen();
uint16_t calibrateKnownGas(uint16_t value);
// WARNING: following 3 functions are NOT RECOMMENDED,
// read datasheet before use
// uint16_t calibrateManual(uint16_t value);
// uint16_t setSpanCalibrate(uint16_t value);
// uint16_t getSpanCalibrate();
// WARNING: following 3 functions are NOT RECOMMENDED,
// read datasheet before use
// uint16_t calibrateManual(uint16_t value);
// uint16_t setSpanCalibrate(uint16_t value);
// uint16_t getSpanCalibrate();
// DIGIFILTER, use with care, read datasheet before use
// 32 = default value = 32,
// 1 = fast (noisy)
// 255 = slow (smoothed)
// DIGIFILTER, use with care, read datasheet before use
// 32 = good default value,
// 1 = fast (noisy and responsive to fast changes)
// 255 = slow (smoothed to the max)
// 0 = special. details see datasheet
void setDigiFilter(uint8_t value);
uint8_t getDigiFilter();
// STREAMING MODE - needs testing...
// STREAMING MODE
void setOutputFields(uint16_t fields);
uint16_t getOutputFields() { return _outputFields; };
bool inOutputFields(uint16_t field);
void clearOutputFields() { setOutputFields(CZR_NONE); };
// WARNING:
// After a call to GetRecentFields() you must read the serial port yourself as
// the internal buffer of this Class cannot handle the possible large output.
// Answers can be over 100 bytes long!
// WARNING:
// After a call to GetRecentFields() you must read the serial port yourself as
// the internal buffer of this Class cannot handle the possible large output.
// Answers can be over 100 bytes long!
void getRecentFields();
// EEPROM
// EEPROM
// not all sensors support these.
void setAutoCalibrationPreload(uint16_t value);
uint16_t getAutoCalibrationPreload();
@ -129,7 +133,9 @@ public:
// TODO test EEPROM function first.
// void setEEPROMFactoryReset();
// META INFORMATION
// META INFORMATION
// library does not parse the output (yet)
void getVersionSerial();
void getConfiguration();
@ -160,3 +166,4 @@ private:
// -- END OF FILE --

View File

@ -1,51 +0,0 @@
//
// FILE: CozirDemoHardwareSerial.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// PURPOSE: demo of Cozir lib (>= 0.1.06)
// DATE: 2015-jan-17
// URL: http://forum.arduino.cc/index.php?topic=91467.0
//
// Note: this sketch needs a MEGA or a Teensy that supports a second
// Serial port named Serial1
#include "cozir.h"
COZIR czr(&Serial1);
void setup()
{
Serial1.begin(9600);
czr.init();
Serial.begin(115200);
Serial.print("Cozir HardwareSerial: ");
Serial.println(COZIR_LIB_VERSION);
Serial.println();
delay(1000);
}
void loop()
{
float t = czr.celsius();
float f = czr.fahrenheit();
float h = czr.humidity();
uint32_t c = czr.CO2();
Serial.print("Celcius =\t"); Serial.println(t);
Serial.print("Fahrenheit =\t"); Serial.println(f);
Serial.print("Humidity =\t"); Serial.println(h);
Serial.print("CO2 =\t"); Serial.println(c);
Serial.println();
delay(3000);
}
// -- END OF FILE --

View File

@ -1,51 +0,0 @@
//
// FILE: CozirDemoSoftwareSerial.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// PURPOSE: demo of Cozir lib
// DATE: 2015-jan-17
// URL: http://forum.arduino.cc/index.php?topic=91467.0
//
#include "cozir.h"
#include "SoftwareSerial.h"
SoftwareSerial sws(3, 2);
COZIR czr(&sws);
void setup()
{
sws.begin(9600);
czr.init();
Serial.begin(9600);
Serial.print("Cozir SoftwareSerial: ");
Serial.println(COZIR_LIB_VERSION);
Serial.println();
delay(1000);
}
void loop()
{
float t = czr.celsius();
float f = czr.fahrenheit();
float h = czr.humidity();
uint32_t c = czr.CO2();
Serial.print("Celcius =\t"); Serial.println(t);
Serial.print("Fahrenheit =\t"); Serial.println(f);
Serial.print("Humidity =\t"); Serial.println(h);
Serial.print("CO2 =\t"); Serial.println(c);
Serial.println();
delay(3000);
}
// -- END OF FILE --

View File

@ -0,0 +1,11 @@
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
# - uno
- due
# - zero
- leonardo
# - m4
# - esp32
# - esp8266
- mega2560

View File

@ -0,0 +1,44 @@
//
// FILE: Cozir_CO2_only.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo of Cozir lib
// URL: https://github.com/RobTillaart/Cozir
// http://forum.arduino.cc/index.php?topic=91467.0
//
// Note: this sketch needs a MEGA or a Teensy that supports a second
// Serial port named Serial1
#include "Arduino.h"
#include "cozir.h"
COZIR czr(&Serial1);
void setup()
{
Serial1.begin(9600);
czr.init();
Serial.begin(115200);
Serial.print("COZIR_LIB_VERSION: ");
Serial.println(COZIR_LIB_VERSION);
Serial.println();
// set to polling explicitly.
czr.setOperatingMode(CZR_POLLING);
delay(1000);
}
void loop()
{
uint32_t c = czr.CO2();
c *= czr.getPPMFactor(); // most of time PPM = one.
Serial.print("CO2 =\t");
Serial.println(c);
delay(1000);
}
// -- END OF FILE --

View File

@ -0,0 +1,11 @@
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
# - uno
# - due
# - zero
# - leonardo
# - m4
# - esp32
# - esp8266
- mega2560

View File

@ -0,0 +1,71 @@
//
// FILE: Cozir_MEGA_3_channel_CO2.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo of Cozir lib
// URL: https://github.com/RobTillaart/Cozir
// http://forum.arduino.cc/index.php?topic=91467.0
//
// Note: this sketch needs a MEGA or another board that supports three
// hardware serial ports named Serial1, Serial2, Serial3.
#include "Arduino.h"
#include "cozir.h"
COZIR czr[3] = { COZIR(&Serial1), COZIR(&Serial2), COZIR(&Serial3)};
uint16_t lastCO2[3] = {0, 0, 0};
uint32_t lastRead = 0;
void setup()
{
Serial.begin(115200);
Serial.print("COZIR_LIB_VERSION: ");
Serial.println(COZIR_LIB_VERSION);
Serial.println();
Serial.println("...initializing serial ports...");
Serial1.begin(9600);
Serial2.begin(9600);
Serial3.begin(9600);
Serial.print("...initializing COZIR objects...");
for (int i = 0; i < 3; i++)
{
Serial.print(i);
czr[i].init();
}
Serial.println();
// set to polling explicitly.
Serial.print("...set POLLING mode...");
for (int i = 0; i < 3; i++)
{
Serial.print(i);
czr[i].setOperatingMode(CZR_POLLING);
}
Serial.println();
}
void loop()
{
if (millis() - lastRead >= 1000)
{
for (int i = 0; i < 3; i++)
{
lastCO2[i] = czr[i].CO2(); // add * czr.getPPMFactor(); most of time PPM = one.
Serial.print(lastCO2[i]);
Serial.print("\t");
}
Serial.println();
}
// insert other code here
}
// -- END OF FILE --

View File

@ -0,0 +1,11 @@
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
# - due
# - zero
- leonardo
# - m4
# - esp32
# - esp8266
# - mega2560

View File

@ -0,0 +1,44 @@
//
// FILE: Cozir_SWSerial_CO2_only.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo of Cozir lib (>= 0.1.06)
// URL: https://github.com/RobTillaart/Cozir
// http://forum.arduino.cc/index.php?topic=91467.0
// NOTE: software serial is less reliable than hardware serial
#include "Arduino.h"
#include "cozir.h"
#include "SoftwareSerial.h"
SoftwareSerial sws(3, 2); // RX, TX, optional inverse logic
COZIR czr(&sws);
void setup()
{
sws.begin(9600);
czr.init();
Serial.begin(115200);
Serial.print("COZIR_LIB_VERSION: ");
Serial.println(COZIR_LIB_VERSION);
Serial.println();
// set to polling explicitly.
czr.setOperatingMode(CZR_POLLING);
delay(1000);
}
void loop()
{
uint32_t c = czr.CO2();
Serial.print("CO2 =\t");
Serial.println(c);
delay(1000);
}
// -- END OF FILE --

View File

@ -2,4 +2,10 @@ compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
# - due
# - zero
- leonardo
# - m4
# - esp32
# - esp8266
# - mega2560

View File

@ -0,0 +1,45 @@
//
// FILE: Cozir_SWSerial_echo.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo of Cozir sensor
// URL: https://github.com/RobTillaart/Cozir
// http://forum.arduino.cc/index.php?topic=91467.0
// NOTE: software serial is less reliable than hardware serial
//
// The purpose of this sketch is to talk lowest level to the COZIR sensor.
// one can send the low level commands (datasheet) directly to the device.
// Note: this can cause (unwanted) side effects, so use with care.
#include "Arduino.h"
#include "cozir.h" // not perse needed
#include "SoftwareSerial.h"
SoftwareSerial sws(3, 2); // RX, TX, optional inverse logic
void setup()
{
sws.begin(9600);
Serial.begin(9600);
Serial.println(__FILE__);
Serial.println();
}
void loop()
{
if (Serial.available())
{
sws.write(Serial.read());
}
if (sws.available())
{
Serial.write(sws.read());
}
}
// -- END OF FILE --

View File

@ -0,0 +1,11 @@
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
# - due
# - zero
- leonardo
# - m4
# - esp32
# - esp8266
# - mega2560

View File

@ -0,0 +1,69 @@
//
// FILE: Cozir_SWSerial_getVersion.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo of Cozir lib
// URL: https://github.com/RobTillaart/Cozir
// http://forum.arduino.cc/index.php?topic=91467.0
// NOTE: software serial is less reliable than hardware serial
#include "Arduino.h"
#include "cozir.h"
#include "SoftwareSerial.h"
SoftwareSerial sws(3, 2); // RX, TX, optional inverse logic
COZIR czr(&sws);
void setup()
{
sws.begin(9600);
czr.init();
Serial.begin(115200);
Serial.print("COZIR_LIB_VERSION: ");
Serial.println(COZIR_LIB_VERSION);
Serial.println();
delay(100);
czr.getVersionSerial();
delay(5);
while (sws.available())
{
Serial.write(sws.read());
}
delay(100);
czr.getConfiguration();
delay(5);
while (sws.available())
{
Serial.write(sws.read());
}
delay(1000);
// set to polling explicitly.
czr.setOperatingMode(CZR_POLLING);
delay(1000);
}
void loop()
{
float t = czr.celsius();
float f = czr.fahrenheit();
float h = czr.humidity();
uint32_t c = czr.CO2();
Serial.print("Celsius =\t"); Serial.println(t);
Serial.print("Fahrenheit =\t"); Serial.println(f);
Serial.print("Humidity =\t"); Serial.println(h);
Serial.print("CO2 =\t"); Serial.println(c);
Serial.println();
delay(3000);
}
// -- END OF FILE --

View File

@ -0,0 +1,12 @@
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
# - due
# - zero
- leonardo
# - m4
# - esp32
# - esp8266
# - mega2560

View File

@ -0,0 +1,147 @@
//
// FILE: Cozir_SWSerial_getVersion.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo of Cozir lib
// URL: https://github.com/RobTillaart/Cozir
// http://forum.arduino.cc/index.php?topic=91467.0
// NOTE: software serial is less reliable than hardware serial
#include "Arduino.h"
#include "cozir.h"
#include "SoftwareSerial.h"
SoftwareSerial sws(3, 2); // RX, TX, optional inverse logic
COZIR czr(&sws);
void setup()
{
sws.begin(9600);
czr.init();
Serial.begin(115200);
Serial.print("COZIR_LIB_VERSION: ");
Serial.println(COZIR_LIB_VERSION);
Serial.println();
// set to polling.
czr.setOperatingMode(CZR_POLLING);
delay(1000);
menu();
}
void loop()
{
if (Serial.available())
{
char c = Serial.read();
switch (toupper(c))
{
case '1':
czr.setOperatingMode(CZR_STREAMING);
break;
case '2':
czr.setOperatingMode(CZR_POLLING);
menu();
break;
case 'Z':
if (czr.getOperatingMode() != 0)
{
Serial.print("CO2:\t");
Serial.println(czr.CO2());
}
break;
case 'T':
if (czr.getOperatingMode() != 0)
{
Serial.print("Temp:\t");
Serial.println(czr.celsius(), 1);
}
break;
case 'H':
if (czr.getOperatingMode() != 0)
{
Serial.print("Humid:\t");
Serial.println(czr.humidity(), 1);
}
break;
case 'L':
if (czr.getOperatingMode() != 0)
{
Serial.print("Light:\t");
Serial.println(czr.light(), 1);
}
break;
case 'P':
if (czr.getOperatingMode() != 0)
{
Serial.print("PPM:\t");
Serial.println(czr.getPPMFactor());
}
break;
case 'G':
if (czr.getOperatingMode() != 0)
{
// use with care
// Serial.println(czr.calibrateFreshAir());
}
break;
case 'N':
if (czr.getOperatingMode() != 0)
{
// use with care
// Serial.println(czr.calibrateNitrogen());
}
break;
case 'V':
czr.getVersionSerial();
break;
case 'C':
czr.getConfiguration();
break;
case '?':
menu();
break;
}
}
// for echo in continuous mode.
if (sws.available())
{
Serial.write(sws.read());
}
}
void menu()
{
Serial.println();
Serial.println("-- COZIR GC0034 --");
Serial.println();
Serial.println(" 1 Continuous mode");
Serial.println(" 2 Polling mode");
Serial.println();
Serial.println(" G calibrate fresh air = 400 ppm (use with care)");
Serial.println(" N calibrate nitrogen (use with care)");
Serial.println();
Serial.println(" Z get CO2");
Serial.println(" P get PPM factor");
Serial.println();
Serial.println(" T get Temperature");
Serial.println(" H get Humidity");
Serial.println(" L get Light");
Serial.println();
Serial.println(" V version info");
Serial.println(" C Configuration info");
Serial.println();
Serial.println(" ? menu");
Serial.println();
}
// -- END OF FILE --

View File

@ -1,6 +1,11 @@
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- leonardo
# - uno
- due
- zero
# - zero
- leonardo
# - m4
# - esp32
# - esp8266
- mega2560

View File

@ -0,0 +1,46 @@
//
// FILE: Cozir_echo.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo of Cozir sensor
// URL: https://github.com/RobTillaart/Cozir
// http://forum.arduino.cc/index.php?topic=91467.0
//
// Note: this sketch needs a MEGA or a Teensy that supports a second
// Serial port named Serial1
// The purpose of this sketch is to talk lowest level to the COZIR sensor.
// one can send the low level commands (datasheet) directly to the device.
// Note: this can cause (unwanted) side effects, so use with care.
#include "Arduino.h"
#include "cozir.h" // not perse needed
COZIR czr(&Serial1);
void setup()
{
Serial1.begin(9600);
Serial.begin(9600);
Serial.println(__FILE__);
Serial.println();
}
void loop()
{
if (Serial.available())
{
Serial1.write(Serial.read());
}
if (Serial1.available())
{
Serial.write(Serial1.read());
}
}
// -- END OF FILE --

View File

@ -1,6 +1,11 @@
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- leonardo
# - uno
- due
- zero
# - zero
- leonardo
# - m4
# - esp32
# - esp8266
- mega2560

View File

@ -1,16 +1,15 @@
//
// FILE: Cozir_getVersion.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: demo of Cozir lib (>= 0.1.06)
// DATE: 2021-01-31
// URL: http://forum.arduino.cc/index.php?topic=91467.0
// PURPOSE: demo of Cozir lib
// URL: https://github.com/RobTillaart/Cozir
// http://forum.arduino.cc/index.php?topic=91467.0
//
// Note: this sketch needs a MEGA or a Teensy that supports a second
// Serial port named Serial1
#include "Arduino.h"
#include "cozir.h"
COZIR czr(&Serial1);
@ -20,9 +19,9 @@ void setup()
{
Serial1.begin(9600);
czr.init();
Serial.begin(115200);
Serial.print("Cozir HardwareSerial: ");
Serial.print("COZIR_LIB_VERSION: ");
Serial.println(COZIR_LIB_VERSION);
Serial.println();
@ -43,8 +42,9 @@ void setup()
}
delay(1000);
// reset to polling again.
// set to polling explicitly.
czr.setOperatingMode(CZR_POLLING);
delay(1000);
}
@ -55,7 +55,7 @@ void loop()
float h = czr.humidity();
uint32_t c = czr.CO2();
Serial.print("Celcius =\t"); Serial.println(t);
Serial.print("Celsius =\t"); Serial.println(t);
Serial.print("Fahrenheit =\t"); Serial.println(f);
Serial.print("Humidity =\t"); Serial.println(h);
Serial.print("CO2 =\t"); Serial.println(c);

View File

@ -0,0 +1,11 @@
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
# - uno
- due
# - zero
- leonardo
# - m4
# - esp32
# - esp8266
- mega2560

View File

@ -0,0 +1,142 @@
//
// FILE: Cozir_interactive.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo of Cozir lib
// URL: https://github.com/RobTillaart/Cozir
// http://forum.arduino.cc/index.php?topic=91467.0
//
#include "Arduino.h"
#include "cozir.h"
COZIR czr(&Serial1);
void setup()
{
Serial1.begin(9600);
czr.init();
Serial.begin(115200);
Serial.print("COZIR_LIB_VERSION: ");
Serial.println(COZIR_LIB_VERSION);
Serial.println();
// set to polling.
czr.setOperatingMode(CZR_POLLING);
delay(1000);
menu();
}
void loop()
{
if (Serial.available())
{
char c = Serial.read();
switch (toupper(c))
{
case '1':
czr.setOperatingMode(CZR_STREAMING);
break;
case '2':
czr.setOperatingMode(CZR_POLLING);
menu();
break;
case 'Z':
if (czr.getOperatingMode() != 0)
{
Serial.print("CO2:\t");
Serial.println(czr.CO2());
}
break;
case 'T':
if (czr.getOperatingMode() != 0)
{
Serial.print("Temp:\t");
Serial.println(czr.celsius(), 1);
}
break;
case 'H':
if (czr.getOperatingMode() != 0)
{
Serial.print("Humid:\t");
Serial.println(czr.humidity(), 1);
}
break;
case 'L':
if (czr.getOperatingMode() != 0)
{
Serial.print("Light:\t");
Serial.println(czr.light(), 1);
}
break;
case 'P':
if (czr.getOperatingMode() != 0)
{
Serial.print("PPM:\t");
Serial.println(czr.getPPMFactor());
}
break;
case 'G':
if (czr.getOperatingMode() != 0)
{
// use with care
// Serial.println(czr.calibrateFreshAir());
}
break;
case 'N':
if (czr.getOperatingMode() != 0)
{
// use with care
// Serial.println(czr.calibrateNitrogen());
}
break;
case 'V':
czr.getVersionSerial();
break;
case 'C':
czr.getConfiguration();
break;
case '?':
menu();
break;
}
}
// for echo in continuous mode.
if (Serial1.available())
{
Serial.write(Serial1.read());
}
}
void menu()
{
Serial.println();
Serial.println("-- COZIR GC0034 --");
Serial.println();
Serial.println(" 1 Continuous mode");
Serial.println(" 2 Polling mode");
Serial.println();
Serial.println(" G calibrate fresh air = 400 ppm (use with care)");
Serial.println(" N calibrate nitrogen (use with care)");
Serial.println();
Serial.println(" Z get CO2");
Serial.println(" P get PPM factor");
Serial.println();
Serial.println(" T get Temperature");
Serial.println(" H get Humidity");
Serial.println(" L get Light");
Serial.println();
Serial.println(" V version info");
Serial.println(" C Configuration info");
Serial.println();
Serial.println(" ? menu");
Serial.println();
}
// -- END OF FILE --

View File

@ -0,0 +1,11 @@
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
# - uno
- due
# - zero
- leonardo
# - m4
# - esp32
# - esp8266
- mega2560

View File

@ -0,0 +1,62 @@
//
// FILE: Cozir_setDigiFilter.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo of Cozir lib
// URL: https://github.com/RobTillaart/Cozir
// http://forum.arduino.cc/index.php?topic=91467.0
//
// Note: this sketch needs a MEGA or a Teensy that supports a second
// Serial port named Serial1
#include "Arduino.h"
#include "cozir.h"
COZIR czr(&Serial1);
uint8_t filter = 1;
uint8_t count = 0;
void setup()
{
Serial1.begin(9600);
czr.init();
Serial.begin(115200);
Serial.print("COZIR_LIB_VERSION: ");
Serial.println(COZIR_LIB_VERSION);
Serial.println();
czr.setOperatingMode(CZR_STREAMING);
delay(1000);
}
void loop()
{
if (Serial1.available())
{
char c = Serial1.read();
Serial.write(c);
if (c == '\n')
{
count++;
Serial.print(count);
Serial.print('\t');
Serial.print(filter); // or print czr.getDigiFilter()
Serial.print('\t');
if (count >= 10)
{
count = 0;
filter *= 2;
if (filter == 0) filter = 1;
czr.setDigiFilter(filter);
}
}
}
}
// -- END OF FILE --

View File

@ -0,0 +1,11 @@
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
# - uno
- due
# - zero
- leonardo
# - m4
- esp32
# - esp8266
# - mega2560

View File

@ -0,0 +1,63 @@
//
// FILE: Cozir_setOutputFields.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo of Cozir lib
// URL: https://github.com/RobTillaart/Cozir
// http://forum.arduino.cc/index.php?topic=91467.0
//
// Note: this sketch needs a MEGA or a Teensy that supports a second
// Serial port named Serial1
// Note: not all fields are supported by all COZIR sensors.
#include "Arduino.h"
#include "cozir.h"
COZIR czr(&Serial1);
uint16_t fields = 2;
uint8_t count = 0;
void setup()
{
Serial1.begin(9600);
czr.init();
Serial.begin(115200);
Serial.print("COZIR_LIB_VERSION: ");
Serial.println(COZIR_LIB_VERSION);
Serial.println();
czr.setOperatingMode(CZR_STREAMING);
delay(1000);
}
void loop()
{
if (Serial1.available())
{
char c = Serial1.read();
Serial.write(c);
if (c == '\n')
{
count++;
Serial.print(count);
Serial.print('\t');
Serial.print(fields); // or print czr.getDigiFilter()
Serial.print('\t');
if (count >= 10)
{
count = 0;
fields *= 2;
if (fields == 16384) fields = 2;
czr.setOutputFields(fields);
}
}
}
}
// -- END OF FILE --

View File

@ -18,7 +18,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/Cozir.git"
},
"version": "0.3.2",
"version": "0.3.3",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=Cozir
version=0.3.2
version=0.3.3
author=Rob Tillaart <rob.tillaart@gmail.com>, DirtGambit
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for COZIR range of CO2 sensors. Polling mode only.