mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.3.1 MTP40C
This commit is contained in:
parent
596e6d78f8
commit
9bff659775
@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.3.1] - 2023-11-14
|
||||
- update readme.md
|
||||
|
||||
|
||||
## [0.3.0] - 2023-07-30
|
||||
- replace CRC with other algorithm for AVR
|
||||
- less RAM, less code, faster (AVR only)
|
||||
|
@ -2,7 +2,7 @@
|
||||
// FILE: MTP40C.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2021-08-20
|
||||
// VERSION: 0.3.0
|
||||
// VERSION: 0.3.1
|
||||
// PURPOSE: Arduino library for MTP40C MTP40D CO2 sensor
|
||||
// URL: https://github.com/RobTillaart/MTP40C
|
||||
|
||||
@ -15,9 +15,9 @@
|
||||
|
||||
|
||||
|
||||
MTP40::MTP40(Stream * str)
|
||||
MTP40::MTP40(Stream * stream)
|
||||
{
|
||||
_ser = str;
|
||||
_ser = stream;
|
||||
_buffer[0] = '\0';
|
||||
_type = 0xFF;
|
||||
}
|
||||
@ -134,23 +134,30 @@ uint16_t MTP40::getGasConcentration()
|
||||
{
|
||||
_lastError = MTP40_OK;
|
||||
|
||||
// max read freq 1x per 4 seconds
|
||||
if (millis() - _lastRead < 4000) return _gasLevel; // last value
|
||||
// max read freq 1x per 4 seconds
|
||||
if (millis() - _lastRead < 4000)
|
||||
{
|
||||
return _gasLevel; // last value
|
||||
}
|
||||
_lastRead = millis();
|
||||
|
||||
uint8_t cmd[5] = { 0xFE, 0x69, 0x03, 0x7E, 0x61 };
|
||||
if (request(cmd, 5, 14) )
|
||||
{
|
||||
// check valid
|
||||
// check valid
|
||||
for (uint8_t i = 8; i < 12; i++)
|
||||
{
|
||||
if (_buffer[i] != 0) return 0;
|
||||
if (_buffer[i] != 0)
|
||||
{
|
||||
_lastError = MTP40_INVALID_GAS_LEVEL;
|
||||
if (_suppressError) return _gasLevel;
|
||||
return _lastError;
|
||||
}
|
||||
}
|
||||
_gasLevel = _buffer[5] *256 + _buffer[4];
|
||||
_gasLevel = _buffer[5] * 256 + _buffer[4];
|
||||
return _gasLevel;
|
||||
}
|
||||
|
||||
_lastError = MTP40_INVALID_GAS_LEVEL;
|
||||
_lastError = MTP40_REQUEST_FAILED;
|
||||
if (_suppressError) return _gasLevel;
|
||||
return _lastError;
|
||||
}
|
||||
@ -158,7 +165,10 @@ uint16_t MTP40::getGasConcentration()
|
||||
|
||||
bool MTP40::setSinglePointCorrection(float spc)
|
||||
{
|
||||
if ((spc < 400) || (spc > 5000)) return false;
|
||||
if ((spc < 400) || (spc > 5000))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
union
|
||||
{
|
||||
@ -213,14 +223,14 @@ bool MTP40::closeSelfCalibration()
|
||||
}
|
||||
|
||||
|
||||
uint8_t MTP40::getSelfCalibrationStatus()
|
||||
uint16_t MTP40::getSelfCalibrationStatus()
|
||||
{
|
||||
uint8_t cmd[5] = { 0xFE, 0x28, 0x67, 0x4F, 0xDA };
|
||||
if (request(cmd, 5, 6) )
|
||||
{
|
||||
return _buffer[3];
|
||||
}
|
||||
return 0x02;
|
||||
return MTP40_REQUEST_FAILED;
|
||||
}
|
||||
|
||||
|
||||
@ -245,7 +255,8 @@ uint16_t MTP40::getSelfCalibrationHours()
|
||||
{
|
||||
return _buffer[4] * 256 + _buffer[3];
|
||||
}
|
||||
return 0xFFFF; // to indicate error.
|
||||
_lastError = MTP40_REQUEST_FAILED;
|
||||
return _lastError;
|
||||
}
|
||||
|
||||
|
||||
@ -260,7 +271,7 @@ int MTP40::lastError()
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PRIVATE
|
||||
// PROTECTED
|
||||
//
|
||||
bool MTP40::request(uint8_t *data, uint8_t commandLength, uint8_t answerLength)
|
||||
{
|
||||
@ -438,11 +449,11 @@ const uint8_t auchCRCLo[] = {
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DERIVED CLASSES
|
||||
//
|
||||
|
||||
MTP40C::MTP40C(Stream * str) : MTP40(str)
|
||||
{
|
||||
_type = 2;
|
||||
@ -455,5 +466,5 @@ MTP40D::MTP40D(Stream * str) : MTP40(str)
|
||||
};
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -3,20 +3,17 @@
|
||||
// FILE: MTP40C.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2021-08-20
|
||||
// VERSION: 0.3.0
|
||||
// VERSION: 0.3.1
|
||||
// PURPOSE: Arduino library for MTP40C + MTP40D CO2 sensor
|
||||
// URL: https://github.com/RobTillaart/MTP40C
|
||||
//
|
||||
// HISTORY: see changelog.md
|
||||
//
|
||||
// Based upon datasheet June 2020, version 2.0
|
||||
//
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
|
||||
#define MTP40_LIB_VERSION (F("0.3.0"))
|
||||
#define MTP40_LIB_VERSION (F("0.3.1"))
|
||||
|
||||
|
||||
#define MTP40_DEFAULT_ADDRESS 0x64
|
||||
@ -25,12 +22,13 @@
|
||||
#define MTP40_INVALID_AIR_PRESSURE 0x01
|
||||
#define MTP40_INVALID_GAS_LEVEL 0x02
|
||||
#define MTP40_INVALID_ADDRESS 0xFF
|
||||
#define MTP40_REQUEST_FAILED 0xFFFF
|
||||
|
||||
|
||||
class MTP40
|
||||
{
|
||||
public:
|
||||
MTP40(Stream * str);
|
||||
MTP40(Stream * stream);
|
||||
|
||||
bool begin(uint8_t address = MTP40_DEFAULT_ADDRESS);
|
||||
bool isConnected();
|
||||
@ -53,7 +51,7 @@ public:
|
||||
|
||||
bool openSelfCalibration();
|
||||
bool closeSelfCalibration();
|
||||
uint8_t getSelfCalibrationStatus();
|
||||
uint16_t getSelfCalibrationStatus();
|
||||
bool setSelfCalibrationHours(uint16_t hours);
|
||||
uint16_t getSelfCalibrationHours();
|
||||
|
||||
@ -108,7 +106,7 @@ protected:
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DERIVED CLASSES
|
||||
// DERIVED CLASSES
|
||||
//
|
||||
class MTP40C : public MTP40
|
||||
{
|
||||
@ -122,11 +120,11 @@ class MTP40D : public MTP40
|
||||
public:
|
||||
MTP40D(Stream * str);
|
||||
|
||||
// TODO
|
||||
// I2C interface
|
||||
// TODO
|
||||
// I2C interface
|
||||
// PWM interface
|
||||
};
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
|
||||
[![Arduino CI](https://github.com/RobTillaart/MTP40C/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
||||
[![JSON check](https://github.com/RobTillaart/MTP40C/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/MTP40C/actions/workflows/jsoncheck.yml)
|
||||
[![Arduino-lint](https://github.com/RobTillaart/MTP40C/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/MTP40C/actions/workflows/arduino-lint.yml)
|
||||
[![JSON check](https://github.com/RobTillaart/MTP40C/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/MTP40C/actions/workflows/jsoncheck.yml)
|
||||
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/MTP40C.svg)](https://github.com/RobTillaart/MTP40C/issues)
|
||||
|
||||
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/MTP40C/blob/master/LICENSE)
|
||||
[![GitHub release](https://img.shields.io/github/release/RobTillaart/MTP40C.svg?maxAge=3600)](https://github.com/RobTillaart/MTP40C/releases)
|
||||
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/MTP40C.svg)](https://registry.platformio.org/libraries/robtillaart/MTP40C)
|
||||
|
||||
|
||||
# MTP40C / MTP40D
|
||||
@ -90,7 +93,7 @@ Has TTL level RS232, I2C and PWM IO.
|
||||
| 9 | GND | idem |
|
||||
|
||||
|
||||
#### Links
|
||||
#### Related
|
||||
|
||||
- https://www.co2.earth/ - current outdoor CO2 level can be used for calibrating.
|
||||
- https://keelingcurve.ucsd.edu/ - historical outdoor CO2 level.
|
||||
@ -237,6 +240,7 @@ moments. Valid values are 24 - 720 .
|
||||
|
||||
#### Must
|
||||
|
||||
- documentation
|
||||
|
||||
#### Should
|
||||
|
||||
@ -244,7 +248,6 @@ moments. Valid values are 24 - 720 .
|
||||
- improve readability code (e.g. parameter names)
|
||||
- move code from .h to .cpp file
|
||||
|
||||
|
||||
#### Could
|
||||
|
||||
- performance measurements
|
||||
@ -258,10 +261,19 @@ moments. Valid values are 24 - 720 .
|
||||
- multiplexer
|
||||
- investigate commands in PROGMEM?
|
||||
|
||||
|
||||
#### Wont (unless on request)
|
||||
|
||||
|
||||
## Sponsor
|
||||
|
||||
The development of this MTP40C library is sponsored by [TinyTronics, Netherlands](https://www.tinytronics.nl/shop/nl).
|
||||
|
||||
|
||||
## Support
|
||||
|
||||
If you appreciate my libraries, you can support the development and maintenance.
|
||||
Improve the quality of the libraries by providing issues and Pull Requests, or
|
||||
donate through PayPal or GitHub sponsors.
|
||||
|
||||
Thank you,
|
||||
|
||||
|
@ -15,9 +15,9 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/MTP40C.git"
|
||||
},
|
||||
"version": "0.3.0",
|
||||
"version": "0.3.1",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"frameworks": "*",
|
||||
"platforms": "*",
|
||||
"headers": "MTP40C.h"
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=MTP40C
|
||||
version=0.3.0
|
||||
version=0.3.1
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for MTP40, MTP40C and MTP40D CO2 sensor
|
||||
|
Loading…
x
Reference in New Issue
Block a user