Skip to content

Commit 2a26acd

Browse files
committed
Adding support for the MPR MicroPressure and SN-GCJA5 Particle sensors
1 parent a8d022b commit 2a26acd

File tree

7 files changed

+661
-3
lines changed

7 files changed

+661
-3
lines changed
7.13 KB
Binary file not shown.

Firmware/OpenLog_Artemis/OpenLog_Artemis.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@
6565
(done) Correct the measurement count misbehaviour (Issue #31)
6666
(done) Use the corrected IMU temperature calculation (Issue #28)
6767
(done) Add individual power-on delays for each sensor type. Add an extended delay for the SCD30. (Issue #5)
68-
6968
(done) v1.7: Fix readVin after sleep bug: https://github.com/sparkfun/OpenLog_Artemis/issues/39
70-
7169
(done) Change detectQwiicDevices so that the MCP9600 (Qwiic Thermocouple) is detected correctly
70+
(done) Add support for the MPRLS0025PA micro pressure sensor
71+
(done) Add support for the SN-GCJA5 particle sensor
7272
*/
7373

7474
const int FIRMWARE_VERSION_MAJOR = 1;
@@ -199,6 +199,8 @@ ICM_20948_SPI myICM;
199199
#include "SparkFun_Qwiic_Humidity_AHT20.h" //Click here to get the library: http://librarymanager/All#Qwiic_Humidity_AHT20 by SparkFun
200200
#include "SparkFun_SHTC3.h" // Click here to get the library: http://librarymanager/All#SparkFun_SHTC3
201201
#include "SparkFun_ADS122C04_ADC_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_ADS122C04
202+
#include "SparkFun_MicroPressure.h" // Click here to get the library: http://librarymanager/All#SparkFun_MicroPressure
203+
#include "SparkFun_Particle_Sensor_SN-GCJA5_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_Particle_Sensor_SN-GCJA5
202204

203205
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
204206

Firmware/OpenLog_Artemis/Sensors.ino

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,124 @@ void gatherDeviceValues()
678678
}
679679
}
680680
break;
681+
case DEVICE_PRESSURE_MPR0025PA1:
682+
{
683+
SparkFun_MicroPressure *nodeDevice = (SparkFun_MicroPressure *)temp->classPtr;
684+
struct_MPR0025PA1 *nodeSetting = (struct_MPR0025PA1 *)temp->configPtr;
685+
if (nodeSetting->log == true)
686+
{
687+
if (nodeSetting->usePSI)
688+
{
689+
sprintf(tempData, "%.04f,", nodeDevice->readPressure());
690+
strcat(outputData, tempData);
691+
}
692+
if (nodeSetting->usePA)
693+
{
694+
sprintf(tempData, "%.01f,", nodeDevice->readPressure(PA));
695+
strcat(outputData, tempData);
696+
}
697+
if (nodeSetting->useKPA)
698+
{
699+
sprintf(tempData, "%.04f,", nodeDevice->readPressure(KPA));
700+
strcat(outputData, tempData);
701+
}
702+
if (nodeSetting->useTORR)
703+
{
704+
sprintf(tempData, "%.03f,", nodeDevice->readPressure(TORR));
705+
strcat(outputData, tempData);
706+
}
707+
if (nodeSetting->useINHG)
708+
{
709+
sprintf(tempData, "%.04f,", nodeDevice->readPressure(INHG));
710+
strcat(outputData, tempData);
711+
}
712+
if (nodeSetting->useATM)
713+
{
714+
sprintf(tempData, "%.06f,", nodeDevice->readPressure(ATM));
715+
strcat(outputData, tempData);
716+
}
717+
if (nodeSetting->useBAR)
718+
{
719+
sprintf(tempData, "%.06f,", nodeDevice->readPressure(BAR));
720+
strcat(outputData, tempData);
721+
}
722+
}
723+
}
724+
break;
725+
case DEVICE_PARTICLE_SNGCJA5:
726+
{
727+
SFE_PARTICLE_SENSOR *nodeDevice = (SFE_PARTICLE_SENSOR *)temp->classPtr;
728+
struct_SNGCJA5 *nodeSetting = (struct_SNGCJA5 *)temp->configPtr;
729+
if (nodeSetting->log == true)
730+
{
731+
if (nodeSetting->logPM1)
732+
{
733+
sprintf(tempData, "%.02f,", nodeDevice->getPM1_0());
734+
strcat(outputData, tempData);
735+
}
736+
if (nodeSetting->logPM25)
737+
{
738+
sprintf(tempData, "%.02f,", nodeDevice->getPM2_5());
739+
strcat(outputData, tempData);
740+
}
741+
if (nodeSetting->logPM10)
742+
{
743+
sprintf(tempData, "%.02f,", nodeDevice->getPM10());
744+
strcat(outputData, tempData);
745+
}
746+
if (nodeSetting->logPC05)
747+
{
748+
sprintf(tempData, "%d,", nodeDevice->getPC0_5());
749+
strcat(outputData, tempData);
750+
}
751+
if (nodeSetting->logPC1)
752+
{
753+
sprintf(tempData, "%d,", nodeDevice->getPC1_0());
754+
strcat(outputData, tempData);
755+
}
756+
if (nodeSetting->logPC25)
757+
{
758+
sprintf(tempData, "%d,", nodeDevice->getPC2_5());
759+
strcat(outputData, tempData);
760+
}
761+
if (nodeSetting->logPC50)
762+
{
763+
sprintf(tempData, "%d,", nodeDevice->getPC5_0());
764+
strcat(outputData, tempData);
765+
}
766+
if (nodeSetting->logPC75)
767+
{
768+
sprintf(tempData, "%d,", nodeDevice->getPC7_5());
769+
strcat(outputData, tempData);
770+
}
771+
if (nodeSetting->logPC10)
772+
{
773+
sprintf(tempData, "%d,", nodeDevice->getPC10());
774+
strcat(outputData, tempData);
775+
}
776+
if (nodeSetting->logSensorStatus)
777+
{
778+
sprintf(tempData, "%d,", nodeDevice->getStatusSensors());
779+
strcat(outputData, tempData);
780+
}
781+
if (nodeSetting->logPDStatus)
782+
{
783+
sprintf(tempData, "%d,", nodeDevice->getStatusPD());
784+
strcat(outputData, tempData);
785+
}
786+
if (nodeSetting->logLDStatus)
787+
{
788+
sprintf(tempData, "%d,", nodeDevice->getStatusLD());
789+
strcat(outputData, tempData);
790+
}
791+
if (nodeSetting->logFanStatus)
792+
{
793+
sprintf(tempData, "%d,", nodeDevice->getStatusFan());
794+
strcat(outputData, tempData);
795+
}
796+
}
797+
}
798+
break;
681799
default:
682800
Serial.printf("printDeviceValue unknown device type: %s\r\n", getDeviceName(temp->deviceType));
683801
break;
@@ -989,6 +1107,62 @@ void printHelperText(bool terminalOnly)
9891107
}
9901108
}
9911109
break;
1110+
case DEVICE_PRESSURE_MPR0025PA1:
1111+
{
1112+
struct_MPR0025PA1 *nodeSetting = (struct_MPR0025PA1 *)temp->configPtr;
1113+
if (nodeSetting->log)
1114+
{
1115+
if (nodeSetting->usePSI)
1116+
strcat(helperText, "PSI,");
1117+
if (nodeSetting->usePA)
1118+
strcat(helperText, "Pa,");
1119+
if (nodeSetting->useKPA)
1120+
strcat(helperText, "kPa,");
1121+
if (nodeSetting->useTORR)
1122+
strcat(helperText, "torr,");
1123+
if (nodeSetting->useINHG)
1124+
strcat(helperText, "inHg,");
1125+
if (nodeSetting->useATM)
1126+
strcat(helperText, "atm,");
1127+
if (nodeSetting->useBAR)
1128+
strcat(helperText, "bar,");
1129+
}
1130+
}
1131+
break;
1132+
case DEVICE_PARTICLE_SNGCJA5:
1133+
{
1134+
struct_SNGCJA5 *nodeSetting = (struct_SNGCJA5 *)temp->configPtr;
1135+
if (nodeSetting->log)
1136+
{
1137+
if (nodeSetting->logPM1)
1138+
strcat(helperText, "PM1_0,");
1139+
if (nodeSetting->logPM25)
1140+
strcat(helperText, "PM2_5,");
1141+
if (nodeSetting->logPM10)
1142+
strcat(helperText, "PM10,");
1143+
if (nodeSetting->logPC05)
1144+
strcat(helperText, "PC0_5,");
1145+
if (nodeSetting->logPC1)
1146+
strcat(helperText, "PC1_0,");
1147+
if (nodeSetting->logPC25)
1148+
strcat(helperText, "PC2_5,");
1149+
if (nodeSetting->logPC50)
1150+
strcat(helperText, "PC5_0,");
1151+
if (nodeSetting->logPC75)
1152+
strcat(helperText, "PC7_5,");
1153+
if (nodeSetting->logPC10)
1154+
strcat(helperText, "PC10,");
1155+
if (nodeSetting->logSensorStatus)
1156+
strcat(helperText, "Sensors,");
1157+
if (nodeSetting->logPDStatus)
1158+
strcat(helperText, "PD,");
1159+
if (nodeSetting->logLDStatus)
1160+
strcat(helperText, "LD,");
1161+
if (nodeSetting->logFanStatus)
1162+
strcat(helperText, "Fan,");
1163+
}
1164+
}
1165+
break;
9921166
default:
9931167
Serial.printf("\nprinterHelperText device not found: %d\r\n", temp->deviceType);
9941168
break;

Firmware/OpenLog_Artemis/autoDetect.ino

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,18 @@ bool addDevice(deviceType_e deviceType, uint8_t address, uint8_t muxAddress, uin
225225
temp->configPtr = new struct_ADS122C04;
226226
}
227227
break;
228+
case DEVICE_PRESSURE_MPR0025PA1:
229+
{
230+
temp->classPtr = new SparkFun_MicroPressure;
231+
temp->configPtr = new struct_MPR0025PA1;
232+
}
233+
break;
234+
case DEVICE_PARTICLE_SNGCJA5:
235+
{
236+
temp->classPtr = new SFE_PARTICLE_SENSOR;
237+
temp->configPtr = new struct_SNGCJA5;
238+
}
239+
break;
228240
default:
229241
Serial.printf("addDevice Device type not found: %d\r\n", deviceType);
230242
break;
@@ -428,6 +440,25 @@ bool beginQwiicDevices()
428440
temp->online = true;
429441
}
430442
break;
443+
case DEVICE_PRESSURE_MPR0025PA1:
444+
{
445+
// TO DO: Figure out how to pass minimumPSI and maximumPSI when instantiating the sensor. Maybe add an update-_minPsi-and-_maxPsi function to the library?
446+
SparkFun_MicroPressure *tempDevice = (SparkFun_MicroPressure *)temp->classPtr;
447+
struct_MPR0025PA1 *nodeSetting = (struct_MPR0025PA1 *)temp->configPtr; //Create a local pointer that points to same spot as node does
448+
if (nodeSetting->powerOnDelayMillis > qwiicPowerOnDelayMillis) qwiicPowerOnDelayMillis = nodeSetting->powerOnDelayMillis; // Increase qwiicPowerOnDelayMillis if required
449+
if (tempDevice->begin(temp->address, qwiic) == true) //Address, Wire port. Returns true on success.
450+
temp->online = true;
451+
}
452+
break;
453+
case DEVICE_PARTICLE_SNGCJA5:
454+
{
455+
SFE_PARTICLE_SENSOR *tempDevice = (SFE_PARTICLE_SENSOR *)temp->classPtr;
456+
struct_SNGCJA5 *nodeSetting = (struct_SNGCJA5 *)temp->configPtr; //Create a local pointer that points to same spot as node does
457+
if (nodeSetting->powerOnDelayMillis > qwiicPowerOnDelayMillis) qwiicPowerOnDelayMillis = nodeSetting->powerOnDelayMillis; // Increase qwiicPowerOnDelayMillis if required
458+
if (tempDevice->begin(qwiic) == true) //Wire port. Returns true on success.
459+
temp->online = true;
460+
}
461+
break;
431462
default:
432463
Serial.printf("beginQwiicDevices: device type not found: %d\r\n", temp->deviceType);
433464
break;
@@ -459,7 +490,7 @@ void printOnlineDevice()
459490

460491
if (temp == NULL)
461492
{
462-
printDebug(F("printOnlineDevice: No devices detected"));
493+
printDebug(F("printOnlineDevice: No devices detected\r\n"));
463494
return;
464495
}
465496

@@ -668,6 +699,12 @@ void configureDevice(node * temp)
668699
sensor->configureADCmode(ADS122C04_2WIRE_HI_TEMP);
669700
}
670701
break;
702+
case DEVICE_PRESSURE_MPR0025PA1:
703+
//Nothing to configure
704+
break;
705+
case DEVICE_PARTICLE_SNGCJA5:
706+
//Nothing to configure
707+
break;
671708
default:
672709
Serial.printf("configureDevice: Unknown device type %d: %s\r\n", deviceType, getDeviceName((deviceType_e)deviceType));
673710
break;
@@ -752,6 +789,12 @@ FunctionPointer getConfigFunctionPtr(uint8_t nodeNumber)
752789
case DEVICE_ADC_ADS122C04:
753790
ptr = (FunctionPointer)menuConfigure_ADS122C04;
754791
break;
792+
case DEVICE_PRESSURE_MPR0025PA1:
793+
ptr = (FunctionPointer)menuConfigure_MPR0025PA1;
794+
break;
795+
case DEVICE_PARTICLE_SNGCJA5:
796+
ptr = (FunctionPointer)menuConfigure_SNGCJA5;
797+
break;
755798
default:
756799
Serial.println(F("getConfigFunctionPtr: Unknown device type"));
757800
Serial.flush();
@@ -880,8 +923,10 @@ void swap(struct node * a, struct node * b)
880923
// Available Qwiic devices
881924
//We no longer use defines in the search table. These are just here for reference.
882925
#define ADR_VEML6075 0x10
926+
#define ADR_MPR0025PA1 0x18
883927
#define ADR_NAU7802 0x2A
884928
#define ADR_VL53L1X 0x29
929+
#define ADR_SNGCJA5 0x33
885930
#define ADR_AHT20 0x38
886931
#define ADR_MS8607 0x40 //Humidity portion of the MS8607 sensor
887932
#define ADR_UBLOX 0x42 //But can be set to any address
@@ -913,6 +958,15 @@ deviceType_e testDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portNumb
913958
return (DEVICE_UV_VEML6075);
914959
}
915960
break;
961+
case 0x18:
962+
{
963+
//Confidence: Medium - Checks the status byte power indication bit and three "always 0" bits
964+
SparkFun_MicroPressure sensor;
965+
if (sensor.begin(i2cAddress, qwiic) == true) //Address, Wire port
966+
if ((sensor.readStatus() & 0x5A) == 0x40) // Mask the power indication bit and three "always 0" bits
967+
return (DEVICE_PRESSURE_MPR0025PA1);
968+
}
969+
break;
916970
case 0x2A:
917971
{
918972
//Confidence: High - Checks 8 bit revision code (0x0F)
@@ -930,6 +984,14 @@ deviceType_e testDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portNumb
930984
return (DEVICE_DISTANCE_VL53L1X);
931985
}
932986
break;
987+
case 0x33:
988+
{
989+
//Confidence: low - basic isConnected test only...
990+
SFE_PARTICLE_SENSOR sensor;
991+
if (sensor.begin(qwiic) == true) //Wire port
992+
return (DEVICE_PARTICLE_SNGCJA5);
993+
}
994+
break;
933995
case 0x38:
934996
{
935997
//Confidence: Medium - begin() does a variety of inits and checks
@@ -1355,6 +1417,12 @@ const char* getDeviceName(deviceType_e deviceNumber)
13551417
case DEVICE_ADC_ADS122C04:
13561418
return "ADC-ADS122C04";
13571419
break;
1420+
case DEVICE_PRESSURE_MPR0025PA1:
1421+
return "Pressure-MPR";
1422+
break;
1423+
case DEVICE_PARTICLE_SNGCJA5:
1424+
return "Particle-SNGCJA5";
1425+
break;
13581426

13591427
case DEVICE_UNKNOWN_DEVICE:
13601428
return "Unknown device";

0 commit comments

Comments
 (0)