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

Av/geiger improvements #173

Merged
merged 6 commits into from
Aug 8, 2023
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
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 |
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "CanAirIO Air Quality Sensors Library",
"version": "0.6.9",
"version": "0.7.0",
"homepage":"https://canair.io",
"keywords":
[
Expand All @@ -15,6 +15,7 @@
"hpma115",
"IKEA",
"Vindriktning",
"Geiger",
"PMS7003",
"PMS5003",
"AM2320",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=CanAirIO Air Quality Sensors Library
version=0.6.9
version=0.7.0
author=@hpsaturn, CanAirIO project <[email protected]>
maintainer=Antonio Vanegas <[email protected]>
url=https://github.com/kike-canaries/canairio_sensorlib
Expand Down
22 changes: 14 additions & 8 deletions src/Sensors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
Expand All @@ -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();
}

// #########################################################################
Expand Down
16 changes: 6 additions & 10 deletions src/Sensors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#include <dht_nonblocking.h>
#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
Expand Down Expand Up @@ -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") \
Expand Down Expand Up @@ -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;

Expand Down
29 changes: 10 additions & 19 deletions src/drivers/geiger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down Expand Up @@ -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;
Expand Down