0
votes

I want to configure I2C for raspberry pi using PYTHON or last choice C. I have worked on ATMEL micro controller, it provide I2C communication with any device. I want some similar mechanism for raspberry pi. I have following questions:

1. We have to define address of every device in I2C bus. If i want to send some data from ATMEL micro controller to raspberry pi (write data to raspberry pi), what will be the address of raspberry pi or how we can set the address.

2. Is there any interrupt or something like that if we receive some data on I2C bus?

3. Which library will be best for PYTHON or C?

4. Can i write my custom codes for implementing I2C protocol?

Please help.... Thanks in advance..

1
Regarding the address, you have to define the address of all the devices in the network. It can be in the range 0-127.Rishikesh Raje
yaa address of some devices is fixed but for micro controllers we can select any address 0-127. What is address of raspberry pi or how we can define address in it..? I found nothing in python codes which define the address for raspberry pi.rohan dhama
AFAIK raspberry pi cannot operate as a slave. And since it must be a master, the address is effectively immaterial.user58697

1 Answers

2
votes

I suggest you use i2c-dev and i2c-bcm2708 module, where you will have the i2c buses exposed to the /dev filesystem.

$ sudo modprobe i2c-dev
$ sudo modprobe i2c-bcm2708

Now will will have i2c buses exported, list them with

$ ls /dev/i2c-*

Using it is not that simple because it is i2c, it has different protocols and addresses.

If you are going to use it in C, this is the tutorial.

In python, you can install the i2cdev package and use it as this:

from devi2c import I2C
device, bus = 0x42, 0
i2c = I2C(device, bus)
value = i2c.read(1)         # read 1 byte
i2c.write(b’some raw data’)     # write bytes
i2c.close()                 # close connection