Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/SparkFun_SCD30_Arduino_Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,23 @@ boolean SCD30::begin(TwoWire &wirePort)
//We expect caller to begin their I2C port, with the speed of their choice external to the library
//But if they forget, we start the hardware here.
_i2cPort->begin();

/* Especially during obtaining the ACK BIT after a byte sent the SCD30 is using clock stretching (but NOT only there)!
* The need for clock stretching is described in the Sensirion_CO2_Sensors_SCD30_Interface_Description.pdf
*
* The default clock stretch (maximum wait time) on the ESP8266-library (2.4.2) is 230us which is set during _i2cPort->begin();
* In the current implementation of the ESP8266 I2C driver there is NO error message when this time expired, while
* the clock stretch is still happening, causing uncontrolled behaviour of the hardware combination.
*
* To set ClockStretchlimit() a check for ESP8266 boards has been added in the driver.
*
* With setting to 20000, we set a max timeout of 20mS (> 20x the maximum measured) basically disabling the time-out
* and now wait for clock stretch to be controlled by the client.
*/

#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
_i2cPort->setClockStretchLimit(200000);
#endif

//Check for device to respond correctly
if(beginMeasuring() == true) //Start continuous measurements
Expand Down