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

Some minor changes, CO2humi added for other sensor #34

Merged
merged 12 commits into from
Dec 30, 2020
71 changes: 71 additions & 0 deletions examples/co2_mhz19/co2_mhz19.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* @file main.cpp
* @author Antonio Vanegas @hpsaturn
* @date June 2018 - 2020
* @brief Particle meter sensor tests
* @license GPL3
*
* Full documentation:
* https://github.com/kike-canaries/canairio_sensorlib#canairio-air-quality-sensors-library
*
* Full implementation for WiFi and Bluetooth Air Quality fixed and mobile station:
* https://github.com/kike-canaries/canairio_firmware#canairio-firmware
*
* CanAirIO project:
* https://canair.io
*/

#include <Arduino.h>
#include <Sensors.hpp>

void onSensorDataOk() {
Serial.print ("-->[MAIN] PM1: "+sensors.getStringPM1());
Serial.print (" PM2.5: " + sensors.getStringPM25());
Serial.print (" PM10: " + sensors.getStringPM10());

Serial.print (" CO2: " + sensors.getStringCO2());
Serial.print (" CO2humi: " + String(sensors.getCO2humi()));
Serial.print (" CO2temp: " + String(sensors.getCO2temp()));

Serial.print (" H: "+ String(sensors.getHumidity()));
Serial.println (" T: " + String(sensors.getTemperature()));

}

void onSensorDataError(const char * msg){
Serial.println(msg);
}

/******************************************************************************
* M A I N
******************************************************************************/

void setup() {
Serial.begin(115200);
delay(200);
Serial.println("\n== Sensor test setup ==\n");

Serial.println("-->[SETUP] Detecting sensors..");

sensors.setSampleTime(5); // config sensors sample time interval
sensors.setOnDataCallBack(&onSensorDataOk); // all data read callback
sensors.setOnErrorCallBack(&onSensorDataError); // [optional] error callback
sensors.setDebugMode(true); // [optional] debug mode

// sensors.init(); // Auto detection of PM sensors (Honeywell, Plantower, Panasonic)
// sensors.init(sensors.Auto); // Auto detection of PM sensors (Honeywell, Plantower, Panasonic)
// sensors.init(sensors.Panasonic); // Force detection to Panasonic sensor
// sensors.init(sensors.Sensirion); // Force detection to Sensirion sensor
// sensors.init(sensors.Auto,mRX,mTX); // Auto detection and custom RX, TX pines
// sensors.init(sensors.Auto,PMS_RX,PMS_TX); // Auto detection, custom RX,TX and custom DHT config
sensors.init(sensors.Mhz19);

if(sensors.isPmSensorConfigured())
Serial.println("-->[SETUP] Sensor configured: " + sensors.getPmDeviceSelected());

delay(500);
}

void loop() {
sensors.loop(); // read sensor data and showed it
}
34 changes: 34 additions & 0 deletions examples/co2_mhz19/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[platformio]
src_dir = .

[common_env_data]
framework = arduino
upload_speed = 1500000
monitor_speed = 115200
lib_deps =
hpsaturn/CanAirIO Air Quality Sensors Library

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = ${common_env_data.framework}
upload_speed = ${common_env_data.upload_speed}
monitor_speed = ${common_env_data.monitor_speed}
lib_deps = ${common_env_data.lib_deps}

[env:esp8266]
platform = espressif8266
board = esp12e
framework = ${common_env_data.framework}
monitor_speed = ${common_env_data.monitor_speed}
lib_deps = ${common_env_data.lib_deps}
6 changes: 3 additions & 3 deletions examples/platformio/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ void onSensorDataOk() {
Serial.print ("-->[MAIN] PM1.0: "+sensors.getStringPM1());
Serial.print (" PM2.5: " + sensors.getStringPM25());
Serial.print (" PM10: " + sensors.getStringPM10());
Serial.print (" PM1: " + sensors.getStringPM1());
Serial.print (" T: " + String(sensors.getTemperature()));
Serial.println(" H: "+ String(sensors.getHumidity()));
Serial.print (" H: "+ String(sensors.getHumidity()));
Serial.println (" T: " + String(sensors.getTemperature()));

}

void onSensorDataError(const char * msg){
Expand Down
24 changes: 21 additions & 3 deletions src/Sensors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,24 @@ String Sensors::getStringPM10() {
return String(output);
}

uint16_t Sensors::getCO2() {
return CO2;
}

String Sensors::getStringCO2() {
char output[5];
sprintf(output, "%04d", getCO2());
return String(output);
}

float Sensors::getCO2humi() {
return CO2humi;
}

float Sensors::getCO2temp() {
return CO2temp;
}

float Sensors::getHumidity() {
return humi;
}
Expand Down Expand Up @@ -273,7 +291,7 @@ bool Sensors:: pmMhz19Read() {
CO2 = myMHZ19.getCO2(); // Request CO2 (as ppm)
CO2temp = myMHZ19.getTemperature(); // Request Temperature (as Celsius)
if(CO2>0){
DEBUG("-->[AM2320] read > done!");
DEBUG("-->[MHZ14-9] read > done!");
return true;
}
return false;
Expand Down Expand Up @@ -591,8 +609,8 @@ void Sensors::dhtInit() {

/// Print some sensors values
void Sensors::printValues() {
char output[100];
sprintf(output, "PM1:%03d PM25:%03d PM10:%03d H:%03f%% T:%03f°C", pm1, pm25, pm10, humi, temp);
char output[200];
sprintf(output, "PM1:%03d PM25:%03d PM10:%03d CO2:%04d CO2humi:%03f%% CO2temp:%03f°C H:%03f%% T:%03f°C", pm1, pm25, pm10, CO2, CO2humi, CO2temp, humi, temp);
DEBUG("-->[SENSORS]", output);
}

Expand Down
13 changes: 10 additions & 3 deletions src/Sensors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ class Sensors {
uint16_t getPM25();
uint16_t getPM4();
uint16_t getPM10();

uint16_t getCO2();

float getCO2humi();
float getCO2temp();

float getTemperature();
float getHumidity();
float getPressure();
Expand All @@ -110,6 +114,8 @@ class Sensors {
String getStringPM25();
String getStringPM4();
String getStringPM10();
String getStringCO2();
String getStringCO2temp();

private:

Expand Down Expand Up @@ -139,8 +145,9 @@ class Sensors {
float alt = 0.0;
float gas = 0.0;

int CO2;
float CO2temp;
uint16_t CO2; // CO2 in ppm
float CO2humi = 0.0; // temperature of the CO2 sensor
float CO2temp = 0.0; // temperature of the CO2 sensor

void restart();
void am2320Init();
Expand Down