Skip to content

Commit

Permalink
Merge pull request #144 from kike-canaries/geiger_sensor
Browse files Browse the repository at this point in the history
Geiger sensor
  • Loading branch information
hpsaturn authored Jul 16, 2023
2 parents d33d70a + 95a6a88 commit adbe60e
Show file tree
Hide file tree
Showing 9 changed files with 446 additions and 12 deletions.
4 changes: 2 additions & 2 deletions examples/advanced_multivariable/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ void setup() {
Serial.println("\n== Sensor test setup ==\n");
Serial.println("-->[SETUP] Detecting sensors..");

sensors.setSampleTime(10); // config sensors sample time interval
sensors.setSampleTime(10); // config sensors sample time interval
sensors.setOnDataCallBack(&onSensorDataOk); // all data read callback
sensors.setDebugMode(true); // [optional] debug mode
sensors.setDebugMode(true); // [optional] debug mode
sensors.detectI2COnly(false); // disable force to only i2c sensors
sensors.init(); // Auto detection to UART and i2c sensors
delay(1000);
Expand Down
65 changes: 65 additions & 0 deletions examples/radiation_CAJOE/radiation_CAJOE.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* @file main.cpp
* @authors @roberbike @iw2lsi @hpsaturn
* @date June 2018 - 2023
* @brief Radiation sensor example
* @license GPL3
*
* Full documentation:
* https://github.com/kike-canaries/canairio_sensorlib#canairio-air-quality-sensors-library
*
* Full implementation for WiFi and Bluetooth Air Quality fixed and mobile station:
* https://github.com/kike-canaries/canairio_firmware#canairio-firmware
*
* Main pull requests and discussions:
* https://github.com/kike-canaries/canairio_sensorlib/pull/144
* https://github.com/kike-canaries/canairio_firmware/pull/226
*
* CanAirIO project:
* https://canair.io
*
* CanAirIO Docs:
* https://canair.io/docs
*
*/

#include <Arduino.h>
#include <Sensors.hpp>

void onSensorDataOk() {
Serial.print(" CPM: " + String(sensors.getGeigerCPM()));
Serial.print(" uSvh: " + String(sensors.getGeigerMicroSievertHour()));
}

void onSensorDataError(const char* msg) {
Serial.println(msg);
}

/******************************************************************************
* M A I N
******************************************************************************/

void setup() {
Serial.begin(115200);
delay(1000);

Serial.println("\n== Sensor test setup ==\n");
Serial.println("-->[SETUP] Detecting sensors..");

sensors.setSampleTime(5); // config sensors sample time interval
sensors.setOnDataCallBack(&onSensorDataOk); // all data read callback
sensors.setOnErrorCallBack(&onSensorDataError); // [optional] error callback
sensors.setDebugMode(true); // [optional] debug mode
sensors.detectI2COnly(true); // [optional] skip UART detection
sensors.enableGeigerSensor(27); // Geiger in sensor pin 27

sensors.init(); // forced UAQ sensor. Empty for auto detection

delay(500);
}

void loop() {
sensors.loop(); // read sensor data and showed it
}


2 changes: 1 addition & 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.8",
"version": "0.6.9",
"homepage":"https://canair.io",
"keywords":
[
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.8
version=0.6.9
author=@hpsaturn, CanAirIO project <[email protected]>
maintainer=Antonio Vanegas <[email protected]>
url=https://github.com/kike-canaries/canairio_sensorlib
Expand Down
42 changes: 37 additions & 5 deletions src/Sensors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ bool Sensors::readAllSensors() {
aht10Read();
DFRobotCORead();
DFRobotNH3Read();
geigerRead();

#ifdef DHT11_ENABLED
dhtRead();
#endif
Expand Down Expand Up @@ -133,7 +135,7 @@ void Sensors::init(u_int pms_type, int pms_rx, int pms_tx) {
#ifdef DHT11_ENABLED
dhtInit();
#endif

printSensorsRegistered(true);
}

Expand Down Expand Up @@ -332,8 +334,6 @@ float Sensors::getCO() {
return co;
}



/**
* @brief UART only: check if the UART sensor is registered
* @return bool true if the UART sensor is registered, false otherwise.
Expand Down Expand Up @@ -550,7 +550,11 @@ float Sensors::getUnitValue(UNIT unit) {
case ALT:
return alt;
case GAS:
return gas;
return gas;
case CPM:
return rad->getTics();
case RAD:
return rad->getUSvh();
case NH3:
return nh3;
case CO:
Expand Down Expand Up @@ -1601,7 +1605,6 @@ void Sensors::DFRobotNH3Init() {
}

// Altitude compensation for CO2 sensors without Pressure atm or Altitude compensation

void Sensors::CO2correctionAlt() {
DEBUG("-->[SLIB] CO2 altitud original\t:", String(CO2Val).c_str());
float CO2cor = (0.016 * ((1013.25 - hpa) /10 ) * (CO2Val - 400)) + CO2Val; // Increment of 1.6% for every hpa of difference at sea level
Expand Down Expand Up @@ -1646,8 +1649,37 @@ void Sensors::resetAllVariables() {
pres = 0.0;
nh3 = 0;
co = 0;
rad->clear();
}

// #########################################################################

void Sensors::geigerRead(){
if(rad->read()){
unitRegister(UNIT::CPM);
unitRegister(UNIT::RAD);
}
}
/**
* @brief Enable Geiger sensor on specific pin
* @param GPIO pin
*/
void Sensors::enableGeigerSensor(int gpio){
sensorAnnounce(SENSORS::SCAJOE);
rad = new GEIGER(gpio,devmode);
sensorRegister(SENSORS::SCAJOE);
}

uint32_t Sensors::getGeigerCPM(void) {
return rad->getTics();
}

float Sensors::getGeigerMicroSievertHour(void) {
return rad->getUSvh();
}

// #########################################################################

void Sensors::DEBUG(const char *text, const char *textb) {
if (devmode) {
_debugPort.print(text);
Expand Down
24 changes: 21 additions & 3 deletions src/Sensors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
#include <s8_uart.h>
#include <sps30.h>
#include <drivers/pm1006.h>
#include <drivers/geiger.h>
#include <DFRobot_MultiGasSensor.h>

#ifdef DHT11_ENABLED
#include <dht_nonblocking.h>
#endif

#define CSL_VERSION "0.6.8"
#define CSL_REVISION 375
#define CSL_VERSION "0.6.9"
#define CSL_REVISION 376

/***************************************************************
* 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 @@ -97,6 +98,8 @@
X(PRESS, "hPa", "P") \
X(ALT, "m", "Alt") \
X(GAS, "Ohm", "Gas") \
X(CPM, "CPM", "CPM") \
X(RAD, "uSv/h", "RAD") \
X(NH3, "ppm", "NH3") \
X(CO, "ppm", "CO") \
X(UCOUNT, "COUNT", "UCOUNT")
Expand Down Expand Up @@ -126,6 +129,7 @@ typedef enum UNIT : size_t { SENSOR_UNITS } UNIT;
X(SDHTX, "DHTX", 3) \
X(SDFRCO, "DFRCO", 3) \
X(SDFRNH3, "DFRNH3", 3) \
X(SCAJOE, "CAJOE", 3) \
X(SCOUNT, "SCOUNT", 3)

#define X(utype, uname, umaintype) utype,
Expand All @@ -136,7 +140,9 @@ typedef enum SENSORS : size_t { SENSORS_TYPES } SENSORS; // backward compatibil
enum class SensorGroup { SENSOR_NONE,
SENSOR_PM,
SENSOR_CO2,
SENSOR_ENV };
SENSOR_ENV,
SENSOR_RAD // CAJOE_GEIGER
};

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

// Geiger CAJOE sensor
GEIGER *rad;

void init(u_int pms_type = 0, int pms_rx = PMS_RX, int pms_tx = PMS_TX);

void loop();
Expand Down Expand Up @@ -267,6 +276,12 @@ class Sensors {

float getCO();

void enableGeigerSensor(int gpio);

uint32_t getGeigerCPM(void);

float getGeigerMicroSievertHour(void);

void setTempOffset(float offset);

void setCO2AltitudeOffset(float altitude);
Expand Down Expand Up @@ -428,6 +443,8 @@ class Sensors {
void sps30Errorloop(char *mess, uint8_t r);
void sps30DeviceInfo();

void geigerRead();

void onSensorError(const char *msg);

void startI2C();
Expand Down Expand Up @@ -469,3 +486,4 @@ extern Sensors sensors;
#endif

#endif

Loading

0 comments on commit adbe60e

Please sign in to comment.