Skip to content

Commit d593f36

Browse files
committed
0.3.5 Cozir
1 parent e146531 commit d593f36

File tree

23 files changed

+414
-71
lines changed

23 files changed

+414
-71
lines changed

libraries/Cozir/README.md

Lines changed: 68 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Arduino library for COZIR range CO2 sensors.
1313

1414
## Description
1515

16-
The Cozir library is **experimental** as not all functionality is tested.
16+
The COZIR library is **experimental** as not all functionality is tested.
1717
The polling mode as used in the examples is tested in the past by DirtGambit.
1818
**CO2meter.com** sponsored a **COZIR GC0034** to start hands on testing (2022-02).
1919
This sensor does not support all commands, but as the pattern of the commands
@@ -25,7 +25,7 @@ does work too.
2525

2626
The library (since 0.3.4) a separate class to parse the STREAMING data.
2727
See COZIRParser below.
28-
The Cozir class is focussed on polling and sending commands.
28+
The COZIR class is focussed on polling and sending commands.
2929

3030

3131
#### Notes
@@ -41,7 +41,7 @@ It needs to be set to **CZR_POLLING** mode.
4141
- Not all COZIR devices support all calls of this library.
4242

4343

44-
## Interface
44+
## Interface Cozir
4545

4646
Read the datasheet (again).
4747

@@ -109,6 +109,7 @@ use with care, read datasheet before use.
109109
| 32 | default, good average |
110110
| 255 | very slow, max smoothed |
111111

112+
112113
- **void setDigiFilter(uint8_t value)** The larger the value the more smoothed the signal is.
113114
Larger values also means that the output does not follow fast changes.
114115
So depending on your needs you need to find an optimal value for the project.
@@ -119,7 +120,7 @@ the actual CO2 value.
119120

120121
### Streaming MODE
121122

122-
Warning: hardware serial is needed to improve the capture of all output correctly.
123+
Warning: hardware serial is needed / recommended to improve the capture of all output correctly.
123124

124125
- **void setOutputFields(uint16_t fields)** Sets the fields in the output stream as a 16 bit mask. See table below.
125126
- **void clearOutputFields()** clears all the fields.
@@ -154,7 +155,8 @@ Note: NOT all sensors support all fields, check the datasheet of the sensor used
154155
| CZR_HTC | 0X1082 | 4226 | shortcut |
155156
| CZR_ALL | 0X3FFE | 16383 | debug |
156157

157-
Default value is 6 = CZR_FILTCO2 + CZR_RAWCO2
158+
159+
Default value is CZR_DEFAULT == 6 == CZR_FILTCO2 + CZR_RAWCO2
158160

159161

160162
### EEPROM
@@ -217,10 +219,34 @@ Also the user must reset the operating mode either to **CZR_POLLING** or **CZR_S
217219
See examples.
218220

219221

222+
## Future
223+
224+
- improve documentation
225+
- COZIR Parser a separate readme?
226+
- add examples
227+
- example COZIR with I2C display?
228+
- COZIR I2C class for newer generation
229+
~ same functional interface
230+
- multiWire / pin a la PCF8574 lib
231+
232+
233+
#### won't for now
234+
235+
- add a **setEEPROMFactoryDefault()**?
236+
- unknown if all sensors have same values
237+
- build a Arduino COZIR simulator for testing.
238+
- add other sensors underneath?
239+
240+
241+
242+
----
243+
244+
220245
## COZIRParser
221246

222247
Class to parse the output of a COZIR sensor in stream mode.
223248

249+
224250
## Description
225251

226252
(added in 0.3.4, experimental)
@@ -235,34 +261,51 @@ The updated value can be accessed with one of the functions, see cozir.h file.
235261

236262
An example **Cozir_stream_parse.ino** is added to show how to use this class.
237263

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).
264+
**NOTE:** to send commands e.g. outputField selection, to the sensor the COZIR
265+
class can be used (which is mostly focussed on polling access).
266+
Alternatively the user sends the low level commands just as a string over serial.
267+
This latter method will save memory especially in a final version of a project.
268+
269+
**NOTE:** The COZIRparser skips the output of the Y, \* and @ command.
270+
These are configuration fields and therefore not part of the **stream mode** fields.
271+
Furthermore not all fields these lines produce are understood.
272+
So parsing these lines is left to the user for now.
273+
274+
**NOTE:** The COZIRparser class does not check for missing characters,
275+
the range of the fields recognized, or other errors. So the values
276+
returned should be handled with care.
277+
278+
279+
## Interface COZIRParser
280+
281+
Read the datasheet (again).
282+
283+
284+
### Constructor and initialisation
285+
286+
- **C0ZIRParser()** constructor
287+
- **void init()** resets all internal variables to 0 except PPM (set to 1)
288+
- **void resetParser()** should / could be called if stream from sensor is
289+
interrupted for long period, e.g. if there are missing characters.
290+
This should prevent the parser to overshoot a value due to concatenating the
291+
value of different (interrupted) measurements or FIELDs.
292+
- **uint8_t nextChar(char c)** all characters coming from the sensor should
293+
be send to the parser by means of **nextChar()**.
294+
Default it will return 0 and the FIELD character is a field has been updated.
295+
Read Datasheet for the characters used.
240296

297+
The remainder of the interface are getters for the different fields.
241298

242299

243300
## Future
244301

245302
- improve documentation
246303
- COZIR Parser a separate readme?
247-
- matrix functions vs sensor ?
248-
- test
249-
- test streaming mode
250-
- test table / matrix ?
304+
- support splitting output of Y and \* command.
305+
- separate parser COZIRParserY()
306+
- separate parser COZIRParserStar()
307+
- separate parser COZIRParser@()
251308
- add examples
252-
- example COZIR with I2C display?
253-
- example with GREEN YELLOW RED LED?
254309
- examples for COZIRParser.
255-
- COZIR I2C class for newer generation
256-
~ same functional interface
257-
- multiWire / pin a la PCF8574 lib
258310

259311

260-
#### won't for now
261-
262-
- add a **setEEPROMFactoryDefault()**?
263-
- unknown if all sensors have same values
264-
- build a Arduino COZIR simulator for testing.
265-
- add other sensors underneath?
266-
267-
268-

libraries/Cozir/changelog.md

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

44

5+
## 0.3.5 2022-02-25
6+
- added capturing mode 'K' field in the COZIRParser class
7+
- added all known fields in the COZIRParser class
8+
- added sending commands in stream parser example to test.
9+
- added example with adaptive timing depending on CO21 level.
10+
- verify requested field in **_request()**
11+
- minor edits.
12+
13+
514
## 0.3.4 2022-02-22
615
- added COZIRParser class for streaming mode
716
- added streaming examples

libraries/Cozir/cozir.cpp

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//
22
// FILE: Cozir.cpp
33
// AUTHOR: DirtGambit & Rob Tillaart
4-
// VERSION: 0.3.4
4+
// VERSION: 0.3.5
55
// PURPOSE: library for COZIR range of sensors for Arduino
6-
// Polling Mode
6+
// Polling Mode + stream parser
77
// URL: https://github.com/RobTillaart/Cozir
88
// http://forum.arduino.cc/index.php?topic=91467.0
99
//
@@ -369,16 +369,22 @@ uint32_t COZIR::_request(const char* str)
369369
if (_ser->available())
370370
{
371371
char c = _ser->read();
372+
if (c == '\n') break;
372373
_buffer[idx++] = c;
373374
_buffer[idx] = '\0';
374-
if (c == '\n') break;
375375
}
376376
}
377377
// Serial.print("buffer: ");
378378
// Serial.println(_buffer);
379-
uint32_t rv = atol(&_buffer[2]);
380-
if (idx > 2) return rv;
381-
return 0;
379+
uint32_t rv = 0;
380+
// default for PPM is different.
381+
if (str[0] == '.') rv = 1;
382+
// do we got the requested field?
383+
if (strchr(_buffer, str[0]) && (idx > 2))
384+
{
385+
rv = atol(&_buffer[2]);
386+
}
387+
return rv;
382388
}
383389

384390

@@ -451,25 +457,72 @@ void C0ZIRParser::init()
451457

452458
uint8_t C0ZIRParser::nextChar(char c)
453459
{
460+
static bool skipLine = false;
454461
uint8_t rv = 0;
462+
463+
// SKIP * and Y until next return.
464+
// as output of these two commands not handled by this parser
465+
if ((c == '*') || (c == 'Y') || (c == '@')) skipLine = true;
466+
if (c == '\n') skipLine = false;
467+
if (skipLine) return 0;
468+
469+
// TODO investigate
470+
// if the last char is more than 2..5 ms ago (9600 baud ~ 1 char/ms)
471+
// it probably needs to sync with the stream again.
472+
// but it depends on how calling process behaves.
473+
// - need for uint32_t _lastChar time stamp?
474+
455475
switch(c)
456476
{
457477
case '0' ... '9':
458478
_value *= 10;
459479
_value += (c - '0');
460480
break;
481+
// major responses to catch
482+
case 'z':
483+
case 'Z':
461484
case 'L':
462485
case 'T':
463486
case 'H':
464-
case 'z':
465-
case 'Z':
487+
// all other known responses, starting a new field
488+
case 'X':
489+
case '.':
490+
case '@': // skipped
491+
case 'Y': // skipped
492+
case '*': // skipped
493+
case 'Q':
494+
case 'F':
495+
case 'G':
496+
case 'M':
497+
case 'K': // mode
466498
case 'A':
499+
case 'a':
467500
case 'P':
501+
case 'p':
502+
case 'S':
503+
case 's':
504+
case 'U':
505+
case 'u':
506+
// new line triggers store() to have results available faster.
507+
// saves ~500 millis() for the last FIELD
508+
case '\n':
468509
rv = store();
469510
_field = c;
470511
_value = 0;
471512
break;
472-
default:
513+
514+
// drop fields of Y, and * command.
515+
// reset parsing on separators of Y and * commands
516+
case ':':
517+
case ',':
518+
_field = 0;
519+
_value = 0;
520+
break;
521+
522+
case ' ': // known separator
523+
case '\r': // known return
524+
break;
525+
default: // catch all unknown characters, including glitches.
473526
break;
474527
}
475528
return rv;

libraries/Cozir/cozir.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#pragma once
22
//
33
// FILE: Cozir.h
4-
// VERSION: 0.3.4
4+
// VERSION: 0.3.5
55
// PURPOSE: library for COZIR range of sensors for Arduino
6-
// Polling Mode
6+
// Polling Mode + stream parser
77
// URL: https://github.com/RobTillaart/Cozir
88
// http://forum.arduino.cc/index.php?topic=91467.0
99
//
@@ -14,7 +14,7 @@
1414
#include "Arduino.h"
1515

1616

17-
#define COZIR_LIB_VERSION (F("0.3.4"))
17+
#define COZIR_LIB_VERSION (F("0.3.5"))
1818

1919

2020
// OUTPUT FIELDS
@@ -180,7 +180,11 @@ class C0ZIRParser
180180
public:
181181
C0ZIRParser();
182182

183+
// init resets all internal values
183184
void init();
185+
// resetParser only resets current FIELD (last values are kept).
186+
void resetParser() { _field = 0; };
187+
184188

185189
// returns field char if a field is completed, 0 otherwise.
186190
uint8_t nextChar(char c);
@@ -232,10 +236,10 @@ class C0ZIRParser
232236

233237

234238
// parsing helpers
235-
uint32_t _value;
236-
uint8_t _field;
239+
uint32_t _value; // to build up the numeric value
240+
uint8_t _field; // last read FIELD
237241

238-
// returns field char if a field is completed, 0 otherwise.
242+
// returns FIELD char if a FIELD is completed, 0 otherwise.
239243
uint8_t store();
240244
};
241245

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)