# Quadcopter program execution time optimization using Raspberry Pi by increasing i2c baudrate

Is it possible to speed up execution time of a c++ program in raspberry pi solely by increasing the i2c baudrate and increasing the sampling frequency of the sensors?

I have the issue of sudden jerkiness of my quadcopter and found the culprit which is the frequency at which my loop excecutes which is only about 14Hz. The minimum requirement for a quadcopter is 100-200hz. It is similar to the issue he faces here Raspberry Pi quadcopter thrashes at high speeds

He said that he was able to increase his sampling rate from 66hz to 200hz by increasing the i2c baudrate. I am confused on how that is done.

In the wiring pi library, it says that we can set the baudrate using this command:

gpio load i2c 1000

will set the baud rate to 1000Kbps – ie. 1,000,000 bps. (K here is times 1000)


What I am curious about is how to set this baudrate to achieve my desired sampling rate?

I plan on optimizing it further to achieve at least a 100Hz sampling rate

As of now, the execution time of each loop in my quadcopter program is at 0.07ms or 14Hz.

It takes 0.01ms to 0.02ms to obtain data from the complementary filter.

I have already adjusted the registers of my sensors to output readings at 190Hz (Gyroscope L3GD20H) and 200Hz (Accelerometer LSM303) and 220Hz (Magnetometer LSM303).

• By increasing the i2c baudrate of the Raspberry Pi I was able to reach 0.007s to 0.019s of loop execution time or 50Hz to 150Hz. – user123456098 Jan 18 '16 at 1:10
• I am now able to get 250Hz consistently :) – user123456098 Jan 18 '16 at 7:26