diff --git a/README.md b/README.md index 5750fe60..0871fdbc 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,8 @@ For developers also you can check the complete library documentation [here](http | IKEA Vindriktning | Yes | --- | Select | STABLE | | Sensirion SPS30 | Yes | Yes | Select / Auto | STABLE | -NOTE: Panasonic via UART in ESP8266 maybe needs select in detection +NOTE: +Panasonic via UART in ESP8266 maybe needs select in detection. ### CO2 sensors @@ -40,7 +41,6 @@ NOTE: Panasonic via UART in ESP8266 maybe needs select in detection | CM1106 | Yes | --- | Select | STABLE | | SenseAir S8 | Yes | --- | Select | STABLE | - ### Environmental sensors | Sensor model | Protocol | Detection mode | Status | @@ -53,9 +53,11 @@ NOTE: Panasonic via UART in ESP8266 maybe needs select in detection | BME680 | i2c | Auto | STABLE | | DfRobot SEN0469 NH3 | i2c | Auto | TESTING | | DFRobot SEN0466 CO | i2c | Auto | TESTING | -| DHTxx | TwoWire | Auto | DISABLED | +| Geiger CAJOE | GPIO | Select | TESTING | +| DHTxx | TwoWire | Select | DISABLED | -NOTE: DHT22 is supported but is not recommended. Please see the documentation. +NOTE: +DHT22 is supported but is not recommended. Please see the documentation. ### Platforms supported @@ -282,12 +284,14 @@ For now we are using it only for DHT sensors in PIN 23. For more info please rev ### PlatformIO (recommended) -We recommended PlatformIO because is more easy than Arduino IDE. For this, please install first [PlatformIO](http://platformio.org/) and its command line tools (Windows, MacOs and Linux), **pio** command, then connect your compatible board to the USB and run the next command: +We recommended PlatformIO because is more easy than Arduino IDE. For that, please install first [PlatformIO](http://platformio.org/) and its command line tools (Windows, MacOs and Linux), **pio** command, then connect your compatible board to the USB and run the next command: ```python pio run -e esp32 --target upload ``` +Also you can see some examples than have `platformio.ini` files for your project. + ### Arduino IDE Only import the `ino` file of the sample and install the libraries listed on `library.json` and this library. Complete list of libraries used [here](https://github.com/kike-canaries/canairio_sensorlib/blob/master/unified-lib-deps.ini) @@ -361,6 +365,7 @@ Also you can make a donation, be a patreon or buy a device: - [x] Multivariable selection (getNextUnit(),getUnitName(),etc) - [x] Two I2C channel supported for M5Stack Devices (M5StickC tested) - [x] Added CO and NH3 sensors +- [x] Added Geiger sensor support - [ ] Sea level setting for Pressure sensors and others - [ ] Support to second UART port diff --git a/library.json b/library.json index e9215e07..01c24699 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "CanAirIO Air Quality Sensors Library", - "version": "0.6.9", + "version": "0.7.0", "homepage":"https://canair.io", "keywords": [ @@ -15,6 +15,7 @@ "hpma115", "IKEA", "Vindriktning", + "Geiger", "PMS7003", "PMS5003", "AM2320", diff --git a/library.properties b/library.properties index 4cf29075..f24351b7 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=CanAirIO Air Quality Sensors Library -version=0.6.9 +version=0.7.0 author=@hpsaturn, CanAirIO project maintainer=Antonio Vanegas url=https://github.com/kike-canaries/canairio_sensorlib diff --git a/src/Sensors.cpp b/src/Sensors.cpp index 28ac6ce1..61176583 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -552,9 +552,9 @@ float Sensors::getUnitValue(UNIT unit) { case GAS: return gas; case CPM: - return rad->getTics(); + return getGeigerCPM(); case RAD: - return rad->getUSvh(); + return getGeigerMicroSievertHour(); case NH3: return nh3; case CO: @@ -1613,9 +1613,9 @@ void Sensors::CO2correctionAlt() { } float Sensors::hpaCalculation(float altitude) { - DEBUG("-->[SLIB] Altitude Compensation for CO2 lectures ON\t:", String(altitude).c_str()); + DEBUG("-->[SLIB] CO2 altitude offset\t:", String(altitude).c_str()); float hpa = 1012 - 0.118 * altitude + 0.00000473 * altitude * altitude; // Cuadratic regresion formula obtained PA (hpa) from high above the sea - DEBUG("-->[SLIB] Atmospheric pressure calculated in hPa\t:", String(hpa).c_str()); + DEBUG("-->[SLIB] CO2 pressure (hPa)\t:", String(hpa).c_str()); return hpa; } @@ -1649,13 +1649,13 @@ void Sensors::resetAllVariables() { pres = 0.0; nh3 = 0; co = 0; - rad->clear(); + if (rad !=nullptr) rad->clear(); } // ######################################################################### void Sensors::geigerRead(){ - if(rad->read()){ + if(rad !=nullptr && rad->read()){ unitRegister(UNIT::CPM); unitRegister(UNIT::RAD); } @@ -1666,16 +1666,22 @@ void Sensors::geigerRead(){ */ void Sensors::enableGeigerSensor(int gpio){ sensorAnnounce(SENSORS::SCAJOE); + if (gpio < 0) { + if (devmode) Serial.printf("[W][SLIB] undefined Geiger pin\t: %i\r\n", gpio); + return; + } rad = new GEIGER(gpio,devmode); sensorRegister(SENSORS::SCAJOE); } uint32_t Sensors::getGeigerCPM(void) { - return rad->getTics(); + if (rad == nullptr) return 0; + else return rad->getTics(); } float Sensors::getGeigerMicroSievertHour(void) { - return rad->getUSvh(); + if (rad == nullptr) return 0; + else return rad->getUSvh(); } // ######################################################################### diff --git a/src/Sensors.hpp b/src/Sensors.hpp index f57500d9..c77ddb02 100644 --- a/src/Sensors.hpp +++ b/src/Sensors.hpp @@ -23,8 +23,8 @@ #include #endif -#define CSL_VERSION "0.6.9" -#define CSL_REVISION 376 +#define CSL_VERSION "0.7.0" +#define CSL_REVISION 377 /*************************************************************** * S E T U P E S P 3 2 B O A R D S A N D F I E L D S @@ -98,7 +98,7 @@ X(PRESS, "hPa", "P") \ X(ALT, "m", "Alt") \ X(GAS, "Ohm", "Gas") \ - X(CPM, "CPM", "CPM") \ + X(CPM, "CPM", "RAD") \ X(RAD, "uSv/h", "RAD") \ X(NH3, "ppm", "NH3") \ X(CO, "ppm", "CO") \ @@ -203,28 +203,24 @@ class Sensors { Adafruit_SCD30 scd30; // CM1106 UART CM1106_UART *cm1106; - + // CM1106 UART CM1106_sensor cm1106sensor; - + // CM1106 UART CM1106_ABC abc; // Panasonic SN-GCJA5 SFE_PARTICLE_SENSOR pmGCJA5; // SenseAir S8 CO2 sensor S8_UART *s8; - + // SenseAir S8 CO2 sensor S8_sensor s8sensor; // SCD4x sensor SensirionI2CScd4x scd4x; - // IKEA Vindriktn sensor PM1006 *pm1006; - // DFRobot gravity NH3 sensor addr 0x74 DFRobot_GAS_I2C dfrCO; - // DFRobot gravity NH3 sensor addr 0x77 DFRobot_GAS_I2C dfrNH3; - // Geiger CAJOE sensor GEIGER *rad; diff --git a/src/drivers/geiger.cpp b/src/drivers/geiger.cpp index 4194e4d3..455af578 100644 --- a/src/drivers/geiger.cpp +++ b/src/drivers/geiger.cpp @@ -31,11 +31,7 @@ void IRAM_ATTR onGeigerTimer() { // ######################################################################### // Initialize Geiger counter GEIGER::GEIGER(int gpio, bool debug) { -#ifdef ESP32 - if (gpio < 0) { - if (debug) Serial.println("[E][SLIB] undefined Geiger pin"); - return; - } +#ifdef ESP32 devmode = debug; tics_cnt = 0U; // tics in 1000ms tics_tot = 0U; // total tics since boot @@ -57,8 +53,6 @@ GEIGER::GEIGER(int gpio, bool debug) { timerAttachInterrupt(geiger_timer, &onGeigerTimer, true); timerAlarmWrite(geiger_timer, 1000000, true); // 1000 ms timerAlarmEnable(geiger_timer); - - Serial.println("-->[SLIB] Geiger counter ready"); #endif } @@ -87,19 +81,16 @@ bool GEIGER::read() { } else { uSvh = 0.0; } - - if (!devmode) return true; - - Serial.print("-->[SLIB] tTOT: "); - Serial.println(tics_tot); - Serial.print("-->[SLIB] tLEN: "); - Serial.print(tics_len); - Serial.println(ready ? " (ready)" : " (not ready)"); - Serial.print("-->[SLIB] tCPM: "); - Serial.println(tics_cpm); - Serial.print("-->[SLIB] uSvh: "); - Serial.println(uSvh); +#ifdef CORE_DEBUG_LEVEL + if (CORE_DEBUG_LEVEL >= 3) { + Serial.printf("-->[SLIB] tTOT:\t %i\r\n", tics_tot); + Serial.printf("-->[SLIB] tLEN:\t %i ", tics_len); + Serial.println(ready ? "(ready)" : "(not ready)"); + Serial.printf("-->[SLIB] tCPM:\t %i\r\n", tics_cpm); + Serial.printf("-->[SLIB] uSvh:\t %04.2f\r\n", uSvh); + } +#endif return true; #else return false;