Skip to content

Commit d51a4ba

Browse files
committed
Add BME280 test to correct issue #109
1 parent 5c10915 commit d51a4ba

File tree

3 files changed

+62
-8
lines changed

3 files changed

+62
-8
lines changed

Firmware/OpenLog_Artemis/OpenLog_Artemis.ino

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,13 @@
107107
The work-around is to use Serial1 in place of serialLog and then to manually force UART1 to use pins 12 and 13
108108
We need a work-around anyway because if pins 12 or 13 have been used as analog inputs, Serial1.begin does not re-configure them for UART TX and RX
109109
(in progress) Reduce sleep current as much as possible. v1.2.1 achieved ~110uA. With v2.1.0 the draw is more like 260uA...
110+
111+
(in progress) Update to Apollo3 v2.2.0 - FIRMWARE_VERSION_MAJOR = 2; FIRMWARE_VERSION_MINOR = 1.
112+
(done) Add a fix for issue #109 - check if a BME280 is connected before calling multiplexerBegin: https://github.com/sparkfun/OpenLog_Artemis/issues/109
110113
*/
111114

112115
const int FIRMWARE_VERSION_MAJOR = 2;
113-
const int FIRMWARE_VERSION_MINOR = 0;
116+
const int FIRMWARE_VERSION_MINOR = 1;
114117

115118
//Define the OLA board identifier:
116119
// This is an int which is unique to this variant of the OLA and which allows us
@@ -120,7 +123,7 @@ const int FIRMWARE_VERSION_MINOR = 0;
120123
// the variant * 0x100 (OLA = 1; GNSS_LOGGER = 2; GEOPHONE_LOGGER = 3)
121124
// the major firmware version * 0x10
122125
// the minor firmware version
123-
#define OLA_IDENTIFIER 0x120 // Stored as 288 decimal in OLA_settings.txt
126+
#define OLA_IDENTIFIER 0x121 // Stored as 289 decimal in OLA_settings.txt
124127

125128
#include "settings.h"
126129

Firmware/OpenLog_Artemis/autoDetect.ino

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,11 +1502,27 @@ deviceType_e testDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portNumb
15021502
//Given an address, returns the device type if it responds as we would expect
15031503
//This version is dedicated to testing muxes and uses a custom .begin to avoid the slippery mux problem
15041504
//However, we also need to check if an MS8607 is attached (address 0x76) as it can cause the I2C bus to lock up if not detected correctly
1505+
//Also check for a BME280 - to prevent multiplexerBegin from confusing it
15051506
deviceType_e testMuxDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portNumber)
15061507
{
15071508
switch (i2cAddress)
15081509
{
15091510
case 0x70:
1511+
{
1512+
//Ignore devices we've already recorded. This was causing the mux to get tested, a begin() would happen, and the mux would be reset.
1513+
if (deviceExists(DEVICE_MULTIPLEXER, i2cAddress, muxAddress, portNumber) == true) return (DEVICE_MULTIPLEXER);
1514+
1515+
//I don't think multiplexerBegin will cause any badness for the SHTC3 as its commands are all 16-bit
1516+
//But, just in case, let's see if one is connected
1517+
SHTC3 sensor;
1518+
if (sensor.begin(qwiic) == 0) //Wire port. Device returns 0 upon success.
1519+
return (DEVICE_HUMIDITY_SHTC3);
1520+
1521+
//Confidence: Medium - Write/Read/Clear to 0x00
1522+
if (multiplexerBegin(i2cAddress, qwiic) == true) //Address, Wire port
1523+
return (DEVICE_MULTIPLEXER);
1524+
}
1525+
break;
15101526
case 0x71:
15111527
case 0x72:
15121528
case 0x73:
@@ -1532,9 +1548,7 @@ deviceType_e testMuxDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portN
15321548
// So, we can't use .begin as the test for a MS5637 / MS5837 / MS8607. We need to be more creative!
15331549
// If we write 0xA0 to i2cAddress and then read two bytes:
15341550
// A mux will return 0xA0A0
1535-
// An MS5637 / MS5837 / MS8607 will return the value stored in its eeprom which _hopefully_ is not 0xA0A0!
1536-
1537-
// Let's hope this doesn't cause problems for the BME280...! We should be OK as the default address for the BME280 is 0x77.
1551+
// An MS5637 / MS5837 / MS8607 / BME280 will return an eeprom or register value which _hopefully_ is not 0xA0A0!
15381552

15391553
qwiic.beginTransmission((uint8_t)i2cAddress);
15401554
qwiic.write((uint8_t)0xA0);
@@ -1543,12 +1557,12 @@ deviceType_e testMuxDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portN
15431557
if (i2c_status == 0) // If the I2C write was successful
15441558
{
15451559
qwiic.requestFrom((uint8_t)i2cAddress, 2U); // Read two bytes
1546-
uint8_t buffer[2];
1560+
uint8_t buffer[2] = { 0, 0 };
15471561
for (uint8_t i = 0; i < 2; i++)
15481562
{
15491563
buffer[i] = qwiic.read();
15501564
}
1551-
if ((buffer[0] != 0xA0) || (buffer[1] != 0xA0)) // If we read back something other than 0xA0A0 then we are probably talking to an MS5637 / MS5837 / MS8607, not a mux
1565+
if ((buffer[0] != 0xA0) || (buffer[1] != 0xA0)) // If we read back something other than 0xA0A0 then we are probably talking to an MS5637 / MS5837 / MS8607 / BME280, not a mux
15521566
{
15531567
return (DEVICE_PRESSURE_MS5637);
15541568
}
@@ -1564,6 +1578,29 @@ deviceType_e testMuxDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portN
15641578
//Ignore devices we've already recorded. This was causing the mux to get tested, a begin() would happen, and the mux would be reset.
15651579
if (deviceExists(DEVICE_MULTIPLEXER, i2cAddress, muxAddress, portNumber) == true) return (DEVICE_MULTIPLEXER);
15661580

1581+
//multiplexerBegin confuses the BME280, so let's check if one is connected first
1582+
// If we write 0xA0 to i2cAddress and then read two bytes:
1583+
// A mux will return 0xA0A0
1584+
// A BME280 will return a register value which _hopefully_ is not 0xA0A0!
1585+
1586+
qwiic.beginTransmission((uint8_t)i2cAddress);
1587+
qwiic.write((uint8_t)0xA0);
1588+
uint8_t i2c_status = qwiic.endTransmission();
1589+
1590+
if (i2c_status == 0) // If the I2C write was successful
1591+
{
1592+
qwiic.requestFrom((uint8_t)i2cAddress, 2U); // Read two bytes
1593+
uint8_t buffer[2] = { 0, 0 };
1594+
for (uint8_t i = 0; i < 2; i++)
1595+
{
1596+
buffer[i] = qwiic.read();
1597+
}
1598+
if ((buffer[0] != 0xA0) || (buffer[1] != 0xA0)) // If we read back something other than 0xA0A0 then we are probably talking to a BME280, not a mux
1599+
{
1600+
return (DEVICE_PHT_BME280);
1601+
}
1602+
}
1603+
15671604
//Confidence: Medium - Write/Read/Clear to 0x00
15681605
if (multiplexerBegin(i2cAddress, qwiic) == true) //Address, Wire port
15691606
return (DEVICE_MULTIPLEXER);

Firmware/OpenLog_Artemis/menuAttachedDevices.ino

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,21 @@ bool detectQwiicDevices()
8282
{
8383
if (settings.printDebugMessages == true)
8484
{
85-
SerialPrintf2("detectQwiicDevices: MS8607/MS5637/MS5837 found at address 0x%02X. Ignoring it for now...\r\n", address);
85+
SerialPrintf2("detectQwiicDevices: MS8607/MS5637/MS5837/BME280 found at address 0x%02X. Ignoring it for now...\r\n", address);
86+
}
87+
}
88+
else if (foundType == DEVICE_PHT_BME280)
89+
{
90+
if (settings.printDebugMessages == true)
91+
{
92+
SerialPrintf2("detectQwiicDevices: BME280 found at address 0x%02X. Ignoring it for now...\r\n", address);
93+
}
94+
}
95+
else if (foundType == DEVICE_HUMIDITY_SHTC3)
96+
{
97+
if (settings.printDebugMessages == true)
98+
{
99+
SerialPrintf2("detectQwiicDevices: SHTC3 found at address 0x%02X. Ignoring it for now...\r\n", address);
86100
}
87101
}
88102
}

0 commit comments

Comments
 (0)