sharksfan98
Posts: 2
Joined: Thu Jan 10, 2013 7:51 pm

Setting up i2c for C?

Sun Feb 24, 2013 10:13 pm

I'm setting up i2c for an Application written in C, but I've not been able to find any how-to's for it. I'm running a model-b Raspberry Pi on Debian 6 with LXDE. Can anybody show me how to set up i2c so I can use it in a C Application?

Thanks for any help in advance

User avatar
j35570
Posts: 7
Joined: Thu Oct 18, 2012 5:45 am

Re: Setting up i2c for C?

Tue Feb 26, 2013 7:21 am

I have successfully connected an lcd and some buttons on the i2c bus.

First you need to install the i2c drivers: http://www.skpang.co.uk/blog/archives/575

Then you need to include the i2c header:

Code: Select all

#include <linux/i2c-dev.h>
Take a look at my project at http://raspify.stockenstrand.com or download a test project at https://github.com/j3557o/RPi_i2c_test/

Good luck!

/j3557o

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Setting up i2c for C?

Tue Feb 26, 2013 9:28 am

It's all fairly straighforwards in C - but the operation can be a bit confusing and you have no direct control over the I2C bus phases (or appear not to, however)...

But if you want some slightly easier to use access, then I write some wrappers for the standard I2C calls and made it part of wiringPi.

And example program to talk to an MCP23017 GPIO expander is:

http://unicorn.drogon.net/q2w.c

The rest can be found:

https://projects.drogon.net/raspberry-p ... c-library/

-Gordon
--
Gordons projects: https://projects.drogon.net/

Return to “Interfacing (DSI, CSI, I2C, etc.)”