Lower i2C clock speed for BME680 & MCP9808 sensors

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
puterguy
 
Posts: 3
Joined: Thu Sep 02, 2010 12:29 pm

Lower i2C clock speed for BME680 & MCP9808 sensors

Post by puterguy »

I am using an esp32 with BME680 and MCP9808 sensors to read temperature/humidity etc using the ArduinoIDE and "Adafruit_BME680.h" and "Adafruit_MCP9808.h" libraries, respectively. I am using the default SCL/SDA i2C pins for the esp32.

This all works so long as the wire length between the sensor and the esp32 is less than ~2m where I am using simple 22-guage 4-wire alarm cable.

To successfully extend the cable length, I would like to lower the i2c bus speed from the default ~100kHz.

I tried adding the following to my setup() block:

Code: Select all

Wire.begin();
Wire.setClock(25000L);
This code is prior to the following simplified code snippet that I use to initialize the sensors

Code: Select all

// BME680 - Temperature, Humidity, Atmospheric Pressure, Gas
#define BME680_ADDR 0x77 // Ox77 (default or if SDO hi), 0x76 if SDO grounded)
Adafruit_BME680 bme680; // I2C

int bme680_setup() {
  if (!bme680.begin(BME680_ADDR)) return -1; //BME680 sensor not found
}

// MCP9808 - Temperature
#define MCP9808_ADDR 0x18 //Default (valid numbers are 0x18 - 0x1f)
Adafruit_MCP9808 mcp9808;

int mcp9808_setup() {
  if (!mcp9808.begin(MCP9808_ADDR)) return -1; //MCP9808 sensor not found
}
My understanding is that the Adafruit BME680 and MCP9808 libraries use Wire.h and reference the default object 'Wire" so I would think that initializing "Wire" and setting its clock speed in the setup() stanza before I initialize the bme680 or mcp9808 code should work [Are my assumptions correct here??]

I am able to confirm that the clock is set properly in the *software* by using a line like the following to print the i2c clock speed.

Code: Select all

Stream.printf("i2C Clock: %d\n", Wire.getClock())
However, when I look on my oscilloscope the *hardware* clock pulses are unchanged and still about 10uSec in duration (corresponding to the default ~100kHz).

What do I need to do in order to successfully change the actual *hardware* i2c clock speed on the esp32 using the Adafruit libraries for the Arduino IDE.

Thanks!

User avatar
puterguy
 
Posts: 3
Joined: Thu Sep 02, 2010 12:29 pm

Re: Lower i2C clock speed for BME680 & MCP9808 sensors

Post by puterguy »

I get the same non-responsive behavior to setting the clock frequency when I just do a simple transmission.

Code: Select all

  Wire.begin();
  Wire.setClock(25000);
  Wire.beginTransmission(0x77);
  Wire.endTransmission();
Or

Code: Select all

  Wire.begin(21, 22, 25000);
  Wire.beginTransmission(0x77);
  Wire.endTransmission();
i.e. I still get clock pulses of length ~10us corresponding to a frequency of 100kHz independent of what I set the clock to.

And I definitely have the pins right since I don't get any transmission if I use other port numbers for SDA/SCL in the second version.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”