sds011: change device driver library (initial)
This commit is contained in:
parent
45f531ccfb
commit
eeed8b7bfe
@ -1,11 +1,13 @@
|
|||||||
#ifndef _SDS011READ_H
|
#ifndef _SDS011READ_H
|
||||||
#define _SDS011READ_H
|
#define _SDS011READ_H
|
||||||
|
|
||||||
#include <SDS011.h>
|
#include <SdsDustSensor.h>
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
|
||||||
#define SDCARD_FILE_HEADER_SDS011 ", PM10,PM25"
|
#define SDCARD_FILE_HEADER_SDS011 ", PM10,PM25"
|
||||||
|
|
||||||
|
extern bool isSDS011Active;
|
||||||
|
|
||||||
bool sds011_init();
|
bool sds011_init();
|
||||||
void sds011_loop();
|
void sds011_loop();
|
||||||
void sds011_sleep(void);
|
void sds011_sleep(void);
|
||||||
|
@ -77,7 +77,7 @@ lib_deps_sensors =
|
|||||||
adafruit/Adafruit BME280 Library @ ^2.2.1
|
adafruit/Adafruit BME280 Library @ ^2.2.1
|
||||||
adafruit/Adafruit BMP085 Library @ ^1.2.0
|
adafruit/Adafruit BMP085 Library @ ^1.2.0
|
||||||
boschsensortec/BSEC Software Library @ 1.6.1480
|
boschsensortec/BSEC Software Library @ 1.6.1480
|
||||||
https://github.com/ricki-z/SDS011.git
|
https://github.com/cyberman54/sds-dust-sensors-arduino-library.git
|
||||||
lib_deps_basic =
|
lib_deps_basic =
|
||||||
https://github.com/dbSuS/libpax.git @ ^1.0.0
|
https://github.com/dbSuS/libpax.git @ ^1.0.0
|
||||||
https://github.com/SukkoPera/Arduino-Rokkit-Hash.git
|
https://github.com/SukkoPera/Arduino-Rokkit-Hash.git
|
||||||
|
@ -9,10 +9,6 @@ static const char TAG[] = __FILE__;
|
|||||||
|
|
||||||
Ticker cyclicTimer;
|
Ticker cyclicTimer;
|
||||||
|
|
||||||
#if (HAS_SDS011)
|
|
||||||
extern boolean isSDS011Active;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void setCyclicIRQ() { xTaskNotify(irqHandlerTask, CYCLIC_IRQ, eSetBits); }
|
void setCyclicIRQ() { xTaskNotify(irqHandlerTask, CYCLIC_IRQ, eSetBits); }
|
||||||
|
|
||||||
// do all housekeeping
|
// do all housekeeping
|
||||||
|
@ -10,35 +10,41 @@ static const char TAG[] = __FILE__;
|
|||||||
#if (HAS_IF482)
|
#if (HAS_IF482)
|
||||||
#error cannot use IF482 together with SDS011 (both use UART#2)
|
#error cannot use IF482 together with SDS011 (both use UART#2)
|
||||||
#endif
|
#endif
|
||||||
// UART(2) is unused in this project
|
|
||||||
static HardwareSerial sdsSerial(2); // so we use it here
|
// sds011 connected to UART(2)
|
||||||
static SDS011 sdsSensor; // fine dust sensor
|
static SdsDustSensor sdsSensor(Serial2);
|
||||||
|
|
||||||
// the results of the sensor:
|
// the results of the sensor:
|
||||||
static float pm10, pm25;
|
static float pm10, pm25;
|
||||||
boolean isSDS011Active;
|
bool isSDS011Active = false;
|
||||||
|
|
||||||
// init
|
// init
|
||||||
bool sds011_init() {
|
bool sds011_init() {
|
||||||
pm25 = pm10 = 0.0;
|
pm25 = pm10 = 0.0;
|
||||||
sdsSensor.begin(&sdsSerial, SDS_RX, SDS_TX);
|
sdsSensor.begin();
|
||||||
|
|
||||||
|
String version = sdsSensor.queryFirmwareVersion().toString();
|
||||||
|
ESP_LOGI(TAG, "SDS011 firmware version %s", version);
|
||||||
|
sdsSensor.setQueryReportingMode();
|
||||||
sds011_sleep(); // we do sleep/wakup by ourselves
|
sds011_sleep(); // we do sleep/wakup by ourselves
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// reading data:
|
// reading data:
|
||||||
void sds011_loop() {
|
void sds011_loop() {
|
||||||
if (isSDS011Active) {
|
if (isSDS011Active) {
|
||||||
int sdsErrorCode = sdsSensor.read(&pm25, &pm10);
|
PmResult pm = sdsSensor.queryPm();
|
||||||
if (sdsErrorCode) {
|
if (!pm.isOk()) {
|
||||||
pm25 = pm10 = 0.0;
|
pm25 = pm10 = 0.0;
|
||||||
ESP_LOGI(TAG, "SDS011 error: %d", sdsErrorCode);
|
ESP_LOGE(TAG, "SDS011 query error");
|
||||||
} else {
|
} else {
|
||||||
|
pm25 = pm.pm25;
|
||||||
|
pm10 = pm.pm10;
|
||||||
ESP_LOGI(TAG, "fine-dust-values: %5.1f,%4.1f", pm10, pm25);
|
ESP_LOGI(TAG, "fine-dust-values: %5.1f,%4.1f", pm10, pm25);
|
||||||
}
|
}
|
||||||
sds011_sleep();
|
sds011_sleep();
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// retrieving stored data:
|
// retrieving stored data:
|
||||||
@ -49,17 +55,15 @@ void sds011_store(sdsStatus_t *sds_store) {
|
|||||||
|
|
||||||
// putting the SDS-sensor to sleep
|
// putting the SDS-sensor to sleep
|
||||||
void sds011_sleep(void) {
|
void sds011_sleep(void) {
|
||||||
sdsSensor.sleep();
|
WorkingStateResult state = sdsSensor.sleep();
|
||||||
isSDS011Active = false;
|
isSDS011Active = state.isWorking();
|
||||||
}
|
}
|
||||||
|
|
||||||
// start the SDS-sensor
|
// start the SDS-sensor
|
||||||
// needs 30 seconds for warming up
|
// needs 30 seconds for warming up
|
||||||
void sds011_wakeup() {
|
void sds011_wakeup() {
|
||||||
if (!isSDS011Active) {
|
WorkingStateResult state = sdsSensor.wakeup();
|
||||||
sdsSensor.wakeup();
|
isSDS011Active = state.isWorking();
|
||||||
isSDS011Active = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // HAS_SDS011
|
#endif // HAS_SDS011
|
||||||
|
Loading…
Reference in New Issue
Block a user