Skip to content

Commit

Permalink
update readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart committed Nov 14, 2023
1 parent e67c95c commit eccba08
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 35 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
45 changes: 28 additions & 17 deletions MTP40C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -15,9 +15,9 @@



MTP40::MTP40(Stream * str)
MTP40::MTP40(Stream * stream)
{
_ser = str;
_ser = stream;
_buffer[0] = '\0';
_type = 0xFF;
}
Expand Down Expand Up @@ -134,31 +134,41 @@ 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;
}


bool MTP40::setSinglePointCorrection(float spc)
{
if ((spc < 400) || (spc > 5000)) return false;
if ((spc < 400) || (spc > 5000))
{
return false;
}

union
{
Expand Down Expand Up @@ -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;
}


Expand All @@ -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;
}


Expand All @@ -260,7 +271,7 @@ int MTP40::lastError()

//////////////////////////////////////////////////////////////////////
//
// PRIVATE
// PROTECTED
//
bool MTP40::request(uint8_t *data, uint8_t commandLength, uint8_t answerLength)
{
Expand Down Expand Up @@ -438,11 +449,11 @@ const uint8_t auchCRCLo[] = {

#endif


/////////////////////////////////////////////////////////////
//
// DERIVED CLASSES
//

MTP40C::MTP40C(Stream * str) : MTP40(str)
{
_type = 2;
Expand All @@ -455,5 +466,5 @@ MTP40D::MTP40D(Stream * str) : MTP40(str)
};


// -- END OF FILE --
// -- END OF FILE --

20 changes: 9 additions & 11 deletions MTP40C.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand All @@ -53,7 +51,7 @@ class MTP40

bool openSelfCalibration();
bool closeSelfCalibration();
uint8_t getSelfCalibrationStatus();
uint16_t getSelfCalibrationStatus();
bool setSelfCalibrationHours(uint16_t hours);
uint16_t getSelfCalibrationHours();

Expand Down Expand Up @@ -108,7 +106,7 @@ class MTP40

/////////////////////////////////////////////////////////////
//
// DERIVED CLASSES
// DERIVED CLASSES
//
class MTP40C : public MTP40
{
Expand All @@ -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 --

20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -237,14 +240,14 @@ moments. Valid values are 24 - 720 .

#### Must

- documentation

#### Should

- CRC verify responses from sensor
- improve readability code (e.g. parameter names)
- move code from .h to .cpp file


#### Could

- performance measurements
Expand All @@ -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,

4 changes: 2 additions & 2 deletions library.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit eccba08

Please sign in to comment.