Skip to content

Commit adbe60e

Browse files
authored
Merge pull request #144 from kike-canaries/geiger_sensor
Geiger sensor
2 parents d33d70a + 95a6a88 commit adbe60e

File tree

9 files changed

+446
-12
lines changed

9 files changed

+446
-12
lines changed

examples/advanced_multivariable/src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ void setup() {
6262
Serial.println("\n== Sensor test setup ==\n");
6363
Serial.println("-->[SETUP] Detecting sensors..");
6464

65-
sensors.setSampleTime(10); // config sensors sample time interval
65+
sensors.setSampleTime(10); // config sensors sample time interval
6666
sensors.setOnDataCallBack(&onSensorDataOk); // all data read callback
67-
sensors.setDebugMode(true); // [optional] debug mode
67+
sensors.setDebugMode(true); // [optional] debug mode
6868
sensors.detectI2COnly(false); // disable force to only i2c sensors
6969
sensors.init(); // Auto detection to UART and i2c sensors
7070
delay(1000);
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* @file main.cpp
3+
* @authors @roberbike @iw2lsi @hpsaturn
4+
* @date June 2018 - 2023
5+
* @brief Radiation sensor example
6+
* @license GPL3
7+
*
8+
* Full documentation:
9+
* https://github.com/kike-canaries/canairio_sensorlib#canairio-air-quality-sensors-library
10+
*
11+
* Full implementation for WiFi and Bluetooth Air Quality fixed and mobile station:
12+
* https://github.com/kike-canaries/canairio_firmware#canairio-firmware
13+
*
14+
* Main pull requests and discussions:
15+
* https://github.com/kike-canaries/canairio_sensorlib/pull/144
16+
* https://github.com/kike-canaries/canairio_firmware/pull/226
17+
*
18+
* CanAirIO project:
19+
* https://canair.io
20+
*
21+
* CanAirIO Docs:
22+
* https://canair.io/docs
23+
*
24+
*/
25+
26+
#include <Arduino.h>
27+
#include <Sensors.hpp>
28+
29+
void onSensorDataOk() {
30+
Serial.print(" CPM: " + String(sensors.getGeigerCPM()));
31+
Serial.print(" uSvh: " + String(sensors.getGeigerMicroSievertHour()));
32+
}
33+
34+
void onSensorDataError(const char* msg) {
35+
Serial.println(msg);
36+
}
37+
38+
/******************************************************************************
39+
* M A I N
40+
******************************************************************************/
41+
42+
void setup() {
43+
Serial.begin(115200);
44+
delay(1000);
45+
46+
Serial.println("\n== Sensor test setup ==\n");
47+
Serial.println("-->[SETUP] Detecting sensors..");
48+
49+
sensors.setSampleTime(5); // config sensors sample time interval
50+
sensors.setOnDataCallBack(&onSensorDataOk); // all data read callback
51+
sensors.setOnErrorCallBack(&onSensorDataError); // [optional] error callback
52+
sensors.setDebugMode(true); // [optional] debug mode
53+
sensors.detectI2COnly(true); // [optional] skip UART detection
54+
sensors.enableGeigerSensor(27); // Geiger in sensor pin 27
55+
56+
sensors.init(); // forced UAQ sensor. Empty for auto detection
57+
58+
delay(500);
59+
}
60+
61+
void loop() {
62+
sensors.loop(); // read sensor data and showed it
63+
}
64+
65+

library.json

Lines changed: 1 addition & 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.8",
3+
"version": "0.6.9",
44
"homepage":"https://canair.io",
55
"keywords":
66
[

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.8
2+
version=0.6.9
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: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ bool Sensors::readAllSensors() {
7777
aht10Read();
7878
DFRobotCORead();
7979
DFRobotNH3Read();
80+
geigerRead();
81+
8082
#ifdef DHT11_ENABLED
8183
dhtRead();
8284
#endif
@@ -133,7 +135,7 @@ void Sensors::init(u_int pms_type, int pms_rx, int pms_tx) {
133135
#ifdef DHT11_ENABLED
134136
dhtInit();
135137
#endif
136-
138+
137139
printSensorsRegistered(true);
138140
}
139141

@@ -332,8 +334,6 @@ float Sensors::getCO() {
332334
return co;
333335
}
334336

335-
336-
337337
/**
338338
* @brief UART only: check if the UART sensor is registered
339339
* @return bool true if the UART sensor is registered, false otherwise.
@@ -550,7 +550,11 @@ float Sensors::getUnitValue(UNIT unit) {
550550
case ALT:
551551
return alt;
552552
case GAS:
553-
return gas;
553+
return gas;
554+
case CPM:
555+
return rad->getTics();
556+
case RAD:
557+
return rad->getUSvh();
554558
case NH3:
555559
return nh3;
556560
case CO:
@@ -1601,7 +1605,6 @@ void Sensors::DFRobotNH3Init() {
16011605
}
16021606

16031607
// Altitude compensation for CO2 sensors without Pressure atm or Altitude compensation
1604-
16051608
void Sensors::CO2correctionAlt() {
16061609
DEBUG("-->[SLIB] CO2 altitud original\t:", String(CO2Val).c_str());
16071610
float CO2cor = (0.016 * ((1013.25 - hpa) /10 ) * (CO2Val - 400)) + CO2Val; // Increment of 1.6% for every hpa of difference at sea level
@@ -1646,8 +1649,37 @@ void Sensors::resetAllVariables() {
16461649
pres = 0.0;
16471650
nh3 = 0;
16481651
co = 0;
1652+
rad->clear();
16491653
}
16501654

1655+
// #########################################################################
1656+
1657+
void Sensors::geigerRead(){
1658+
if(rad->read()){
1659+
unitRegister(UNIT::CPM);
1660+
unitRegister(UNIT::RAD);
1661+
}
1662+
}
1663+
/**
1664+
* @brief Enable Geiger sensor on specific pin
1665+
* @param GPIO pin
1666+
*/
1667+
void Sensors::enableGeigerSensor(int gpio){
1668+
sensorAnnounce(SENSORS::SCAJOE);
1669+
rad = new GEIGER(gpio,devmode);
1670+
sensorRegister(SENSORS::SCAJOE);
1671+
}
1672+
1673+
uint32_t Sensors::getGeigerCPM(void) {
1674+
return rad->getTics();
1675+
}
1676+
1677+
float Sensors::getGeigerMicroSievertHour(void) {
1678+
return rad->getUSvh();
1679+
}
1680+
1681+
// #########################################################################
1682+
16511683
void Sensors::DEBUG(const char *text, const char *textb) {
16521684
if (devmode) {
16531685
_debugPort.print(text);

src/Sensors.hpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
#include <s8_uart.h>
1717
#include <sps30.h>
1818
#include <drivers/pm1006.h>
19+
#include <drivers/geiger.h>
1920
#include <DFRobot_MultiGasSensor.h>
2021

2122
#ifdef DHT11_ENABLED
2223
#include <dht_nonblocking.h>
2324
#endif
2425

25-
#define CSL_VERSION "0.6.8"
26-
#define CSL_REVISION 375
26+
#define CSL_VERSION "0.6.9"
27+
#define CSL_REVISION 376
2728

2829
/***************************************************************
2930
* 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
@@ -97,6 +98,8 @@
9798
X(PRESS, "hPa", "P") \
9899
X(ALT, "m", "Alt") \
99100
X(GAS, "Ohm", "Gas") \
101+
X(CPM, "CPM", "CPM") \
102+
X(RAD, "uSv/h", "RAD") \
100103
X(NH3, "ppm", "NH3") \
101104
X(CO, "ppm", "CO") \
102105
X(UCOUNT, "COUNT", "UCOUNT")
@@ -126,6 +129,7 @@ typedef enum UNIT : size_t { SENSOR_UNITS } UNIT;
126129
X(SDHTX, "DHTX", 3) \
127130
X(SDFRCO, "DFRCO", 3) \
128131
X(SDFRNH3, "DFRNH3", 3) \
132+
X(SCAJOE, "CAJOE", 3) \
129133
X(SCOUNT, "SCOUNT", 3)
130134

131135
#define X(utype, uname, umaintype) utype,
@@ -136,7 +140,9 @@ typedef enum SENSORS : size_t { SENSORS_TYPES } SENSORS; // backward compatibil
136140
enum class SensorGroup { SENSOR_NONE,
137141
SENSOR_PM,
138142
SENSOR_CO2,
139-
SENSOR_ENV };
143+
SENSOR_ENV,
144+
SENSOR_RAD // CAJOE_GEIGER
145+
};
140146

141147
typedef void (*errorCbFn)(const char *msg);
142148
typedef void (*voidCbFn)();
@@ -219,6 +225,9 @@ class Sensors {
219225
// DFRobot gravity NH3 sensor addr 0x77
220226
DFRobot_GAS_I2C dfrNH3;
221227

228+
// Geiger CAJOE sensor
229+
GEIGER *rad;
230+
222231
void init(u_int pms_type = 0, int pms_rx = PMS_RX, int pms_tx = PMS_TX);
223232

224233
void loop();
@@ -267,6 +276,12 @@ class Sensors {
267276

268277
float getCO();
269278

279+
void enableGeigerSensor(int gpio);
280+
281+
uint32_t getGeigerCPM(void);
282+
283+
float getGeigerMicroSievertHour(void);
284+
270285
void setTempOffset(float offset);
271286

272287
void setCO2AltitudeOffset(float altitude);
@@ -428,6 +443,8 @@ class Sensors {
428443
void sps30Errorloop(char *mess, uint8_t r);
429444
void sps30DeviceInfo();
430445

446+
void geigerRead();
447+
431448
void onSensorError(const char *msg);
432449

433450
void startI2C();
@@ -469,3 +486,4 @@ extern Sensors sensors;
469486
#endif
470487

471488
#endif
489+

0 commit comments

Comments
 (0)