MH-Z-CO2-Sensors/MHZ.h
Christoph Schultz 8a063e7c27
Add support for setting the range and autocalibration. Closes #1.
* added possibility to set Range, to enable/disable Autocalibrate and to calibrate maually ( see Datasheet v 1.2 : https://www.winsen-sensor.com/d/files/MH-Z14A.pdf

* Update MHZ.cpp

* Update MHZ.cpp

* Update MHZ.h

added calibrate Span, for complete functionality but commented out , due to professional use (req. constant atmosphere with 2k, 5k or 10k ppm CO2.).
corrected the bugs in MHZ.cpp also.

* Update MHZ.cpp

Added comments for  Sensors with specific firmware.

Co-authored-by: Christoph Schultz <christoph@schultz1-christoph.de>
2021-01-14 22:28:47 +01:00

57 lines
1.2 KiB
C++

/* MHZ library
By Tobias Schürg
*/
#ifndef MHZ_H
#define MHZ_H
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include <SoftwareSerial.h>
// types of sensors.
extern const int MHZ14A;
extern const int MHZ19B;
extern const int MHZ_2K;
extern const int MHZ_5k;
extern const int MHZ_10K;
// status codes
extern const int STATUS_NO_RESPONSE;
extern const int STATUS_CHECKSUM_MISMATCH;
extern const int STATUS_INCOMPLETE;
extern const int STATUS_NOT_READY;
class MHZ {
public:
MHZ(uint8_t rxpin, uint8_t txpin, uint8_t pwmpin, uint8_t type);
MHZ(uint8_t rxpin, uint8_t txpin, uint8_t type);
MHZ(uint8_t pwmpin, uint8_t type);
MHZ(Stream * serial, uint8_t pwmpin, uint8_t type);
MHZ(Stream * serial, uint8_t type);
void setDebug(boolean enable);
boolean isPreHeating();
boolean isReady();
void setAutoCalibrate(boolean b);
void calibrateZero();
void setRange(int range);
// void calibrateSpan(int range); //only for professional use... see implementation and Dataheet.
int readCO2UART();
int readCO2PWM();
int getLastTemperature();
private:
uint8_t _pwmpin, _type, temperature;
boolean debug = false;
Stream * _serial;
byte getCheckSum(byte *packet);
};
#endif