Note: Steps 5-8 are only for verification purposes, you can skip them
-
Open /boot/config.txt file
sudo nano /boot/config.txt
-
Find the line containing
dtparam=i2c_arm=on
-
Add
i2c_arm_baudrate=<new speed>
(Separate with a Comma)dtparam=i2c_arm=on,i2c_arm_baudrate=400000
-
Reboot Raspberry Pi
-
Create a simple test script to verify the speed
- Switch to home directory
cd ~
- Create shell script
nano i2cspeed.sh
- Copy and paste the following lines of code
#!/bin/bash
var="$(xxd /sys/class/i2c-adapter/i2c-1/of_node/clock-frequency | awk -F': ' '{print $2}')"
var=${var//[[:blank:].\}]/}
printf "%d\n" 0x$var
- Change file permissions
chmod +x i2cspeed.sh
- Execute test script
./i2cspeed.sh
- Verify that the value is the correct setting
pi@rpi-dev:~ $ ./i2cspeed.sh
400000
Source: Raspberry Pi Forums
It will be better, if the file 'i2cspeed.sh' is changed to the followings,