0.2.2 MTP40C

This commit is contained in:
rob tillaart 2022-11-18 14:05:26 +01:00
parent 31ec3d648f
commit 4bcd11b45d
8 changed files with 83 additions and 41 deletions

View File

@ -1,11 +1,27 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:
packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
compile: compile:
# Choosing to run compilation tests on 2 different Arduino platforms # Choosing to run compilation tests on 2 different Arduino platforms
platforms: platforms:
- uno - uno
- due # - due
- zero # - zero
- leonardo # - leonardo
- m4 - m4
- esp32 - esp32
# - esp8266 # - esp8266
# - mega2560 # - mega2560
- rpipico

View File

@ -0,0 +1,32 @@
# Change Log MTP40C
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.2.2] - 2022-11-17
- add RP2040 in build-CI
- add changelog.md
## [0.2.1] - 2021-12-22
- update library.json
- update license
- minor edits
## [0.2.0] - 2021-08-27
- add MTP40D derived class
- many fixes after testing
----
## [0.1.1] - 2021-08-23
- addexamples
- minor fixes
## [0.1.0] - 2021-08-20
- initial version.

View File

@ -1,23 +1,17 @@
// //
// FILE: MTP40C.h // FILE: MTP40C.cpp
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// DATE: 2021-08-20 // DATE: 2021-08-20
// VERSION: 0.2.1 // VERSION: 0.2.2
// PURPOSE: Arduino library for MTP40C MTP40D CO2 sensor // PURPOSE: Arduino library for MTP40C MTP40D CO2 sensor
// URL: https://github.com/RobTillaart/MTP40C // URL: https://github.com/RobTillaart/MTP40C
//
// HISTORY:
// 0.1.0 2021-08-20 initial version
// 0.1.1 2021-08-23 added examples, minor fixes
// 0.2.0 2021-08-27 added MTP40D derived class
// + many fixes after testing
// 0.2.1 2021-12-22 update library.json, license, minor edits
#include "MTP40C.h" #include "MTP40C.h"
// debug flag, development. // debug flag, development.
// #define MTP40_DEBUG 1 // #define MTP40_DEBUG 1
@ -90,7 +84,7 @@ float MTP40::getAirPressureReference()
_lastError = MTP40_OK; _lastError = MTP40_OK;
// max read freq 1x per 4 seconds // max read freq 1x per 4 seconds
if (millis() - _lastRead < 4000) return _airPressureReference; // last value if (millis() - _lastRead < 4000) return _airPressureReference; // last value
_lastRead = millis(); _lastRead = millis();
@ -137,7 +131,6 @@ bool MTP40::setAirPressureReference(float apr)
uint16_t MTP40::getGasConcentration() uint16_t MTP40::getGasConcentration()
{ {
_lastError = MTP40_OK; _lastError = MTP40_OK;
// max read freq 1x per 4 seconds // max read freq 1x per 4 seconds
@ -266,20 +259,20 @@ int MTP40::lastError()
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// //
// PRIVATE // PRIVATE
// //
bool MTP40::request(uint8_t *data, uint8_t commandLength, uint8_t answerLength) bool MTP40::request(uint8_t *data, uint8_t commandLength, uint8_t answerLength)
{ {
// generic or specific address // generic or specific address
if (_useAddress) if (_useAddress)
{ {
data[0] = _address; data[0] = _address;
} }
else else
{ {
data[0] = 0xFE; // broadcast data[0] = 0xFE; // broadcast
} }
// calculate CRC of command // calculate CRC of command
uint16_t crc = CRC(data, commandLength - 2); uint16_t crc = CRC(data, commandLength - 2);
data[commandLength - 1] = crc / 256; data[commandLength - 1] = crc / 256;
data[commandLength - 2] = crc & 0xFF; data[commandLength - 2] = crc & 0xFF;
@ -292,7 +285,7 @@ bool MTP40::request(uint8_t *data, uint8_t commandLength, uint8_t answerLength)
#else #else
_ser->write(*data++); _ser->write(*data++);
#endif #endif
yield(); // because baud rate is low! yield(); // because baud rate is low!
} }
uint32_t start = millis(); uint32_t start = millis();
@ -306,7 +299,7 @@ bool MTP40::request(uint8_t *data, uint8_t commandLength, uint8_t answerLength)
i++; i++;
answerLength--; answerLength--;
} }
yield(); // because baud rate is low! yield(); // because baud rate is low!
} }
return true; return true;
} }
@ -363,9 +356,9 @@ const uint8_t auchCRCLo[] = {
uint16_t uIndex; // Query the CRC table index uint16_t uIndex; // Query the CRC table index
uint16_t crc; uint16_t crc;
while (len--) /* Complete the entire message buffer*/ while (len--) /* Complete the entire message buffer*/
{ {
uIndex = uchCRCLo ^ *data++; /* Calculate CRC */; uIndex = uchCRCLo ^ *data++; /* Calculate CRC */;
uchCRCLo = uchCRCHi ^ auchCRCHi[uIndex]; uchCRCLo = uchCRCHi ^ auchCRCHi[uIndex];
uchCRCHi = auchCRCLo[uIndex]; uchCRCHi = auchCRCLo[uIndex];
} }
@ -377,7 +370,7 @@ const uint8_t auchCRCLo[] = {
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
// //
// DERIVED CLASSES // DERIVED CLASSES
// //
MTP40C::MTP40C(Stream * str) : MTP40(str) MTP40C::MTP40C(Stream * str) : MTP40(str)

View File

@ -3,12 +3,11 @@
// FILE: MTP40C.h // FILE: MTP40C.h
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// DATE: 2021-08-20 // DATE: 2021-08-20
// VERSION: 0.2.1 // VERSION: 0.2.2
// PURPOSE: Arduino library for MTP40C + MTP40D CO2 sensor // PURPOSE: Arduino library for MTP40C + MTP40D CO2 sensor
// URL: https://github.com/RobTillaart/MTP40C // URL: https://github.com/RobTillaart/MTP40C
// //
// HISTORY: // HISTORY: see changelog.md
// see MTP40C.cpp file
// //
// Based upon datasheet June 2020, version 2.0 // Based upon datasheet June 2020, version 2.0
// //
@ -17,7 +16,7 @@
#include "Arduino.h" #include "Arduino.h"
#define MTP40_LIB_VERSION (F("0.2.1")) #define MTP40_LIB_VERSION (F("0.2.2"))
#define MTP40_DEFAULT_ADDRESS 0x64 #define MTP40_DEFAULT_ADDRESS 0x64
@ -62,13 +61,14 @@ public:
void setSpecificAddress() { _useAddress = true; }; void setSpecificAddress() { _useAddress = true; };
bool useSpecificAddress() { return _useAddress; }; bool useSpecificAddress() { return _useAddress; };
// set timeout of serial communication. // set timeout of serial communication.
void setTimeout(uint32_t to = 100) { _timeout = to; }; void setTimeout(uint32_t to = 100) { _timeout = to; };
uint32_t getTimeout() { return _timeout; }; uint32_t getTimeout() { return _timeout; };
uint32_t lastRead() { return _lastRead; }; uint32_t lastRead() { return _lastRead; };
// 2 = MTP40C 3 = MTP40D // 2 = MTP40C
// 3 = MTP40D
uint8_t getType() { return _type; }; uint8_t getType() { return _type; };
int lastError(); int lastError();

View File

@ -204,6 +204,11 @@ moments. Valid values are 24 - 720 .
- **uint16_t getSelfCalibrationHours()** returns the value set above. - **uint16_t getSelfCalibrationHours()** returns the value set above.
## Operations
See examples.
## Future ## Future
#### CRC #### CRC
@ -223,11 +228,7 @@ moments. Valid values are 24 - 720 .
- serial bus with multiple devices? => diodes - serial bus with multiple devices? => diodes
- improve readability code (e.g. parameter names) - improve readability code (e.g. parameter names)
- move all code from .h to .cpp file
## Operations
See examples.
## Sponsor ## Sponsor

View File

@ -15,7 +15,7 @@
"type": "git", "type": "git",
"url": "https://github.com/RobTillaart/MTP40C.git" "url": "https://github.com/RobTillaart/MTP40C.git"
}, },
"version": "0.2.1", "version": "0.2.2",
"license": "MIT", "license": "MIT",
"frameworks": "arduino", "frameworks": "arduino",
"platforms": "*", "platforms": "*",

View File

@ -1,5 +1,5 @@
name=MTP40C name=MTP40C
version=0.2.1 version=0.2.2
author=Rob Tillaart <rob.tillaart@gmail.com> author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com> maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for MTP40, MTP40C and MTP40D CO2 sensor sentence=Arduino library for MTP40, MTP40C and MTP40D CO2 sensor

View File

@ -35,10 +35,10 @@
//////////////////////////////////// ////////////////////////////////////
// //
// MANY TESTS WILL BLOCK AS BUILD CI HAS NO GOOD TIMEOUT // MANY TESTS WILL BLOCK AS BUILD CI HAS NO GOOD TIMEOUT
// ALL FAILING TESTS ARE COMMENTED // ALL FAILING TESTS ARE COMMENTED
// //
// USE GODMODE SERIAL TO IMPROVE THESE TESTS // USE GODMODE SERIAL TO IMPROVE THESE TESTS
// //
#include <ArduinoUnitTests.h> #include <ArduinoUnitTests.h>