Changing the default I2C bus speed on the Raspberry Pi can help improve the performance of some projects. This is particularly important when using the I2C interface to control a display module. In the newer versions of Raspbian this change must be made using a Device Tree parameter.
The bus speed is sometimes referred to as “baudrate” although the two aren’t actually the same thing.
Step 1 – Enable the I2C Interface
Before the interface baudrate can be changed the I2C interface must be enabled. This can be done using “raspi-config” on the command line or “Raspberry Pi Configuration” on the Raspbian desktop.
For step-by-step instructions on how to do this please take a look at the Enable I2C Interface on the Raspberry Pi post.
Step 2 – Edit Config.txt File to set I2C Bus Speed
Using the following command the config.txt file can be edited :
sudo nano /boot/config.txt
Find the line containing “dtparam=i2c_arm=on”.
Add “,i2c_arm_baudrate=400000” where 400000 is the new speed (400 Kbit/s). Note the comma.
This should give you a line looking like :
This enables the bus and sets the baudrate at the same time with a comma separating both parameters.
Use CTRL-X, then Y, then RETURN to save the file and exit.
Step 3 – Reboot
Finally, reboot the Pi for the new setting to take effect :
I2C Baudrate Values
The BCM2835 ARM Peripherals specification (page 28) says that the Pi has a “fast-mode” (400Kb/s) driver. For this reason I would recommend using 100000 or 400000 as baudrate values. The default is usually set to 100000.
I successfully used 400000 with an OLED display module to increase the rate at which images could be updated.
Finally, for a list of I2C related articles click here.
More information about the I2C protocol can be found on Wikipedia.