Skip to content

Commit

Permalink
added SN-GCJA5 sensor via i2c. Fixed issue on i2c only
Browse files Browse the repository at this point in the history
  • Loading branch information
hpsaturn committed Jun 8, 2021
1 parent 510da5e commit e1516a3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ lib_deps =
wifwaf/MH-Z19 @ ^1.5.3
sparkfun/SparkFun SCD30 Arduino Library @ ^1.0.10
https://github.com/hpsaturn/CM1106_UART.git
https://github.com/paulvha/SN-GCJA5.git
; https://github.com/jcomas/CM1106_UART
; hpsaturn/CanAirIO Air Quality Sensors Library

Expand Down
27 changes: 25 additions & 2 deletions src/Sensors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ void Sensors::loop() {
if ((millis() - pmLoopTimeStamp > sample_time * (uint32_t)1000)) { // sample time for each capture
pmLoopTimeStamp = millis();
dataReady = false;
dataReady = pmSensorRead();
DEBUG("-->[SENSORS] enable data from UART sensors: ",String(dataReady).c_str());
if(!_only_i2c_sensors ) {
dataReady = pmSensorRead();
DEBUG("-->[SENSORS] able data from UART sensors: ",String(dataReady).c_str());
}
dhtRead();
am2320Read();
bme280Read();
bme680Read();
aht10Read();
sht31Read();
CO2scd30Read();
PMGCJA5Read();

if(!dataReady)DEBUG("-->[SENSORS] Any data from sensors? check your wirings!");

Expand Down Expand Up @@ -67,6 +70,7 @@ void Sensors::init(int pms_type, int pms_rx, int pms_tx) {

DEBUG("-->[SENSORS] trying to load I2C sensors..");
sps30I2CInit();
PMGCJA5Init();
am2320Init();
sht31Init();
bme280Init();
Expand Down Expand Up @@ -473,6 +477,14 @@ void Sensors::CO2scd30Read() {
}
}

void Sensors::PMGCJA5Read() {
if (getPmDeviceSelected().equals("PANASONIC")) {
pm10 = pmGCJA5.getPC1_0();
pm25 = pmGCJA5.getPC2_5();
pm10 = pmGCJA5.getPC10();
}
}

bool Sensors::dhtIsReady(float *temperature, float *humidity) {
static unsigned long measurement_timestamp = millis();

Expand Down Expand Up @@ -852,6 +864,17 @@ void Sensors::CO2scd30Init() {
}
}

void Sensors::PMGCJA5Init() {
DEBUG("-->[GCJA5] starting PANASONIC GCJA5 sensor..");
if (pmGCJA5.begin()) {
DEBUG("-->[GCJA5] PANASONIC via I2C detected!");
device_selected = "PANASONIC";
device_type = Panasonic;
uint8_t status = pmGCJA5.getStatusFan();
DEBUG("-->[GCJA5] FAN status: ",String(status).c_str());
}
}

void Sensors::dhtInit() {
}

Expand Down
6 changes: 6 additions & 0 deletions src/Sensors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <Adafruit_Sensor.h>
#include <MHZ19.h>
#include <SparkFun_SCD30_Arduino_Library.h>
#include <SparkFun_Particle_Sensor_SN-GCJA5_Arduino_Library.h>
#include <dht_nonblocking.h>
#include <sps30.h>
#include <cm1106_uart.h>
Expand Down Expand Up @@ -106,6 +107,8 @@ class Sensors {
CM1106_UART *sensor_CM1106;
CM1106_sensor sensor;
CM1106_ABC abc;
// Panasonic SN-GCJA5
SFE_PARTICLE_SENSOR pmGCJA5;

void init(int pms_type = 0, int pms_rx = PMS_RX, int pms_tx = PMS_TX);
void loop();
Expand Down Expand Up @@ -200,6 +203,9 @@ class Sensors {
void CO2scd30Init();
void CO2scd30Read();

void PMGCJA5Init();
void PMGCJA5Read();

void dhtInit();
void dhtRead();
bool dhtIsReady(float *temperature, float *humidity);
Expand Down

0 comments on commit e1516a3

Please sign in to comment.