Skip to content

Commit d76f508

Browse files
committed
0.3.4 Cozir
1 parent 32c21b5 commit d76f508

File tree

14 files changed

+457
-11
lines changed

14 files changed

+457
-11
lines changed

libraries/Cozir/README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ This version of the library supports only the **Serial** interface.
2323
Preferred is a hardware Serial port to connect the sensor but software Serial
2424
does work too.
2525

26+
The library (since 0.3.4) a separate class to parse the STREAMING data.
27+
See COZIRParser below.
28+
The Cozir class is focussed on polling and sending commands.
29+
30+
2631
#### Notes
2732

2833
- Read the datasheet before using this library.
@@ -212,16 +217,41 @@ Also the user must reset the operating mode either to **CZR_POLLING** or **CZR_S
212217
See examples.
213218

214219

220+
## COZIRParser
221+
222+
Class to parse the output of a COZIR sensor in stream mode.
223+
224+
## Description
225+
226+
(added in 0.3.4, experimental)
227+
228+
The COZIRparser object has a main function called **nextChar(c)**
229+
It needs to be called with all incoming characters from the sensor.
230+
231+
If a new field is found **nextChar()** returns the field identifier
232+
of the last parsed field (single char) to indicate its value has been
233+
updated, otherwise it returns 0.
234+
The updated value can be accessed with one of the functions, see cozir.h file.
235+
236+
An example **Cozir_stream_parse.ino** is added to show how to use this class.
237+
238+
Note: to send commands e.g. outputField selection, to the sensor the COZIR
239+
class is used (which is mostly focussed on polling access).
240+
241+
242+
215243
## Future
216244

217245
- improve documentation
246+
- COZIR Parser a separate readme?
218247
- matrix functions vs sensor ?
219248
- test
220249
- test streaming mode
221250
- test table / matrix ?
222251
- add examples
223252
- example COZIR with I2C display?
224-
- example streaming mode parsing.
253+
- example with GREEN YELLOW RED LED?
254+
- examples for COZIRParser.
225255
- COZIR I2C class for newer generation
226256
~ same functional interface
227257
- multiWire / pin a la PCF8574 lib

libraries/Cozir/changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
# Cozir Changelog
33

44

5+
## 0.3.4 2022-02-22
6+
- added COZIRParser class for streaming mode
7+
- added streaming examples
8+
- minor edits
9+
10+
511
## 0.3.3 2022-02-21
612
- update readme,
713
- update + add examples

libraries/Cozir/cozir.cpp

Lines changed: 132 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: Cozir.cpp
33
// AUTHOR: DirtGambit & Rob Tillaart
4-
// VERSION: 0.3.3
4+
// VERSION: 0.3.4
55
// PURPOSE: library for COZIR range of sensors for Arduino
66
// Polling Mode
77
// URL: https://github.com/RobTillaart/Cozir
@@ -417,4 +417,135 @@ uint16_t COZIR::_getEEPROM2(uint8_t address)
417417

418418

419419

420+
////////////////////////////////////////////////////////////////////////////////
421+
//
422+
// C0ZIRParser
423+
//
424+
C0ZIRParser::C0ZIRParser()
425+
{
426+
init();
427+
}
428+
429+
430+
void C0ZIRParser::init()
431+
{
432+
_light = 0;
433+
_humidity = 0;
434+
_LED_FILT = 0;
435+
_LED_RAW = 0;
436+
_LED_MAX = 0;
437+
_zeroPoint = 0;
438+
_temperature_RAW = 0;
439+
_temperature_FILT = 0;
440+
_LED_signal_FILT = 0;
441+
_LED_signal_RAW = 0;
442+
_temperature_Sensor = 0;
443+
_CO2_FILT = 0;
444+
_CO2_RAW = 0;
445+
_samples = 0;
446+
_PPM = 1; // Note default one
447+
_value = 0;
448+
_field = 0;
449+
}
450+
451+
452+
uint8_t C0ZIRParser::nextChar(char c)
453+
{
454+
uint8_t rv = 0;
455+
switch(c)
456+
{
457+
case '0' ... '9':
458+
_value *= 10;
459+
_value += (c - '0');
460+
break;
461+
case 'L':
462+
case 'T':
463+
case 'H':
464+
case 'z':
465+
case 'Z':
466+
case 'A':
467+
case 'P':
468+
rv = store();
469+
_field = c;
470+
_value = 0;
471+
break;
472+
default:
473+
break;
474+
}
475+
return rv;
476+
}
477+
478+
479+
float C0ZIRParser::celsius()
480+
{
481+
return 0.1 * (_temperature_FILT - 1000.0);
482+
}
483+
484+
485+
//////////////////////////////////
486+
//
487+
// PRIVATE
488+
//
489+
uint8_t C0ZIRParser::store()
490+
{
491+
switch(_field)
492+
{
493+
// LIGHT related
494+
case 'L':
495+
_light = _value;
496+
return _field;
497+
case 'D':
498+
_LED_FILT = _value;
499+
return _field;
500+
case 'd':
501+
_LED_RAW = _value;
502+
return _field;
503+
case 'l':
504+
_LED_MAX = _value;
505+
return _field;
506+
case 'o':
507+
_LED_signal_FILT = _value;
508+
return _field;
509+
case 'O':
510+
_LED_signal_RAW = _value;
511+
return _field;
512+
513+
// TEMPERATURE & HUMIDITY
514+
case 'V':
515+
_temperature_RAW = _value;
516+
return _field;
517+
case 'v':
518+
_temperature_Sensor = _value;
519+
return _field;
520+
case 'T':
521+
_temperature_FILT = _value;
522+
return _field;
523+
case 'H':
524+
_humidity = _value;
525+
return _field;
526+
527+
// CO2 related
528+
case 'z':
529+
_CO2_RAW = _value;
530+
return _field;
531+
case 'Z':
532+
_CO2_FILT = _value;
533+
return _field;
534+
535+
// OTHER
536+
case 'h':
537+
_zeroPoint = _value;
538+
return _field;
539+
case 'a':
540+
_samples = _value;
541+
return _field;
542+
case '.':
543+
_PPM = _value;
544+
return _field;
545+
}
546+
return 0;
547+
}
548+
549+
420550
// -- END OF FILE --
551+

libraries/Cozir/cozir.h

Lines changed: 79 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#pragma once
22
//
33
// FILE: Cozir.h
4-
// AUTHOR: DirtGambit & Rob Tillaart
5-
// VERSION: 0.3.3
4+
// VERSION: 0.3.4
65
// PURPOSE: library for COZIR range of sensors for Arduino
76
// Polling Mode
87
// URL: https://github.com/RobTillaart/Cozir
@@ -15,12 +14,15 @@
1514
#include "Arduino.h"
1615

1716

18-
#define COZIR_LIB_VERSION (F("0.3.3"))
17+
#define COZIR_LIB_VERSION (F("0.3.4"))
1918

2019

21-
// OUTPUTFIELDS
20+
// OUTPUT FIELDS
2221
// See datasheet for details.
2322
// These defines can be OR-ed for the SetOutputFields command
23+
//
24+
#define CZR_UNKNOWN_2 0x8000 // returns P 00128 ?
25+
#define CZR_UNKNOWN_1 0x4000 // returns E 00016 ?
2426
#define CZR_LIGHT 0x2000
2527
#define CZR_HUMIDITY 0x1000
2628
#define CZR_FILTLED 0x0800
@@ -165,5 +167,78 @@ class COZIR
165167
};
166168

167169

170+
171+
////////////////////////////////////////////////////////////////////////////////
172+
//
173+
// C0ZIRParser
174+
//
175+
// used to parse the stream from a COZIR CO2 sensor.
176+
// Note: one can comment fields / code not used to minimize footprint.
177+
//
178+
class C0ZIRParser
179+
{
180+
public:
181+
C0ZIRParser();
182+
183+
void init();
184+
185+
// returns field char if a field is completed, 0 otherwise.
186+
uint8_t nextChar(char c);
187+
188+
// FETCH LAST READ VALUES
189+
float celsius();
190+
float fahrenheit() { return (celsius() * 1.8) + 32; };
191+
float kelvin() { return celsius() + 273.15; };
192+
float humidity() { return 0.1 * _humidity; };
193+
194+
uint16_t light() { return _light; };
195+
uint16_t ledFilt() { return _LED_FILT; };
196+
uint16_t ledRaw() { return _LED_RAW; };
197+
uint16_t ledMax() { return _LED_MAX; };
198+
uint16_t ledSignalFilt() { return _LED_signal_FILT; };
199+
uint16_t ledSignalRaw() { return _LED_signal_RAW; };
200+
201+
uint16_t zeroPoint() { return _zeroPoint; };
202+
uint16_t tempFilt() { return _temperature_FILT; };
203+
uint16_t tempRaw() { return _temperature_RAW; };
204+
uint16_t tempSensor() { return _temperature_Sensor; };
205+
206+
uint16_t CO2() { return _CO2_FILT; };
207+
uint16_t CO2Raw() { return _CO2_RAW; };
208+
209+
uint16_t samples() { return _samples; };
210+
uint16_t getPPMFactor() { return _PPM; }
211+
212+
213+
private:
214+
// FIELD ID character
215+
uint16_t _light; // L
216+
uint16_t _humidity; // H
217+
uint16_t _LED_FILT; // D
218+
uint16_t _LED_RAW; // d
219+
uint16_t _LED_MAX; // l // el not one
220+
uint16_t _zeroPoint; // h
221+
uint16_t _temperature_RAW; // V
222+
uint16_t _temperature_FILT; // T
223+
uint16_t _LED_signal_FILT; // o // oo not zero
224+
uint16_t _LED_signal_RAW; // O // oo not zero
225+
uint16_t _temperature_Sensor; // v
226+
uint16_t _CO2_FILT; // Z
227+
uint16_t _CO2_RAW; // z
228+
229+
// not output fields sec but useful.
230+
uint16_t _samples; // a
231+
uint16_t _PPM; // . // point
232+
233+
234+
// parsing helpers
235+
uint32_t _value;
236+
uint8_t _field;
237+
238+
// returns field char if a field is completed, 0 otherwise.
239+
uint8_t store();
240+
};
241+
242+
168243
// -- END OF FILE --
169244

libraries/Cozir/examples/Cozir_SWSerial_echo/Cozir_SWSerial_echo.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void setup()
2222
{
2323
sws.begin(9600);
2424

25-
Serial.begin(9600);
25+
Serial.begin(115200);
2626
Serial.println(__FILE__);
2727
Serial.println();
2828

libraries/Cozir/examples/Cozir_echo/Cozir_echo.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void setup()
2323
{
2424
Serial1.begin(9600);
2525

26-
Serial.begin(9600);
26+
Serial.begin(115200);
2727
Serial.println(__FILE__);
2828
Serial.println();
2929

libraries/Cozir/examples/Cozir_interactive/Cozir_interactive.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ void loop()
3737
char c = Serial.read();
3838
switch (toupper(c))
3939
{
40+
case '0':
41+
czr.setOperatingMode(CZR_COMMAND);
42+
break;
4043
case '1':
4144
czr.setOperatingMode(CZR_STREAMING);
4245
break;
@@ -118,6 +121,7 @@ void menu()
118121
Serial.println();
119122
Serial.println("-- COZIR GC0034 --");
120123
Serial.println();
124+
Serial.println(" 0 Command mode (low power)");
121125
Serial.println(" 1 Continuous mode");
122126
Serial.println(" 2 Polling mode");
123127
Serial.println();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
compile:
2+
# Choosing to run compilation tests on 2 different Arduino platforms
3+
platforms:
4+
# - uno
5+
- due
6+
# - zero
7+
- leonardo
8+
# - m4
9+
# - esp32
10+
# - esp8266
11+
- mega2560

0 commit comments

Comments
 (0)