Skip to content

Commit 0fd31e7

Browse files
authored
Merge pull request #173 from kike-canaries/av/geiger_improvements
Av/geiger improvements
2 parents f8b4381 + 1a7980e commit 0fd31e7

File tree

6 files changed

+43
-44
lines changed

6 files changed

+43
-44
lines changed

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ For developers also you can check the complete library documentation [here](http
2828
| IKEA Vindriktning | Yes | --- | Select | STABLE |
2929
| Sensirion SPS30 | Yes | Yes | Select / Auto | STABLE |
3030

31-
NOTE: Panasonic via UART in ESP8266 maybe needs select in detection
31+
NOTE:
32+
Panasonic via UART in ESP8266 maybe needs select in detection.
3233

3334
### CO2 sensors
3435

@@ -40,7 +41,6 @@ NOTE: Panasonic via UART in ESP8266 maybe needs select in detection
4041
| CM1106 | Yes | --- | Select | STABLE |
4142
| SenseAir S8 | Yes | --- | Select | STABLE |
4243

43-
4444
### Environmental sensors
4545

4646
| Sensor model | Protocol | Detection mode | Status |
@@ -53,9 +53,11 @@ NOTE: Panasonic via UART in ESP8266 maybe needs select in detection
5353
| BME680 | i2c | Auto | STABLE |
5454
| DfRobot SEN0469 NH3 | i2c | Auto | TESTING |
5555
| DFRobot SEN0466 CO | i2c | Auto | TESTING |
56-
| DHTxx | TwoWire | Auto | DISABLED |
56+
| Geiger CAJOE | GPIO | Select | TESTING |
57+
| DHTxx | TwoWire | Select | DISABLED |
5758

58-
NOTE: DHT22 is supported but is not recommended. Please see the documentation.
59+
NOTE:
60+
DHT22 is supported but is not recommended. Please see the documentation.
5961

6062
### Platforms supported
6163

@@ -282,12 +284,14 @@ For now we are using it only for DHT sensors in PIN 23. For more info please rev
282284

283285
### PlatformIO (recommended)
284286

285-
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:
287+
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:
286288

287289
```python
288290
pio run -e esp32 --target upload
289291
```
290292

293+
Also you can see some examples than have `platformio.ini` files for your project.
294+
291295
### Arduino IDE
292296

293297
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:
361365
- [x] Multivariable selection (getNextUnit(),getUnitName(),etc)
362366
- [x] Two I2C channel supported for M5Stack Devices (M5StickC tested)
363367
- [x] Added CO and NH3 sensors
368+
- [x] Added Geiger sensor support
364369
- [ ] Sea level setting for Pressure sensors and others
365370
- [ ] Support to second UART port
366371

library.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "CanAirIO Air Quality Sensors Library",
3-
"version": "0.6.9",
3+
"version": "0.7.0",
44
"homepage":"https://canair.io",
55
"keywords":
66
[
@@ -15,6 +15,7 @@
1515
"hpma115",
1616
"IKEA",
1717
"Vindriktning",
18+
"Geiger",
1819
"PMS7003",
1920
"PMS5003",
2021
"AM2320",

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=CanAirIO Air Quality Sensors Library
2-
version=0.6.9
2+
version=0.7.0
33
author=@hpsaturn, CanAirIO project <info@canair.io>
44
maintainer=Antonio Vanegas <hpsaturn@gmail.com>
55
url=https://github.com/kike-canaries/canairio_sensorlib

src/Sensors.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -552,9 +552,9 @@ float Sensors::getUnitValue(UNIT unit) {
552552
case GAS:
553553
return gas;
554554
case CPM:
555-
return rad->getTics();
555+
return getGeigerCPM();
556556
case RAD:
557-
return rad->getUSvh();
557+
return getGeigerMicroSievertHour();
558558
case NH3:
559559
return nh3;
560560
case CO:
@@ -1613,9 +1613,9 @@ void Sensors::CO2correctionAlt() {
16131613
}
16141614

16151615
float Sensors::hpaCalculation(float altitude) {
1616-
DEBUG("-->[SLIB] Altitude Compensation for CO2 lectures ON\t:", String(altitude).c_str());
1616+
DEBUG("-->[SLIB] CO2 altitude offset\t:", String(altitude).c_str());
16171617
float hpa = 1012 - 0.118 * altitude + 0.00000473 * altitude * altitude; // Cuadratic regresion formula obtained PA (hpa) from high above the sea
1618-
DEBUG("-->[SLIB] Atmospheric pressure calculated in hPa\t:", String(hpa).c_str());
1618+
DEBUG("-->[SLIB] CO2 pressure (hPa)\t:", String(hpa).c_str());
16191619
return hpa;
16201620
}
16211621

@@ -1649,13 +1649,13 @@ void Sensors::resetAllVariables() {
16491649
pres = 0.0;
16501650
nh3 = 0;
16511651
co = 0;
1652-
rad->clear();
1652+
if (rad !=nullptr) rad->clear();
16531653
}
16541654

16551655
// #########################################################################
16561656

16571657
void Sensors::geigerRead(){
1658-
if(rad->read()){
1658+
if(rad !=nullptr && rad->read()){
16591659
unitRegister(UNIT::CPM);
16601660
unitRegister(UNIT::RAD);
16611661
}
@@ -1666,16 +1666,22 @@ void Sensors::geigerRead(){
16661666
*/
16671667
void Sensors::enableGeigerSensor(int gpio){
16681668
sensorAnnounce(SENSORS::SCAJOE);
1669+
if (gpio < 0) {
1670+
if (devmode) Serial.printf("[W][SLIB] undefined Geiger pin\t: %i\r\n", gpio);
1671+
return;
1672+
}
16691673
rad = new GEIGER(gpio,devmode);
16701674
sensorRegister(SENSORS::SCAJOE);
16711675
}
16721676

16731677
uint32_t Sensors::getGeigerCPM(void) {
1674-
return rad->getTics();
1678+
if (rad == nullptr) return 0;
1679+
else return rad->getTics();
16751680
}
16761681

16771682
float Sensors::getGeigerMicroSievertHour(void) {
1678-
return rad->getUSvh();
1683+
if (rad == nullptr) return 0;
1684+
else return rad->getUSvh();
16791685
}
16801686

16811687
// #########################################################################

src/Sensors.hpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
#include <dht_nonblocking.h>
2424
#endif
2525

26-
#define CSL_VERSION "0.6.9"
27-
#define CSL_REVISION 376
26+
#define CSL_VERSION "0.7.0"
27+
#define CSL_REVISION 377
2828

2929
/***************************************************************
3030
* 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 @@
9898
X(PRESS, "hPa", "P") \
9999
X(ALT, "m", "Alt") \
100100
X(GAS, "Ohm", "Gas") \
101-
X(CPM, "CPM", "CPM") \
101+
X(CPM, "CPM", "RAD") \
102102
X(RAD, "uSv/h", "RAD") \
103103
X(NH3, "ppm", "NH3") \
104104
X(CO, "ppm", "CO") \
@@ -203,28 +203,24 @@ class Sensors {
203203
Adafruit_SCD30 scd30;
204204
// CM1106 UART
205205
CM1106_UART *cm1106;
206-
206+
// CM1106 UART
207207
CM1106_sensor cm1106sensor;
208-
208+
// CM1106 UART
209209
CM1106_ABC abc;
210210
// Panasonic SN-GCJA5
211211
SFE_PARTICLE_SENSOR pmGCJA5;
212212
// SenseAir S8 CO2 sensor
213213
S8_UART *s8;
214-
214+
// SenseAir S8 CO2 sensor
215215
S8_sensor s8sensor;
216216
// SCD4x sensor
217217
SensirionI2CScd4x scd4x;
218-
219218
// IKEA Vindriktn sensor
220219
PM1006 *pm1006;
221-
222220
// DFRobot gravity NH3 sensor addr 0x74
223221
DFRobot_GAS_I2C dfrCO;
224-
225222
// DFRobot gravity NH3 sensor addr 0x77
226223
DFRobot_GAS_I2C dfrNH3;
227-
228224
// Geiger CAJOE sensor
229225
GEIGER *rad;
230226

src/drivers/geiger.cpp

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ void IRAM_ATTR onGeigerTimer() {
3131
// #########################################################################
3232
// Initialize Geiger counter
3333
GEIGER::GEIGER(int gpio, bool debug) {
34-
#ifdef ESP32
35-
if (gpio < 0) {
36-
if (debug) Serial.println("[E][SLIB] undefined Geiger pin");
37-
return;
38-
}
34+
#ifdef ESP32
3935
devmode = debug;
4036
tics_cnt = 0U; // tics in 1000ms
4137
tics_tot = 0U; // total tics since boot
@@ -57,8 +53,6 @@ GEIGER::GEIGER(int gpio, bool debug) {
5753
timerAttachInterrupt(geiger_timer, &onGeigerTimer, true);
5854
timerAlarmWrite(geiger_timer, 1000000, true); // 1000 ms
5955
timerAlarmEnable(geiger_timer);
60-
61-
Serial.println("-->[SLIB] Geiger counter ready");
6256
#endif
6357
}
6458

@@ -87,19 +81,16 @@ bool GEIGER::read() {
8781
} else {
8882
uSvh = 0.0;
8983
}
90-
91-
if (!devmode) return true;
92-
93-
Serial.print("-->[SLIB] tTOT: ");
94-
Serial.println(tics_tot);
95-
Serial.print("-->[SLIB] tLEN: ");
96-
Serial.print(tics_len);
97-
Serial.println(ready ? " (ready)" : " (not ready)");
98-
Serial.print("-->[SLIB] tCPM: ");
99-
Serial.println(tics_cpm);
100-
Serial.print("-->[SLIB] uSvh: ");
101-
Serial.println(uSvh);
10284

85+
#ifdef CORE_DEBUG_LEVEL
86+
if (CORE_DEBUG_LEVEL >= 3) {
87+
Serial.printf("-->[SLIB] tTOT:\t %i\r\n", tics_tot);
88+
Serial.printf("-->[SLIB] tLEN:\t %i ", tics_len);
89+
Serial.println(ready ? "(ready)" : "(not ready)");
90+
Serial.printf("-->[SLIB] tCPM:\t %i\r\n", tics_cpm);
91+
Serial.printf("-->[SLIB] uSvh:\t %04.2f\r\n", uSvh);
92+
}
93+
#endif
10394
return true;
10495
#else
10596
return false;

0 commit comments

Comments
 (0)