Skip to content

Commit 46873aa

Browse files
committed
Adding SGP40, SDP3X and MS5837
1 parent ccd148f commit 46873aa

File tree

9 files changed

+620
-3
lines changed

9 files changed

+620
-3
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Change Log
22
======================
33

4+
v1.9
5+
---------
6+
7+
* Added support for the SGP40 air quality sensor
8+
* Added support for the SDP3X differential pressure sensor
9+
* Added support for the MS5837 depth / pressure sensor - as used in the BlueRobotics Bar02
10+
411
v1.8
512
---------
613

Firmware/OpenLog_Artemis/OpenLog_Artemis.ino

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@
8383
(done?) Add "sleep on pin" functionality based @ryanneve's PR https://github.com/sparkfun/OpenLog_Artemis/pull/64 and Issue https://github.com/sparkfun/OpenLog_Artemis/issues/46
8484
(done?) Add "wake at specified times" functionality based on Issue https://github.com/sparkfun/OpenLog_Artemis/issues/46
8585
(done?) Add corrections for the SCD30 based on Forum post by paulvha: https://forum.sparkfun.com/viewtopic.php?p=222455#p222455
86+
(done) Add support for the SGP40
87+
(done) Add support for the SDP31
88+
(done) Add support for the MS5837 - as used in the BlueRobotics BAR02 and BAR30 water pressure sensors
8689
*/
8790

8891
const int FIRMWARE_VERSION_MAJOR = 1;
@@ -215,6 +218,9 @@ ICM_20948_SPI myICM;
215218
#include "SparkFun_ADS122C04_ADC_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_ADS122C04
216219
#include "SparkFun_MicroPressure.h" // Click here to get the library: http://librarymanager/All#SparkFun_MicroPressure
217220
#include "SparkFun_Particle_Sensor_SN-GCJA5_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_Particle_Sensor_SN-GCJA5
221+
#include "SparkFun_SGP40_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SGP40
222+
#include "SparkFun_SDP3x_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SDP3x
223+
#include "MS5837.h" // Click here to download the library: https://github.com/sparkfunX/BlueRobotics_MS5837_Library
218224

219225
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
220226

Firmware/OpenLog_Artemis/Sensors.ino

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,79 @@ void gatherDeviceValues()
771771
}
772772
}
773773
break;
774+
case DEVICE_VOC_SGP40:
775+
{
776+
SGP40 *nodeDevice = (SGP40 *)temp->classPtr;
777+
struct_SGP40 *nodeSetting = (struct_SGP40 *)temp->configPtr;
778+
if (nodeSetting->log == true)
779+
{
780+
if (nodeSetting->logVOC)
781+
{
782+
sprintf(tempData, "%d,", nodeDevice->getVOCindex(nodeSetting->RH, nodeSetting->T));
783+
strcat(outputData, tempData);
784+
}
785+
}
786+
}
787+
break;
788+
case DEVICE_PRESSURE_SDP3X:
789+
{
790+
SDP3X *nodeDevice = (SDP3X *)temp->classPtr;
791+
struct_SDP3X *nodeSetting = (struct_SDP3X *)temp->configPtr;
792+
if (nodeSetting->log == true)
793+
{
794+
float pressure;
795+
float temperature;
796+
if ((nodeSetting->logPressure) || (nodeSetting->logTemperature))
797+
{
798+
nodeDevice->triggeredMeasurement(nodeSetting->massFlow, nodeSetting->clockStretching);
799+
nodeDevice->readMeasurement(&pressure, &temperature);
800+
}
801+
if (nodeSetting->logPressure)
802+
{
803+
sprintf(tempData, "%.02f,", pressure);
804+
strcat(outputData, tempData);
805+
}
806+
if (nodeSetting->logTemperature)
807+
{
808+
sprintf(tempData, "%.02f,", temperature);
809+
strcat(outputData, tempData);
810+
}
811+
}
812+
}
813+
break;
814+
case DEVICE_PRESSURE_MS5837:
815+
{
816+
MS5837 *nodeDevice = (MS5837 *)temp->classPtr;
817+
struct_MS5837 *nodeSetting = (struct_MS5837 *)temp->configPtr;
818+
if (nodeSetting->log == true)
819+
{
820+
if ((nodeSetting->logPressure) || (nodeSetting->logTemperature) || (nodeSetting->logDepth) || (nodeSetting->logAltitude))
821+
{
822+
nodeDevice->read();
823+
}
824+
if (nodeSetting->logPressure)
825+
{
826+
sprintf(tempData, "%.02f,", nodeDevice->pressure(nodeSetting->conversion));
827+
strcat(outputData, tempData);
828+
}
829+
if (nodeSetting->logTemperature)
830+
{
831+
sprintf(tempData, "%.02f,", nodeDevice->temperature());
832+
strcat(outputData, tempData);
833+
}
834+
if (nodeSetting->logDepth)
835+
{
836+
sprintf(tempData, "%.03f,", nodeDevice->depth());
837+
strcat(outputData, tempData);
838+
}
839+
if (nodeSetting->logAltitude)
840+
{
841+
sprintf(tempData, "%.02f,", nodeDevice->altitude());
842+
strcat(outputData, tempData);
843+
}
844+
}
845+
}
846+
break;
774847
default:
775848
SerialPrintf2("printDeviceValue unknown device type: %s\r\n", getDeviceName(temp->deviceType));
776849
break;
@@ -923,7 +996,7 @@ void printHelperText(bool terminalOnly)
923996
if (nodeSetting->logPressure)
924997
strcat(helperText, "pressure_hPa,");
925998
if (nodeSetting->logTemperature)
926-
strcat(helperText, "pressure_degC,");
999+
strcat(helperText, "temperature_degC,");
9271000
}
9281001
}
9291002
break;
@@ -1133,6 +1206,44 @@ void printHelperText(bool terminalOnly)
11331206
}
11341207
}
11351208
break;
1209+
case DEVICE_VOC_SGP40:
1210+
{
1211+
struct_SGP40 *nodeSetting = (struct_SGP40 *)temp->configPtr;
1212+
if (nodeSetting->log)
1213+
{
1214+
if (nodeSetting->logVOC)
1215+
strcat(helperText, "VOCindex,");
1216+
}
1217+
}
1218+
break;
1219+
case DEVICE_PRESSURE_SDP3X:
1220+
{
1221+
struct_SDP3X *nodeSetting = (struct_SDP3X *)temp->configPtr;
1222+
if (nodeSetting->log)
1223+
{
1224+
if (nodeSetting->logPressure)
1225+
strcat(helperText, "Pa,");
1226+
if (nodeSetting->logTemperature)
1227+
strcat(helperText, "degC,");
1228+
}
1229+
}
1230+
break;
1231+
case DEVICE_PRESSURE_MS5837:
1232+
{
1233+
struct_MS5837 *nodeSetting = (struct_MS5837 *)temp->configPtr;
1234+
if (nodeSetting->log)
1235+
{
1236+
if (nodeSetting->logPressure)
1237+
strcat(helperText, "mbar,");
1238+
if (nodeSetting->logTemperature)
1239+
strcat(helperText, "degC,");
1240+
if (nodeSetting->logDepth)
1241+
strcat(helperText, "depth_m,");
1242+
if (nodeSetting->logAltitude)
1243+
strcat(helperText, "alt_m,");
1244+
}
1245+
}
1246+
break;
11361247
default:
11371248
SerialPrintf2("\nprinterHelperText device not found: %d\r\n", temp->deviceType);
11381249
break;

Firmware/OpenLog_Artemis/autoDetect.ino

Lines changed: 118 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,24 @@ bool addDevice(deviceType_e deviceType, uint8_t address, uint8_t muxAddress, uin
237237
temp->configPtr = new struct_SNGCJA5;
238238
}
239239
break;
240+
case DEVICE_VOC_SGP40:
241+
{
242+
temp->classPtr = new SGP40;
243+
temp->configPtr = new struct_SGP40;
244+
}
245+
break;
246+
case DEVICE_PRESSURE_SDP3X:
247+
{
248+
temp->classPtr = new SDP3X;
249+
temp->configPtr = new struct_SDP3X;
250+
}
251+
break;
252+
case DEVICE_PRESSURE_MS5837:
253+
{
254+
temp->classPtr = new MS5837;
255+
temp->configPtr = new struct_MS5837;
256+
}
257+
break;
240258
default:
241259
SerialPrintf2("addDevice Device type not found: %d\r\n", deviceType);
242260
break;
@@ -469,6 +487,33 @@ bool beginQwiicDevices()
469487
temp->online = true;
470488
}
471489
break;
490+
case DEVICE_VOC_SGP40:
491+
{
492+
SGP40 *tempDevice = (SGP40 *)temp->classPtr;
493+
struct_SGP40 *nodeSetting = (struct_SGP40 *)temp->configPtr; //Create a local pointer that points to same spot as node does
494+
if (nodeSetting->powerOnDelayMillis > qwiicPowerOnDelayMillis) qwiicPowerOnDelayMillis = nodeSetting->powerOnDelayMillis; // Increase qwiicPowerOnDelayMillis if required
495+
if (tempDevice->begin(qwiic) == true) //Wire port. Returns true on success.
496+
temp->online = true;
497+
}
498+
break;
499+
case DEVICE_PRESSURE_SDP3X:
500+
{
501+
SDP3X *tempDevice = (SDP3X *)temp->classPtr;
502+
struct_SDP3X *nodeSetting = (struct_SDP3X *)temp->configPtr; //Create a local pointer that points to same spot as node does
503+
if (nodeSetting->powerOnDelayMillis > qwiicPowerOnDelayMillis) qwiicPowerOnDelayMillis = nodeSetting->powerOnDelayMillis; // Increase qwiicPowerOnDelayMillis if required
504+
if (tempDevice->begin(temp->address, qwiic) == true) //Address, Wire port. Returns true on success.
505+
temp->online = true;
506+
}
507+
break;
508+
case DEVICE_PRESSURE_MS5837:
509+
{
510+
MS5837 *tempDevice = (MS5837 *)temp->classPtr;
511+
struct_MS5837 *nodeSetting = (struct_MS5837 *)temp->configPtr; //Create a local pointer that points to same spot as node does
512+
if (nodeSetting->powerOnDelayMillis > qwiicPowerOnDelayMillis) qwiicPowerOnDelayMillis = nodeSetting->powerOnDelayMillis; // Increase qwiicPowerOnDelayMillis if required
513+
if (tempDevice->begin(qwiic) == true) //Wire port. Returns true on success.
514+
temp->online = true;
515+
}
516+
break;
472517
default:
473518
SerialPrintf2("beginQwiicDevices: device type not found: %d\r\n", temp->deviceType);
474519
break;
@@ -719,6 +764,21 @@ void configureDevice(node * temp)
719764
case DEVICE_PARTICLE_SNGCJA5:
720765
//Nothing to configure
721766
break;
767+
case DEVICE_VOC_SGP40:
768+
//Nothing to configure
769+
break;
770+
case DEVICE_PRESSURE_SDP3X:
771+
//Nothing to configure
772+
break;
773+
case DEVICE_PRESSURE_MS5837:
774+
{
775+
MS5837 *sensor = (MS5837 *)temp->classPtr;
776+
struct_MS5837 *sensorSetting = (struct_MS5837 *)temp->configPtr;
777+
778+
sensor->setModel(sensorSetting->model);
779+
sensor->setFluidDensity(sensorSetting->fluidDensity);
780+
}
781+
break;
722782
default:
723783
SerialPrintf3("configureDevice: Unknown device type %d: %s\r\n", deviceType, getDeviceName((deviceType_e)deviceType));
724784
break;
@@ -809,6 +869,15 @@ FunctionPointer getConfigFunctionPtr(uint8_t nodeNumber)
809869
case DEVICE_PARTICLE_SNGCJA5:
810870
ptr = (FunctionPointer)menuConfigure_SNGCJA5;
811871
break;
872+
case DEVICE_VOC_SGP40:
873+
ptr = (FunctionPointer)menuConfigure_SGP40;
874+
break;
875+
case DEVICE_PRESSURE_SDP3X:
876+
ptr = (FunctionPointer)menuConfigure_SDP3X;
877+
break;
878+
case DEVICE_PRESSURE_MS5837:
879+
ptr = (FunctionPointer)menuConfigure_MS5837;
880+
break;
812881
default:
813882
SerialPrintln(F("getConfigFunctionPtr: Unknown device type"));
814883
SerialFlush();
@@ -938,6 +1007,7 @@ void swap(struct node * a, struct node * b)
9381007
//We no longer use defines in the search table. These are just here for reference.
9391008
#define ADR_VEML6075 0x10
9401009
#define ADR_MPR0025PA1 0x18
1010+
#define ADR_SDP3X 0x21 //Alternates: 0x22, 0x23
9411011
#define ADR_NAU7802 0x2A
9421012
#define ADR_VL53L1X 0x29
9431013
#define ADR_SNGCJA5 0x33
@@ -947,6 +1017,7 @@ void swap(struct node * a, struct node * b)
9471017
#define ADR_ADS122C04 0x45 //Alternates: 0x44, 0x41 and 0x40
9481018
#define ADR_TMP117 0x48 //Alternates: 0x49, 0x4A, and 0x4B
9491019
#define ADR_SGP30 0x58
1020+
#define ADR_SGP40 0x59
9501021
#define ADR_CCS811 0x5B //Alternates: 0x5A
9511022
#define ADR_LPS25HB 0x5D //Alternates: 0x5C
9521023
#define ADR_VCNL4040 0x60
@@ -955,6 +1026,7 @@ void swap(struct node * a, struct node * b)
9551026
#define ADR_MULTIPLEXER 0x70 //0x70 to 0x77
9561027
#define ADR_SHTC3 0x70
9571028
#define ADR_MS5637 0x76
1029+
#define ADR_MS5837 0x76
9581030
//#define ADR_MS8607 0x76 //Pressure portion of the MS8607 sensor. We'll catch the 0x40 first
9591031
#define ADR_BME280 0x77 //Alternates: 0x76
9601032

@@ -981,6 +1053,30 @@ deviceType_e testDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portNumb
9811053
return (DEVICE_PRESSURE_MPR0025PA1);
9821054
}
9831055
break;
1056+
case 0x21:
1057+
{
1058+
//Confidence: Medium - .begin reads the product ID
1059+
SDP3X sensor;
1060+
if (sensor.begin(i2cAddress, qwiic) == true) //Address, Wire port
1061+
return (DEVICE_PRESSURE_SDP3X);
1062+
}
1063+
break;
1064+
case 0x22:
1065+
{
1066+
//Confidence: Medium - .begin reads the product ID
1067+
SDP3X sensor;
1068+
if (sensor.begin(i2cAddress, qwiic) == true) //Address, Wire port
1069+
return (DEVICE_PRESSURE_SDP3X);
1070+
}
1071+
break;
1072+
case 0x23:
1073+
{
1074+
//Confidence: Medium - .begin reads the product ID
1075+
SDP3X sensor;
1076+
if (sensor.begin(i2cAddress, qwiic) == true) //Address, Wire port
1077+
return (DEVICE_PRESSURE_SDP3X);
1078+
}
1079+
break;
9841080
case 0x2A:
9851081
{
9861082
//Confidence: High - Checks 8 bit revision code (0x0F)
@@ -1098,6 +1194,13 @@ deviceType_e testDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portNumb
10981194
return (DEVICE_VOC_SGP30);
10991195
}
11001196
break;
1197+
case 0x59:
1198+
{
1199+
SGP40 sensor;
1200+
if (sensor.begin(qwiic) == true) //Wire port
1201+
return (DEVICE_VOC_SGP40);
1202+
}
1203+
break;
11011204
case 0x5A:
11021205
case 0x5B:
11031206
{
@@ -1244,7 +1347,12 @@ deviceType_e testDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portNumb
12441347
//Ignore devices we've already recorded. This was causing the mux to get tested, a begin() would happen, and the mux would be reset.
12451348
if (deviceExists(DEVICE_MULTIPLEXER, i2cAddress, muxAddress, portNumber) == true) return (DEVICE_MULTIPLEXER);
12461349

1247-
//Confidence: High - does CRC on internal EEPROM read
1350+
//Confidence: High - does CRC on internal EEPROM read and checks sensor version
1351+
MS5837 sensor2;
1352+
if (sensor2.begin(qwiic) == true) //Wire port
1353+
return (DEVICE_PRESSURE_MS5837);
1354+
1355+
//Confidence: High - does CRC on internal EEPROM read - but do this second as a MS5837 will appear as a MS5637
12481356
MS5637 sensor;
12491357
if (sensor.begin(qwiic) == true) //Wire port
12501358
return (DEVICE_PRESSURE_MS5637);
@@ -1493,6 +1601,15 @@ const char* getDeviceName(deviceType_e deviceNumber)
14931601
case DEVICE_PARTICLE_SNGCJA5:
14941602
return "Particle-SNGCJA5";
14951603
break;
1604+
case DEVICE_VOC_SGP40:
1605+
return "VOC-SGP40";
1606+
break;
1607+
case DEVICE_PRESSURE_SDP3X:
1608+
return "Pressure-SDP3X";
1609+
break;
1610+
case DEVICE_PRESSURE_MS5837:
1611+
return "Pressure-MS5837";
1612+
break;
14961613

14971614
case DEVICE_UNKNOWN_DEVICE:
14981615
return "Unknown device";

0 commit comments

Comments
 (0)