I2C tools Speed <Solved>


9 posts
by Pulse9 » Sat Jul 06, 2013 6:31 pm
Hello all, I'm trying to read the samples of a BMA180 Accelerometer, I'm using the i2cget to get the values of each axis, I did a script in bash with a while true to read the values and concatenate in a txt file, and running the script with timeout 1s, but when it finish it only show that there is ~50 samples of the BMA180 per second, I modify the registers the decrease the bw (page 30 of the datasheet) to get more samples but didnt work.. is there a way to improve the i2cget speed? so i can get more samples per second? (sorry for my english)
Last edited by Pulse9 on Sun Jul 07, 2013 2:52 pm, edited 1 time in total.
Posts: 5
Joined: Tue May 28, 2013 3:10 pm
by joan » Sat Jul 06, 2013 6:43 pm
I'm surprised you are getting even that many with bash. You could try C.
User avatar
Posts: 5452
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by Pulse9 » Sat Jul 06, 2013 6:51 pm
Isnt using direct bash script fastest than C?
Posts: 5
Joined: Tue May 28, 2013 3:10 pm
by joan » Sat Jul 06, 2013 7:26 pm
If you are determined to use i2cget then C wouldn't be dramatically faster then bash.

You can access the i2c device directly.
User avatar
Posts: 5452
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by Pulse9 » Sat Jul 06, 2013 7:45 pm
Is there a library of C that recommend me? I need to get at least 150 samples per second and I only have ~50, how can i improve the i2c communication to get more samples? Thanks a lot
Posts: 5
Joined: Tue May 28, 2013 3:10 pm
by joan » Sat Jul 06, 2013 7:55 pm
Personally with C I just open /dev/i2c-0 or /dev/i2c-1 as files and use read and write.

If you need a C wrapper both http://www.airspayce.com/mikem/bcm2835/ and http://wiringpi.com/ provide them.

Python also provided wrappers.
User avatar
Posts: 5452
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by Pulse9 » Sun Jul 07, 2013 4:47 am
SOLVED Thanks a lot joan you were right I used C and I got ~1000 samples per second! This is an interesting page to check for performance in different languages Thanks a Lot

http://codeandlife.com/2012/07/03/benchmarking-raspberry-pi-gpio-speed/
Posts: 5
Joined: Tue May 28, 2013 3:10 pm
by joan » Sun Jul 07, 2013 7:56 am
Well done! Quite an improvement.
User avatar
Posts: 5452
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by xerpi » Sun Jul 07, 2013 12:59 pm
Pulse9 wrote:Isnt using direct bash script fastest than C?


C is compiled to machine code, so the resulting program will be executed directly by the CPU, whereas bash is interpreted, so it's not executed directly by the CPU, there's a program (the interpreter) that executes the bash script.
Posts: 6
Joined: Mon Jul 01, 2013 7:25 pm
Location: Barcelona