Adafruit Industries, Essential service and business: NYC – Executive Order 202.6 - Read more. Accepting essential orders - here's how.

BeagleBone: Speed of I2C bus
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

BeagleBone: Speed of I2C bus

by vex73 on Thu Dec 18, 2014 12:57 pm


I just got some sensors that I interfaced with my BB (LPS331AP, L3GD20H, LSM303D) using I2C. It works fine reading data, but I am still stuck facing a problem:

The I2C reading seems really slow (20ms between each using a loop), and I don't think it is because of the sensors. I am using I2C #1, 100kHz

Here below is the code (Python):

Code: Select all | TOGGLE FULL SIZE
import commands
import datetime

 # Compass LSM303D (accelerometer and magnetometer)
print "Client started ..."

print "i2cdetect -r -y 1"
print commands.getoutput("i2cdetect -r -y 1")
print "Attempt to connect to the Compass..."
x = commands.getoutput("i2cget -y 1 0x1D 0x0F b")
if x == '0x49':
    print "Beagle Bone is connected with the Compass"
    print "Cannot connect to the Compass"
commands.getoutput("i2cset -y 1 0x1D 0x21 0x00 b") #CTRL2
# magnetic sensor into continuous mode from sleep mode
commands.getoutput("i2cset -y 1 0x1D 0x20 0x57 b") #CTRL1 0x57
# ctrl5 parameter
commands.getoutput("i2cset -y 1 0x1D 0x24 0x64") #CTRL5
commands.getoutput("i2cset -y 1 0x1D 0x25 0x20") #CTRL6
commands.getoutput("i2cset -y 1 0x1D 0x26 0x00") #CTRL7
while True:
    time_1 =
    #read x-axis accelerometer
    x = commands.getoutput("i2cget -y 1 0x1D 0x28 b") #Low
    time_2 =
    print "int : "+str(time_2 - time_1)

Any idea ?

Posts: 4
Joined: Sat Mar 15, 2014 2:02 pm

Re: BeagleBone: Speed of I2C bus

by adafruit2 on Fri Dec 19, 2014 2:39 pm

yow, you are using python but then calling a command line program, theres a ton of layers going on, please use the python smbus package!

Site Admin
Posts: 19110
Joined: Fri Mar 11, 2005 7:36 pm

Re: BeagleBone: Speed of I2C bus

by tdicola on Fri Dec 19, 2014 5:17 pm

Yeah check out the python-smbus library to natively access the I2C hardware. We use it a lot with the different libraries, etc. being ported to the Pi. Unfortunately there isn't that great of documentation on it, but you can find some basic info here: and the kernel smbus docs (this is the definitive API, but it's in C and a little tougher to use): ... s-protocol

You can install the python-smbus library pretty easily with an apt-get package too:
Code: Select all | TOGGLE FULL SIZE
sudo apt-get update
sudo apt-get install python-smbus

Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: BeagleBone: Speed of I2C bus

by madGambol on Tue Sep 06, 2016 11:13 am


I'm looking at the SMBus style interface embodied in the AdaFruit_I2C python class, and I don't understand what the parameter "reg" is doing. I'm reading an I2C address and a "register" doesn't factor into it. From an I2C address, I read or write N bytes. So what is "reg" doing?

I added to this topic because I can't find the "new topic" button.


Posts: 5
Joined: Wed Jul 02, 2014 1:03 am

Re: BeagleBone: Speed of I2C bus

by drewfustini on Wed Sep 07, 2016 12:16 am

Please see my response in the topic:
AdaFruit_I2C reg parameter

Posts: 920
Joined: Sat Dec 26, 2015 1:19 pm

Re: BeagleBone: Speed of I2C bus

by edebonis on Thu Sep 08, 2016 9:50 am

Hi, i fix the slow response programming in C. I made a cuple of functions and call them with my main code in python.

Posts: 1
Joined: Thu Sep 08, 2016 9:44 am

Please be positive and constructive with your questions and comments.