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

NH3 + CO DFRobot Multigas #165

Merged
merged 6 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
95 changes: 95 additions & 0 deletions examples/gravity/readGasConcentration.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, for the moment remove this example because it don't use the CanAirIO Sensorlib example structures. This will be to understand but maybe will be useful for write a CanAirIO example.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eliminado

* @file readGasConcentration.ino
* @brief Obtain gas concentration corresponding to the current environment, output as concentration value
* @n Experimental mode: connect sensor communication pin to the main controller and burn
* @n Communication mode select, DIP switch SEL: 0: I2C, 1: UART
* @n Group serial number Address in the group
* @n A0 A1 DIP level 00 01 10 11
* @n 1 0x60 0x61 0x62 0x63
* @n 2 0x64 0x65 0x66 0x67
* @n 3 0x68 0x69 0x6A 0x6B
* @n 4 0x6C 0x6D 0x6E 0x6F
* @n 5 0x70 0x71 0x72 0x73
* @n 6 (Default address group) 0x74 0x75 0x76 0x77 (Default address)
* @n 7 0x78 0x79 0x7A 0x7B
* @n 8 0x7C 0x7D 0x7E 0x7F
* @n i2c address select, default to 0x77, A1 and A0 are grouped into 4 I2C addresses.
* @n | A0 | A1 |
* @n | 0 | 0 | 0x74
* @n | 0 | 1 | 0x75
* @n | 1 | 0 | 0x76
* @n | 1 | 1 | 0x77 default i2c address
* @n Experimental phenomenon: view the gas concentration corresponding to the current environment through serial port printing
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @license The MIT License (MIT)
* @author PengKaixing([email protected])
* @version V1.0
* @date 2021-03-28
* @url https://github.com/DFRobot/DFRobot_MultiGasSensor
*/
#include "DFRobot_MultiGasSensor.h"

//Turn on by default, using I2C communication at the time, switch to serial port communication after turning off
#define I2C_COMMUNICATION

#ifdef I2C_COMMUNICATION
#define I2C_ADDRESS 0x77
DFRobot_GAS_I2C gas(&Wire ,I2C_ADDRESS);
#else
#if (!defined ARDUINO_ESP32_DEV) && (!defined __SAMD21G18A__)
/**
UNO:pin_2-----RX
pin_3-----TX
*/
SoftwareSerial mySerial(2,3);
DFRobot_GAS_SoftWareUart gas(&mySerial);
#else
/**
ESP32:IO16-----RX
IO17-----TX
*/
DFRobot_GAS_HardWareUart gas(&Serial2); //ESP32HardwareSerial
#endif
#endif

void setup() {
//Serial port init for viewing printing output
Serial.begin(115200);

//Sensor init, used to init serial port or I2C, depending on the communication mode currently used
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);
}

void loop() {
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();
delay(1000);
}
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ lib_deps =
https://github.com/paulvha/SN-GCJA5.git
https://github.com/jcomas/S8_UART.git
https://github.com/jcomas/CM1106_UART.git
https://github.com/DFRobot/DFRobot_MultiGasSensor.git

[common]
framework = ${env.framework}
Expand Down
52 changes: 50 additions & 2 deletions src/Sensors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ bool Sensors::readAllSensors() {
bmp280Read();
bme680Read();
dhtRead();
DFRobotGravityRead();
disableWire1();

printValues();
Expand Down Expand Up @@ -117,6 +118,7 @@ void Sensors::init(int pms_type, int pms_rx, int pms_tx) {
sht31Init();
aht10Init();
dhtInit();
DFRobotgravityInit();
printSensorsRegistered(true);
}

Expand Down Expand Up @@ -557,8 +559,12 @@ float Sensors::getUnitValue(UNIT unit) {
return pres;
case ALT:
return alt;
case GAS:
return gas;
// case GAS:
roberbike marked this conversation as resolved.
Show resolved Hide resolved
// return gas;
case DFRobot_GAS::NH3:
return NH3;
case DFRobot_GAS::CO:
return CO;
default:
return 0.0;
}
Expand Down Expand Up @@ -994,6 +1000,24 @@ 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();
}

bool Sensors::dhtIsReady(float *temperature, float *humidity) {
static unsigned long measurement_timestamp = millis();
if (millis() - measurement_timestamp > sample_time * (uint32_t)1000) {
Expand Down Expand Up @@ -1558,6 +1582,28 @@ void Sensors::dhtInit() {
dhtRead();
}

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 @@ -1602,6 +1648,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
29 changes: 22 additions & 7 deletions src/Sensors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
#include <s8_uart.h>
#include <sps30.h>
#include <drivers/pm1006.h>
#include <drivers/DFRobot_MultiGasSensor.h>

#define CSL_VERSION "0.5.9"
#define CSL_REVISION 366
#define CSL_VERSION "0.5.9.1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is invalid, only add one more to the final number of revision and version.

More info here:
https://docs.platformio.org/en/latest/manifests/library-json/fields/version.html

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Entendido

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bueno, aqui deberia quedar 0.5.10 si fue un cambio pequeño compatible. O 0.6.0 si no es compatible hacia atras. Q creo es el caso por el tema del gas, porque ese getter depronto lo vamos a cambiar

#define CSL_REVISION 366.1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aqui simplemente sube el numero.


/***************************************************************
* 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,9 +99,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 @@ -123,6 +127,7 @@ typedef enum UNIT : size_t { SENSOR_UNITS } UNIT;
X(SAHT10, "AHT10", 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(int pms_type = 0, int pms_rx = PMS_RX, int pms_tx = PMS_TX);

void loop();
Expand Down Expand Up @@ -251,21 +259,22 @@ class Sensors {

float getAltitude();

float getGas();
// float getGas(); // Posible colision con DFRobot Multigas
roberbike marked this conversation as resolved.
Show resolved Hide resolved

void setTempOffset(float offset);

void setCO2AltitudeOffset(float altitude);

void setSeaLevelPressure(float hpa);


String getFormatTemp();

String getFormatPress();

String getFormatHum();

String getFormatGas();
// String getFormatGas(); // Posible colision con DFRobot Multigas

String getFormatAlt();

Expand Down Expand Up @@ -354,12 +363,15 @@ 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

void am2320Init();
void am2320Read();

Expand Down Expand Up @@ -397,6 +409,9 @@ class Sensors {
void dhtRead();
bool dhtIsReady(float *temperature, float *humidity);

void DFRobotgravityInit();
void DFRobotGravityRead();

// UART sensors methods:

bool sensorSerialInit(int pms_type, int rx, int tx);
Expand Down
95 changes: 95 additions & 0 deletions src/drivers/DFRobot_MultiGasSensor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*!
roberbike marked this conversation as resolved.
Show resolved Hide resolved
* @file readGasConcentration.ino
* @brief Obtain gas concentration corresponding to the current environment, output as concentration value
* @n Experimental mode: connect sensor communication pin to the main controller and burn
* @n Communication mode select, DIP switch SEL: 0: I2C, 1: UART
* @n Group serial number Address in the group
* @n A0 A1 DIP level 00 01 10 11
* @n 1 0x60 0x61 0x62 0x63
* @n 2 0x64 0x65 0x66 0x67
* @n 3 0x68 0x69 0x6A 0x6B
* @n 4 0x6C 0x6D 0x6E 0x6F
* @n 5 0x70 0x71 0x72 0x73
* @n 6 (Default address group) 0x74 0x75 0x76 0x77 (Default address)
* @n 7 0x78 0x79 0x7A 0x7B
* @n 8 0x7C 0x7D 0x7E 0x7F
* @n i2c address select, default to 0x77, A1 and A0 are grouped into 4 I2C addresses.
* @n | A0 | A1 |
* @n | 0 | 0 | 0x74
* @n | 0 | 1 | 0x75
* @n | 1 | 0 | 0x76
* @n | 1 | 1 | 0x77 default i2c address
* @n Experimental phenomenon: view the gas concentration corresponding to the current environment through serial port printing
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @license The MIT License (MIT)
* @author PengKaixing([email protected])
* @version V1.0
* @date 2021-03-28
* @url https://github.com/DFRobot/DFRobot_MultiGasSensor
*/
#include "DFRobot_MultiGasSensor.h"

//Turn on by default, using I2C communication at the time, switch to serial port communication after turning off
#define I2C_COMMUNICATION

#ifdef I2C_COMMUNICATION
#define I2C_ADDRESS 0x77
DFRobot_GAS_I2C gas(&Wire ,I2C_ADDRESS);
#else
#if (!defined ARDUINO_ESP32_DEV) && (!defined __SAMD21G18A__)
/**
UNO:pin_2-----RX
pin_3-----TX
*/
SoftwareSerial mySerial(2,3);
DFRobot_GAS_SoftWareUart gas(&mySerial);
#else
/**
ESP32:IO16-----RX
IO17-----TX
*/
DFRobot_GAS_HardWareUart gas(&Serial2); //ESP32HardwareSerial
#endif
#endif

void setup() {
//Serial port init for viewing printing output
Serial.begin(115200);

//Sensor init, used to init serial port or I2C, depending on the communication mode currently used
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);
}

void loop() {
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();
delay(1000);
}
Loading