Skip to content

Commit 2701a62

Browse files
committed
Add MS8607 support
1 parent 8ffeec2 commit 2701a62

File tree

5 files changed

+340
-4
lines changed

5 files changed

+340
-4
lines changed

Firmware/OpenLog_Artemis/OpenLog_Artemis.ino

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ enum returnStatus {
3333

3434
//Setup Qwiic Port
3535
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
36-
#include "Wire.h"
36+
#include <Wire.h>
3737
TwoWire qwiic(1); //Will use pads 8/9
3838
const byte PIN_QWIIC_POWER = 18;
3939
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
@@ -138,6 +138,9 @@ SGP30 vocSensor_SGP30;
138138
#include "SparkFun_SCD30_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_SCD30
139139
SCD30 co2Sensor_SCD30;
140140

141+
#include "MS8607_Library.h" //Click here to get the library: http://librarymanager/All#Qwiic_MS8607
142+
MS8607 pressureSensor_MS8607;
143+
141144
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
142145

143146
//Global variables

Firmware/OpenLog_Artemis/Sensors.ino

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,26 @@ bool beginSensors()
207207
else
208208
beginSensorOutput += "SCD30 failed to respond. Check wiring.\n";
209209
}
210+
211+
if (qwiicAvailable.MS8607 && settings.sensor_MS8607.log && !qwiicOnline.MS8607)
212+
{
213+
if (pressureSensor_MS8607.begin(qwiic) == true) //Wire port. This checks both 0x40 and 0x76 sensor addresses
214+
{
215+
if(settings.sensor_MS8607.enableHeater == true)
216+
pressureSensor_MS8607.enable_heater();
217+
else
218+
pressureSensor_MS8607.disable_heater();
219+
220+
pressureSensor_MS8607.set_pressure_resolution(settings.sensor_MS8607.pressureResolution);
221+
pressureSensor_MS8607.set_humidity_resolution(settings.sensor_MS8607.humidityResolution);
222+
223+
qwiicOnline.MS8607 = true;
224+
beginSensorOutput += "MS8607 Online\n";
225+
}
226+
else
227+
beginSensorOutput += "MS8607 failed to respond. Check wiring.\n";
228+
}
229+
210230
return true;
211231
}
212232

@@ -642,6 +662,25 @@ void getData()
642662
}
643663
}
644664

665+
if (qwiicOnline.MS8607 && settings.sensor_MS8607.log)
666+
{
667+
if (settings.sensor_MS8607.logPressure)
668+
{
669+
outputData += (String)pressureSensor_MS8607.getPressure() + ",";
670+
helperText += "hPa,";
671+
}
672+
if (settings.sensor_MS8607.logHumidity)
673+
{
674+
outputData += (String)pressureSensor_MS8607.getHumidity() + ",";
675+
helperText += "humidity_%,";
676+
}
677+
if (settings.sensor_MS8607.logPressure)
678+
{
679+
outputData += (String)pressureSensor_MS8607.getTemperature() + ",";
680+
helperText += "degC,";
681+
}
682+
}
683+
645684
if (settings.logHertz)
646685
{
647686
//Calculate the actual update rate based on the sketch start time and the

Firmware/OpenLog_Artemis/menuAttachedDevices.ino

Lines changed: 143 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ void menuAttachedDevices()
103103
functionPointers[availableDevices - 1] = menuConfigure_SCD30;
104104
Serial.printf("%d) SCD30 CO2 Sensor\n", availableDevices++);
105105
}
106+
if (qwiicAvailable.MS8607)
107+
{
108+
functionPointers[availableDevices - 1] = menuConfigure_MS8607;
109+
Serial.printf("%d) MS8607 Pressure Humidity Temperature Sensor\n", availableDevices++);
110+
}
106111

107112
Serial.println("x) Exit");
108113

@@ -155,6 +160,7 @@ bool detectQwiicDevices()
155160
#define ADR_VEML6075 0x10
156161
#define ADR_NAU7802 0x2A
157162
#define ADR_VL53L1X 0x29
163+
#define ADR_MS8607 0x40 //Humidity portion of the MS8607 sensor
158164
#define ADR_UBLOX 0x42
159165
#define ADR_TMP117 0x48 //Alternates: 0x49, 0x4A, and 0x4B
160166
#define ADR_SGP30 0x58
@@ -167,6 +173,7 @@ bool detectQwiicDevices()
167173
#define ADR_MCP9600_1 0x66
168174
#define ADR_BME280_2 0x76
169175
#define ADR_MS5637 0x76
176+
//#define ADR_MS8607 0x76 //Pressure portion of the MS8607 sensor. We'll catch the 0x40 first
170177
#define ADR_BME280_1 0x77
171178

172179
//Given an address, see if it repsonds as we would expect
@@ -230,13 +237,23 @@ bool testDevice(uint8_t i2cAddress)
230237
qwiicAvailable.VEML6075 = true;
231238
break;
232239
case ADR_MS5637:
233-
if (pressureSensor_MS5637.begin(qwiic) == true) //Wire port
234-
qwiicAvailable.MS5637 = true;
235-
break;
240+
{
241+
//By the time we hit this address, MS8607 should have already been started by its first address
242+
if (qwiicAvailable.MS8607 == false)
243+
{
244+
if (pressureSensor_MS5637.begin(qwiic) == true) //Wire port
245+
qwiicAvailable.MS5637 = true;
246+
}
247+
break;
248+
}
236249
case ADR_SCD30:
237250
if (co2Sensor_SCD30.begin(qwiic) == true) //Wire port
238251
qwiicAvailable.SCD30 = true;
239252
break;
253+
case ADR_MS8607:
254+
if (pressureSensor_MS8607.begin(qwiic) == true) //Wire port. Tests for both 0x40 and 0x76 I2C addresses.
255+
qwiicAvailable.MS8607 = true;
256+
break;
240257
default:
241258
Serial.printf("Unknown device at address 0x%02X\n", i2cAddress);
242259
return false;
@@ -1193,3 +1210,126 @@ void menuConfigure_SCD30()
11931210

11941211
qwiicOnline.SCD30 = false; //Mark as offline so it will be started with new settings
11951212
}
1213+
1214+
void menuConfigure_MS8607()
1215+
{
1216+
while (1)
1217+
{
1218+
Serial.println();
1219+
Serial.println("Menu: Configure MS8607 Pressure Humidity Temperature (PHT) Sensor");
1220+
1221+
Serial.print("1) Sensor Logging: ");
1222+
if (settings.sensor_MS8607.log == true) Serial.println("Enabled");
1223+
else Serial.println("Disabled");
1224+
1225+
if (settings.sensor_MS8607.log == true)
1226+
{
1227+
Serial.print("2) Log Pressure: ");
1228+
if (settings.sensor_MS8607.logPressure == true) Serial.println("Enabled");
1229+
else Serial.println("Disabled");
1230+
1231+
Serial.print("3) Log Humidity: ");
1232+
if (settings.sensor_MS8607.logHumidity == true) Serial.println("Enabled");
1233+
else Serial.println("Disabled");
1234+
1235+
Serial.print("4) Log Temperature: ");
1236+
if (settings.sensor_MS8607.logTemperature == true) Serial.println("Enabled");
1237+
else Serial.println("Disabled");
1238+
1239+
Serial.print("5) Heater: ");
1240+
if (settings.sensor_MS8607.enableHeater == true) Serial.println("Enabled");
1241+
else Serial.println("Disabled");
1242+
1243+
Serial.print("6) Set Pressure Resolution: ");
1244+
if (settings.sensor_MS8607.pressureResolution == MS8607_pressure_resolution_osr_256)
1245+
Serial.print("0.11");
1246+
else if (settings.sensor_MS8607.pressureResolution == MS8607_pressure_resolution_osr_512)
1247+
Serial.print("0.062");
1248+
else if (settings.sensor_MS8607.pressureResolution == MS8607_pressure_resolution_osr_1024)
1249+
Serial.print("0.039");
1250+
else if (settings.sensor_MS8607.pressureResolution == MS8607_pressure_resolution_osr_2048)
1251+
Serial.print("0.028");
1252+
else if (settings.sensor_MS8607.pressureResolution == MS8607_pressure_resolution_osr_4096)
1253+
Serial.print("0.021");
1254+
else if (settings.sensor_MS8607.pressureResolution == MS8607_pressure_resolution_osr_8192)
1255+
Serial.print("0.016");
1256+
Serial.println(" mbar");
1257+
1258+
Serial.print("7) Set Humidity Resolution: ");
1259+
if (settings.sensor_MS8607.humidityResolution == MS8607_humidity_resolution_8b)
1260+
Serial.print("8");
1261+
else if (settings.sensor_MS8607.humidityResolution == MS8607_humidity_resolution_10b)
1262+
Serial.print("10");
1263+
else if (settings.sensor_MS8607.humidityResolution == MS8607_humidity_resolution_11b)
1264+
Serial.print("11");
1265+
else if (settings.sensor_MS8607.humidityResolution == MS8607_humidity_resolution_12b)
1266+
Serial.print("12");
1267+
Serial.println(" bits");
1268+
}
1269+
Serial.println("x) Exit");
1270+
1271+
byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds
1272+
1273+
if (incoming == '1')
1274+
settings.sensor_MS8607.log ^= 1;
1275+
else if (settings.sensor_MS8607.log == true)
1276+
{
1277+
if (incoming == '2')
1278+
settings.sensor_MS8607.logPressure ^= 1;
1279+
else if (incoming == '3')
1280+
settings.sensor_MS8607.logHumidity ^= 1;
1281+
else if (incoming == '4')
1282+
settings.sensor_MS8607.logTemperature ^= 1;
1283+
else if (incoming == '5')
1284+
settings.sensor_MS8607.enableHeater ^= 1;
1285+
else if (incoming == '6')
1286+
{
1287+
Serial.println("Set Pressure Resolution:");
1288+
Serial.println("1) 0.11 mbar");
1289+
Serial.println("2) 0.062 mbar");
1290+
Serial.println("3) 0.039 mbar");
1291+
Serial.println("4) 0.028 mbar");
1292+
Serial.println("5) 0.021 mbar");
1293+
Serial.println("6) 0.016 mbar");
1294+
int amt = getNumber(menuTimeout); //x second timeout
1295+
if (amt >= 1 && amt <= 6)
1296+
settings.sensor_MS8607.pressureResolution = (MS8607_pressure_resolution)(amt - 1);
1297+
else
1298+
Serial.println("Error: Out of range");
1299+
}
1300+
else if (incoming == '7')
1301+
{
1302+
Serial.println("Set Humidity Resolution:");
1303+
Serial.println("1) 8 bit");
1304+
Serial.println("2) 10 bit");
1305+
Serial.println("3) 11 bit");
1306+
Serial.println("4) 12 bit");
1307+
int amt = getNumber(menuTimeout); //x second timeout
1308+
if (amt >= 1 && amt <= 4)
1309+
{
1310+
//Unfortunately these enums aren't sequential so we have to lookup
1311+
if (amt == 1) settings.sensor_MS8607.humidityResolution = MS8607_humidity_resolution_8b;
1312+
if (amt == 2) settings.sensor_MS8607.humidityResolution = MS8607_humidity_resolution_10b;
1313+
if (amt == 3) settings.sensor_MS8607.humidityResolution = MS8607_humidity_resolution_11b;
1314+
if (amt == 4) settings.sensor_MS8607.humidityResolution = MS8607_humidity_resolution_12b;
1315+
}
1316+
else
1317+
Serial.println("Error: Out of range");
1318+
}
1319+
else if (incoming == 'x')
1320+
break;
1321+
else if (incoming == STATUS_GETBYTE_TIMEOUT)
1322+
break;
1323+
else
1324+
printUnknown(incoming);
1325+
}
1326+
else if (incoming == 'x')
1327+
break;
1328+
else if (incoming == STATUS_GETBYTE_TIMEOUT)
1329+
break;
1330+
else
1331+
printUnknown(incoming);
1332+
}
1333+
1334+
qwiicOnline.MS8607 = false; //Mark as offline so it will be started with new settings
1335+
}

Firmware/OpenLog_Artemis/settings.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "MS8607_Library.h" //Click here to get the library: http://librarymanager/All#Qwiic_MS8607
2+
13
//Add the new sensor settings below
24
struct struct_LPS25HB {
35
bool log = true;
@@ -115,6 +117,17 @@ struct struct_SCD30 {
115117
int temperatureOffset = 0; //C - Be careful not to overwrite the value on the sensor
116118
};
117119

120+
121+
struct struct_MS8607 {
122+
bool log = true;
123+
bool logHumidity = true;
124+
bool logPressure = true;
125+
bool logTemperature = true;
126+
bool enableHeater = false; // The TE examples say that get_compensated_humidity and get_dew_point will only work if the heater is OFF
127+
MS8607_pressure_resolution pressureResolution = MS8607_pressure_resolution_osr_8192; //17ms per reading, 0.016mbar resolution
128+
MS8607_humidity_resolution humidityResolution = MS8607_humidity_resolution_12b; //12-bit
129+
};
130+
118131
//This is all the settings that can be set on OpenLog. It's recorded to NVM and the config file.
119132
struct struct_settings {
120133
int sizeOfSettings = 0;
@@ -169,6 +182,7 @@ struct struct_settings {
169182
struct_VEML6075 sensor_VEML6075;
170183
struct_MS5637 sensor_MS5637;
171184
struct_SCD30 sensor_SCD30;
185+
struct_MS8607 sensor_MS8607;
172186
} settings;
173187

174188
//These are the devices on board OpenLog that may be on or offline.
@@ -195,6 +209,7 @@ struct struct_QwiicSensors {
195209
bool VEML6075;
196210
bool MS5637;
197211
bool SCD30;
212+
bool MS8607;
198213
};
199214

200215
struct_QwiicSensors qwiicAvailable = {
@@ -212,6 +227,7 @@ struct_QwiicSensors qwiicAvailable = {
212227
.VEML6075 = false,
213228
.MS5637 = false,
214229
.SCD30 = false,
230+
.MS8607 = false,
215231
};
216232

217233
struct_QwiicSensors qwiicOnline = {
@@ -229,4 +245,5 @@ struct_QwiicSensors qwiicOnline = {
229245
.VEML6075 = false,
230246
.MS5637 = false,
231247
.SCD30 = false,
248+
.MS8607 = false,
232249
};

0 commit comments

Comments
 (0)