Skip to content

Commit

Permalink
Merge pull request #165 from roberbike/gravity
Browse files Browse the repository at this point in the history
NH3 + CO DFRobot Multigas
  • Loading branch information
hpsaturn authored May 29, 2023
2 parents 51a2c31 + f5d6a70 commit ff7ef67
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 14 deletions.
3 changes: 0 additions & 3 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ monitor_speed = 115200
monitor_filters = time
build_flags =
-D CORE_DEBUG_LEVEL=0
; -D DHT11_ENABLED=1 // Deprecated, please change this old sensor
; -D DHT_SENSOR_TYPE=2
; -D DHT_SENSOR_PIN=19
lib_deps = ${commonlibs.lib_deps}

[common]
Expand Down
61 changes: 56 additions & 5 deletions src/Sensors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ bool Sensors::readAllSensors() {
bmp280Read();
bme680Read();
aht10Read();

DFRobotGravityRead();
#ifdef DHT11_ENABLED
dhtRead();
#endif

disableWire1();

printValues();
Expand Down Expand Up @@ -125,7 +125,8 @@ void Sensors::init(u_int pms_type, int pms_rx, int pms_tx) {
am2320Init();
sht31Init();
aht10Init();

DFRobotgravityInit();

#ifdef DHT11_ENABLED
dhtInit();
#endif
Expand Down Expand Up @@ -535,8 +536,12 @@ float Sensors::getUnitValue(UNIT unit) {
return pres;
case ALT:
return alt;
case GAS:
return gas;
// case GAS:
// return gas;
case DFRobot_GAS::NH3:
return NH3;
case DFRobot_GAS::CO:
return CO;
default:
return 0.0;
}
Expand Down Expand Up @@ -970,6 +975,26 @@ void Sensors::GCJA5Read() {
unitRegister(UNIT::PM10);
}


void Sensors::DFRobotGravityRead() {
String gastype = gas.queryGasType();
/**
*Fill in the parameter readGasConcentration() with the type of gas to be obtained and print
*The current gas concentration
*Print with 1s delay each time
*/
Serial.print("Ambient ");
Serial.print(gastype);
Serial.print(" concentration is: ");
Serial.print(gas.readGasConcentrationPPM());
if (gastype == "O2")
Serial.println(" %vol");
else
Serial.println(" PPM");
Serial.println();
}


#ifdef DHT11_ENABLED
DHT_nonblocking dht_sensor(DHT_SENSOR_PIN, DHT_SENSOR_TYPE);
/**
Expand Down Expand Up @@ -1546,6 +1571,30 @@ void Sensors::GCJA5Init() {
sensorRegister(SENSORS::SGCJA5);
}



void Sensors::DFRobotgravityInit() {
sensorAnnounce(SENSORS::MULTIGAS);
DFRobot_GAS_I2C gas(&Wire ,0x77);
while(!gas.begin())
{
Serial.println("NO Deivces !");
delay(1000);
}
Serial.println("The device is connected successfully!");

//Mode of obtaining data: the main controller needs to request the sensor for data
gas.changeAcquireMode(gas.PASSIVITY);
delay(1000);

/**
*Turn on temperature compensation: gas.ON : turn on
* gas.OFF:turn off
*/
gas.setTempCompensation(gas.ON);
sensorRegister(SENSORS::MULTIGAS);
}

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

void Sensors::CO2correctionAlt() {
Expand Down Expand Up @@ -1590,6 +1639,8 @@ void Sensors::resetAllVariables() {
alt = 0.0;
gas = 0.0;
pres = 0.0;
NH3 = 0.0;
CO = 0.0;
}

void Sensors::DEBUG(const char *text, const char *textb) {
Expand Down
32 changes: 26 additions & 6 deletions src/Sensors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <s8_uart.h>
#include <sps30.h>
#include <drivers/pm1006.h>
#include <drivers/DFRobot_MultiGasSensor.h>

#ifdef DHT11_ENABLED
#include <dht_nonblocking.h>
Expand Down Expand Up @@ -95,9 +96,12 @@
X(CO2HUM, "%", "CO2H") \
X(PRESS, "hPa", "P") \
X(ALT, "m", "Alt") \
X(GAS, "Ohm", "Gas") \
X(NH3, "ppm", "NH3") \
X(CO, "ppm", "CO") \
X(UCOUNT, "COUNT", "UCOUNT")

// X(GAS, "Ohm", "Gas") \ // COlisiona con DFRobot Multigas

#define X(unit, symbol, name) unit,
typedef enum UNIT : size_t { SENSOR_UNITS } UNIT;
#undef X
Expand All @@ -120,6 +124,7 @@ typedef enum UNIT : size_t { SENSOR_UNITS } UNIT;
X(SAHTXX, "AHTXX", 3) \
X(SAM232X, "AM232X", 3) \
X(SDHTX, "DHTX", 3) \
X(SMULTIGAS, "MULTIGAS", 2) \
X(SCOUNT, "SCOUNT", 3)

#define X(utype, uname, umaintype) utype,
Expand Down Expand Up @@ -204,9 +209,12 @@ class Sensors {
// SCD4x sensor
SensirionI2CScd4x scd4x;

// IKA Vindriktn sensor
// IKEA Vindriktn sensor
PM1006 *pm1006;

// DFRobot gravity Gas sensor
DFRobot_GAS_I2C gas;

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

void loop();
Expand Down Expand Up @@ -249,14 +257,18 @@ class Sensors {

float getAltitude();

float getGas();
// float getGas(); // Posible colision con DFRobot Multigas

float getNH3();

float getCO();

void setTempOffset(float offset);

void setCO2AltitudeOffset(float altitude);

void setSeaLevelPressure(float hpa);

void setCO2RecalibrationFactor(int ppmValue);

void detectI2COnly(bool enable);
Expand Down Expand Up @@ -333,12 +345,17 @@ class Sensors {
float temp = 0.0; // Temperature (°C)
float pres = 0.0; // Pressure
float alt = 0.0;
float gas = 0.0;

// float gas = 0.0; // Colisiona con DFRobot Multigas
uint16_t CO2Val; // CO2 in ppm
float CO2humi = 0.0; // humidity of CO2 sensor
float CO2temp = 0.0; // temperature of CO2 sensor

uint16_t NH3; // Amonium in ppm
uint16_t CO; // Carbon monoxide
float NH3 = 0.0;
float CO = 0.0;

void am2320Init();
void am2320Read();

Expand Down Expand Up @@ -378,6 +395,9 @@ class Sensors {
bool dhtIsReady(float *temperature, float *humidity);
#endif

void DFRobotgravityInit();
void DFRobotGravityRead();

// UART sensors methods:

bool sensorSerialInit(u_int pms_type, int rx, int tx);
Expand Down

0 comments on commit ff7ef67

Please sign in to comment.