Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct issue #16 #17

Merged
merged 3 commits into from
Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,18 @@ The available status/error codes and pre-defined error messages are:
For easy of use, the error message are pre-defined with `#define`.
See the [examples](examples/) for error handling implementation.

## Temperature and humidity offset correction (Optional)

Some sensors have a small deviation with temperature and humidity readings.
The compensate is possible with a correction offset defined by set_temp_offset() and set_rhum_offset().
The result will be reading + offset. Default offset values are O.

Example:
```c++
set_temp_offset(-0.6);
set_rhum_offset(2);
```

## Contribute

If you have read this far, this is the library for your project
Expand Down
8 changes: 4 additions & 4 deletions src/PMserial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,15 @@ void SerialPM::decodeBuffer(bool tsi_mode, bool truncated_num)
hcho = buff2word(28) * 1e-3;
break;
case PMS5003T:
temp = int8_t(n5p0) * 1e-1; // cast to signed integer
rhum = n10p0 * 1e-1;
temp = int16_t(n5p0) * 1e-1 + temp_offset; // cast to signed integer 16bits
rhum = n10p0 * 1e-1 + rhum_offset;
n5p0 = 0;
n10p0 = 0;
break;
case PMS5003ST:
hcho = buff2word(28) * 1e-3;
temp = int8_t(buff2word(30)) * 1e-1; // cast to signed integer
rhum = buff2word(32) * 1e-1;
temp = int16_t(buff2word(30)) * 1e-1 + temp_offset; // cast to signed integer 16bits
rhum = buff2word(32) * 1e-1 + rhum_offset;
break;
default:
break;
Expand Down
11 changes: 11 additions & 0 deletions src/PMserial.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ class SerialPM
inline bool has_number_concentration() { return (status == OK) && (pms != PMS3003); }
inline bool has_temperature_humidity() { return (status == OK) && ((pms == PMS5003T) || (pms == PMS5003ST)); }
inline bool has_formaldehyde() { return (status == OK) && ((pms == PMS5003S) || (pms == PMS5003ST)); }

// adding offsets works well in normal range
// might introduce under- or overflow at the ends of the sensor range
inline void set_rhum_offset(float offset) { rhum_offset = offset; };
inline void set_temp_offset(float offset) { temp_offset = offset; };
inline float get_rhum_offset() { return rhum_offset; };
inline float get_temp_offset() { return temp_offset; };
#ifdef PMS_DEBUG
#ifdef HAS_HW_SERIAL
inline void print_buffer(Stream &term, const char *fmt)
Expand All @@ -154,6 +161,10 @@ class SerialPM
uint8_t rx, tx; // Serial1 pins on ESP32
#endif

// Correct Temperature & Humidity
float temp_offset = 0.0;
float rhum_offset = 0.0;

// utility functions
STATUS trigRead();
bool checkBuffer(size_t bufferLen);
Expand Down