0.1.3 MHZCO2

This commit is contained in:
Rob Tillaart 2023-07-27 16:14:19 +02:00
parent 9b8c1190e0
commit acbf8e5b73
13 changed files with 84 additions and 56 deletions

View File

@ -6,13 +6,18 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.1.3] - 2023-07-27
- remove MTP40F as it is not compatible
- update examples.
- minor edits.
## [0.1.2] - 2023-01-18
- fix build - SoftwareSerial problem
- fix version in .cpp
- fix date in changelog
- minor edit in readme.md
## [0.1.1] - 2023-01-06
- rename to MHZCO2
- create derived classes
@ -21,7 +26,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- improve documentation
- refactor, rewrite, optimize
## [0.1.x] - 2020-09-01
- add PWM and analog examples for MHZ19B

View File

@ -1,7 +1,7 @@
//
// FILE: MHZCO2.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.2
// VERSION: 0.1.3
// PURPOSE: Arduino Library for MHZ series CO2 sensors
// DATE: 2020-05-05
// URL: https://github.com/RobTillaart/MHZCO2
@ -19,6 +19,12 @@ MHZCO2::MHZCO2()
void MHZCO2::begin(Stream * str)
{
_str = str;
_lastMeasurement = 0;
_PPM = 0;
_CO2 = 0;
_temperature = 0;
_accuracy = 0;
_minCO2 = 0;
}
@ -202,9 +208,6 @@ MHZ19E::MHZ19E() : MHZCO2()
{
}
MTP40F::MTP40F() : MHZCO2()
{
}
// -- END OF FILE --

View File

@ -2,7 +2,7 @@
//
// FILE: MHZCO2.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.2
// VERSION: 0.1.3
// PURPOSE: Arduino Library for MHZ series CO2 sensors
// DATE: 2020-05-05
// URL: https://github.com/RobTillaart/MHZCO2
@ -10,7 +10,7 @@
#include "Arduino.h"
#define MHZCO2_LIB_VERSION (F("0.1.2"))
#define MHZCO2_LIB_VERSION (F("0.1.3"))
#define MHZCO2_OK 0
#define MHZCO2_TIMEOUT -10
@ -102,11 +102,6 @@ public:
MHZ19E();
};
class MTP40F : public MHZCO2
{
public:
MTP40F();
};
// -- END OF FILE --

View File

@ -13,13 +13,14 @@ Arduino Library for MHZ series CO2 sensors.
## Description
The MHZCO2 is an experimental library for the MHZ19B CO2 sensor with a Serial (RS232-TTL) interface and compatibles.
The MHZCO2 is an experimental library for the MHZ19B CO2 sensor
with a Serial (RS232-TTL) interface and compatibles.
The library offers a base class and derived classes to prepare for specific functionality.
The base class is based upon the MHZ19B specification. This might change in the future as compatibles might differ on detail.
Reference: user manual MHZ129B 2019-04-25 version 1.4
The base class is based upon the MHZ19B specification.
This might change in the future as compatibles might differ on detail.
Reference: user manual MHZ129B 2019-04-25 version 1.4
#### Compatibles
@ -33,17 +34,24 @@ This list is not verified although these devices should be compatible based upon
| MHZ19C | 50ppm + 5% |
| MHZ19D | 50ppm + 5% |
| MHZ19E | 50ppm + 5% |
| MTP40F | |
Note: The calibration of the MHZ1311A is different than MHZ19x series
If there are compatible devices missing in this list, please let me know.
In previous versions the MTP40F was incorrectly mentioned as compatible.
#### Links
- https://emariete.com/en/sensor-co2-mh-z19b/
- https://emariete.com/en/sensor-co2-low-consumption-mh-z1311a-winsen/
- https://revspace.nl/MHZ19
- https://www.co2.earth/ - current outdoor CO2 level can be used for calibrating.
- https://keelingcurve.ucsd.edu/ - historical outdoor CO2 level.
- https://github.com/RobTillaart/MTP40C
- https://github.com/RobTillaart/MTP40F
- https://github.com/RobTillaart/Cozir
## Connection
@ -56,22 +64,22 @@ If there are compatible devices missing in this list, please let me know.
#### Constructor
- **MHZCO2()** base class constructor.
- **MHZ19()** constructor. Also 19B,C,D,E
- **MTP40F()** constructor.
- **void begin(Stream \* str)** set the Serial port to use, e.g Serial1.
- **MHZ19()** constructor. Also 19B, C, D, E
- **void begin(Stream \* str)** set the Serial port to use, e.g Serial1,
or a softwareSerial port.
- **uint32_t uptime()** returns milliseconds since 'instantiation'.
#### Range
- **void setPPM(uint16_t PPM)** PPM = 2000, 5000, 10000
- **uint16_t getPPM()** returns (cached) PPM value
- **void setPPM(uint16_t PPM)** PPM = 2000, 5000, 10000.
- **uint16_t getPPM()** returns (cached) PPM value.
#### Measure
- **int measure()** workhorse, send command to read the sensor.
- **uint32_t lastMeasurement()** timestamp in millis of last measurement
- **uint32_t lastMeasurement()** timestamp in milliseconds of last measurement.
- **int getCO2()** returns CO2 PPM last measurement.
- **int getTemperature()** returns temperature last measurement.
- **int getAccuracy()** returns accuracy last measurement.
@ -83,10 +91,18 @@ The latter two might not be supported by all MH sensors.
**WARNING:** use with care, read the datasheet as these commands may disrupt your sensor.
- **void calibrateZero()** Only use when sensor is at least 30 minutes in **400** PPM environment.
- **void calibrateSpan(uint16_t span)** Only use when sensor is at least 30 minutes in **2000** PPM environment.
- **void calibrateZero()** Only use when sensor is at least 30 minutes
in a calibrated **400** PPM environment.
- **void calibrateSpan(uint16_t span)** Only use when sensor is at least 30 minutes
in a calibrated **2000** PPM environment.
- **void calibrateAuto(bool mode = true)**
Note the outdoor calibration CO2 level differs per day and one should check
a local airport or weather station for a good reference.
The University of San Diego keeps track of CO2 for a long time now.
See - https://keelingcurve.ucsd.edu/
## Future
@ -110,6 +126,7 @@ The latter two might not be supported by all MH sensors.
- extend unit tests
- add type info for derived classes?
- A .. E ?
- save RAM? possible?

View File

@ -1,7 +1,6 @@
//
// FILE: MHZCO2_PWM.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: demo MHZ library / sensor
// DATE: 2020-09-01
@ -14,6 +13,8 @@
#include "Arduino.h"
#include "MHZCO2.h"
// adjust to calibrate.
const float MAX_CONCENTRATION = 2000.0;
@ -30,7 +31,7 @@ void IRQ()
}
uint16_t PWM_conc()
uint16_t PWM_concentration()
{
noInterrupts();
uint16_t TimeHigh = width; // milliseconds
@ -45,14 +46,16 @@ void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("MHZCO2_LIB_VERSION: ");
Serial.println(MHZCO2_LIB_VERSION);
attachInterrupt(digitalPinToInterrupt(3), IRQ, CHANGE);
}
void loop()
{
Serial.println(PWM_conc());
Serial.println(PWM_concentration());
delay(1000);
}

View File

@ -1,11 +1,14 @@
//
// FILE: MHZCO2_analog.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: demo MHZ library / sensor
// DATE: 2020-09-01
#include "Arduino.h"
#include "MHZCO2.h"
/*
DATASHEET P.7
Conversion between analog voltage output and concentration,
@ -20,21 +23,23 @@
void setup()
{
Serial.begin(115200);
// Serial.println(__FILE__);
// Serial.println(__FILE__);
// Serial.print("MHZCO2_LIB_VERSION: ");
// Serial.println(MHZCO2_LIB_VERSION);
}
void loop()
{
uint16_t C = concentration(A0, 2000);
uint16_t C = concentration(A0, 2000);
Serial.println(C);
}
uint16_t concentration(int port, uint16_t maxC)
uint16_t concentration(int port, uint16_t maxConcentration)
{
float volt = analogRead(port) * (5.0 / 1023.0);
uint16_t C = (volt - 0.4) * maxC / 1.6;
uint16_t C = (volt - 0.4) * maxConcentration / 1.6;
return C;
}

View File

@ -1,24 +1,26 @@
//
// FILE: MHZCO2_serial1.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: demo for MEGA / 2560 with Serial1
// DATE: 2020-09-01
#include "Arduino.h"
#include "MHZCO2.h"
MHZ19B MHZ19B;
void setup()
{
Serial.begin(115200);
// Serial.println(__FILE__);
Serial.println(__FILE__);
Serial.print("MHZCO2_LIB_VERSION: ");
Serial.println(MHZCO2_LIB_VERSION);
MHZ19B.begin(&Serial1);
Serial1.begin(9600);
}

View File

@ -16,16 +16,16 @@ packages:
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
# - due // has no SoftwareSerial
# - zero // has no SoftwareSerial
- leonardo
# - m4 // has no SoftwareSerial
# - esp32 // has no SoftwareSerial
- esp8266
- mega2560
- rpipico
# - uno
# - due
# - zero
# - leonardo
# - m4
# - esp32
# - esp8266
# - mega2560
# - rpipico
# external libraries
libraries:
# - "SoftwareSerial" does not work as it is build in.
# - "SoftwareSerial" does not work

View File

@ -1,12 +1,12 @@
//
// FILE: MHZCO2_sw_serial.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: demo
// DATE: 2020-09-01
#include "SoftwareSerial.h"
#include "Arduino.h"
#include "MHZCO2.h"
@ -22,6 +22,8 @@ void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("MHZCO2_LIB_VERSION: ");
Serial.println(MHZCO2_LIB_VERSION);
MHZ19B.begin(&ss);
ss.begin(9600);

View File

@ -7,7 +7,6 @@ MHZ19 KEYWORD1
MHZ19B KEYWORD1
MHZ19C KEYWORD1
MHZ19D KEYWORD1
MTP40F KEYWORD1
# Methods and Functions (KEYWORD2)

View File

@ -1,6 +1,6 @@
{
"name": "MHZCO2",
"keywords": "MHZ1311A,MHZ19,MHZ19B,MHZ19C,MHZ19D,MHZ19E,MTP40F",
"keywords": "MHZ1311A,MHZ19,MHZ19B,MHZ19C,MHZ19D,MHZ19E",
"description": "Arduino Library for MHZ series CO2 sensors.",
"authors":
[
@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/MHZCO2.git"
},
"version": "0.1.2",
"version": "0.1.3",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,9 +1,9 @@
name=MHZCO2
version=0.1.2
version=0.1.3
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino Library for MHZ series CO2 sensors.
paragraph=MHZ1311A,MHZ19,MHZ19B,MHZ19C,MHZ19D,MHZ19E,MTP40F
paragraph=MHZ1311A,MHZ19,MHZ19B,MHZ19C,MHZ19D,MHZ19E
category=Sensors
url=https://github.com/RobTillaart/MHZCO2
architectures=*

View File

@ -48,11 +48,9 @@ unittest(test_constructor)
{
MHZCO2 A;
MHZ19B B;
MTP40F C;
assertEqual( 0, A.uptime());
assertEqual( 0, B.uptime());
assertEqual( 0, C.uptime());
}