Browse Source

Add PMSX003Sensor.h

fastled
Oscar Rovira 6 years ago
parent
commit
6a58a8a907
4 changed files with 105 additions and 5 deletions
  1. +0
    -4
      code/espurna/config/hardware.h
  2. +13
    -1
      code/espurna/config/sensors.h
  3. +91
    -0
      code/espurna/sensors/PMSX003Sensor.h
  4. +1
    -0
      code/platformio.ini

+ 0
- 4
code/espurna/config/hardware.h View File

@ -43,10 +43,6 @@
#define LED1_PIN 2
#define LED1_PIN_INVERSE 1
#define PMSX003_SUPPORT true
#define PMS_RX_PIN 13
#define PMS_TX_PIN 15
#elif defined(WEMOS_D1_MINI_RELAYSHIELD)
// Info


+ 13
- 1
code/espurna/config/sensors.h View File

@ -186,7 +186,7 @@
//--------------------------------------------------------------------------------
#ifndef EMON_ADS1115_SUPPORT
#define EMON_ADS1115_SUPPORT 1 // Do not build support by default
#define EMON_ADS1115_SUPPORT 0 // Do not build support by default
#endif
#define EMON_ADS1115_PORT_MASK 0x08 // A0=1 A1=2 A2=4 A4=8
@ -197,6 +197,18 @@
#define EMON_ADS1115_GAIN ADS1115_PGA_4P096
#define EMON_ADS1115_REFERENCE_VOLTAGE 8.192 // Double the gain for peak-to-peak
//--------------------------------------------------------------------------------
// Particle Monitor based on Plantower PMSX003
// Enable support by passing PMSX003_SUPPORT=1 build flag
//--------------------------------------------------------------------------------
#ifndef PMSX003_SUPPORT
#define PMSX003_SUPPORT 1
#endif
#define PMS_RX_PIN 13
#define PMS_TX_PIN 15
//--------------------------------------------------------------------------------
// Internal power montior
// Enable support by passing ADC_VCC_ENABLED=1 build flag


+ 91
- 0
code/espurna/sensors/PMSX003Sensor.h View File

@ -0,0 +1,91 @@
// -----------------------------------------------------------------------------
// PMSX003 Dust sensor
// -----------------------------------------------------------------------------
#pragma once
#include "Arduino.h"
#include "BaseSensor.h"
#include <PMS.h>
#include <SoftwareSerial.h>
class PMSX003Sensor : public BaseSensor {
public:
PMSX003Sensor(int pin_rx = PMS_RX_PIN, int pin_tx = PMS_TX_PIN): BaseSensor() {
_pmsSerial = new SoftwareSerial(pin_rx, pin_tx, false, 256);
_pmsSerial->begin(9600);
_pms = new PMS(* _pmsSerial);
// _pmsSerial.begin(9600);
_pin_rx = pin_rx;
_pin_tx = pin_tx;
_count = 3;
}
// Descriptive name of the sensor
String name() {
char buffer[36];
snprintf(buffer, sizeof(buffer), "PMSX003 @ SwSerial RX: %i TX: %i", _pin_rx, _pin_tx);
return String(buffer);
}
// Descriptive name of the slot # index
String slot(unsigned char index) {
if (index < _count) {
_error = SENSOR_ERROR_OK;
if (index == 0) return String("PM 1.0");
if (index == 1) return String("PM 2.5");
if (index == 2) return String("PM 10");
}
_error = SENSOR_ERROR_OUT_OF_RANGE;
return String();
}
// Type for slot # index
magnitude_t type(unsigned char index) {
if (index < _count) {
_error = SENSOR_ERROR_OK;
if (index == 0) return MAGNITUDE_PM1dot0;
if (index == 1) return MAGNITUDE_PM2dot5;
if (index == 2) return MAGNITUDE_PM10;
}
_error = SENSOR_ERROR_OUT_OF_RANGE;
return MAGNITUDE_NONE;
}
// Current value for slot # index
double value(unsigned char index) {
if (index < _count) {
_error = SENSOR_ERROR_OK;
if(index == 0) return _pm1dot0;
if(index == 1) return _pm2dot5;
if(index == 2) return _pm10;
}
_error = SENSOR_ERROR_OUT_OF_RANGE;
return 0;
}
void tick() {
if(_pms->read(_data, 1000)) {
// if (_pms.read(_data)) {
_pm1dot0 = _data.PM_AE_UG_1_0;
_pm2dot5 = _data.PM_AE_UG_2_5;
_pm10 = _data.PM_AE_UG_10_0;
}
}
protected:
unsigned int _pm1dot0;
unsigned int _pm2dot5;
unsigned int _pm10;
unsigned int _pin_rx;
unsigned int _pin_tx;
SoftwareSerial * _pmsSerial;
PMS * _pms;
// SoftwareSerial _pmsSerial;
// PMS _pms;
PMS::DATA _data;
};

+ 1
- 0
code/platformio.ini View File

@ -23,6 +23,7 @@ lib_deps =
Brzo I2C
I2Cdevlib-ADS1115
EspSoftwareSerial
PMS Library
https://bitbucket.org/xoseperez/justwifi.git#1.1.4
https://bitbucket.org/xoseperez/hlw8012.git#1.1.0
https://bitbucket.org/xoseperez/fauxmoesp.git#2.3.0


Loading…
Cancel
Save