In order to use certain I2C sensors, such as the BNO055 and the CCS811, you'll need to enable I2C clock stretching 'support' by greatly slowing down the I2C clock on the Raspberry Pi using the device tree overlay.

This is done by adding a line in /boot/config.txt.  Log in to a terminal on your Pi and open that file in Nano, or your text editor of choice:

Download: file
sudo nano /boot/config.txt

Scroll down until you find a block like:

Download: file
# Uncomment some of all of these to enable the optional hardware interfaces

This block might vary depending on what you've enabled in raspi-config. Directly below it, add the following:

Download: file
# Clock stretching by slowing down to 10KHz

The default baudrate may be 100KHz or 1MHz, by slowing it down to 10KHz or more, you may be able to be slow enough to avoid missing clocks.

In Nano, your screen should look like this:

Next, save the file and exit (in Nano, press Ctrl-Xy for yes, and Enter).

Now you can reboot your Pi and proceed to testing your I2C device:

Download: file
sudo reboot

If you still get bad data, try slowing it down more, maybe to 5 KHz or 1 KHz rate. Reboot after each change

This guide was first published on Jun 30, 2018. It was last updated on Jun 30, 2018.
This page (I2C Clock Stretching) was last updated on Oct 20, 2020.