Page 1 of 1

Getting i2c to work on Raspberry Pi2

Posted: Sun Mar 15, 2015 4:20 pm
by jerseytechguy
I come from a Windows and .NET world. So a bit new to Linux and the PI.

I am trying to get i2c working on my Pi2. I am running Raspbian (most recent version for Pi2). Have gone through config and enabled I2C and SPI as both will be needed for my projects.

I am trying to get a ds1307 RTC working. From what I've read running the command below is supposed to detect the devices. However I get the following error.

Code: Select all

sudo i2cdetect -y 0
Error: Could not open file `/dev/i2c-0' or `/dev/i2c/0': No such file or directory
I also tried -y 1 per another article on newer PIs and this throws same error.

I am not finding much info out there on Pi2 and I2C. Does anyone have any advice or experience with this?

Re: Getting i2c to work on Raspberry Pi2

Posted: Sun Mar 15, 2015 4:49 pm
by ShiftPlusOne

Re: Getting i2c to work on Raspberry Pi2

Posted: Sun Mar 15, 2015 4:55 pm
by joan
Add the following lines to /boot/config.txt and reboot.

Code: Select all

dtparam=i2c1=on
dtparam=spi=on
The spi devices should be present if you do

Code: Select all

$ ls -l /dev/spi*
crw-rw---- 1 root spi 153, 0 Mar 13 22:17 /dev/spidev0.0
crw-rw---- 1 root spi 153, 1 Mar 13 22:17 /dev/spidev0.1
$
For I2C you'll probably have to install the modules

Code: Select all

sudo modprobe i2c_bcm2708
sudo modprobe i2c_dev
Then

Code: Select all

 $ ls -l /dev/i2c*
crw-rw---- 1 root i2c 89, 0 Mar 15 12:54 /dev/i2c-0
crw-rw---- 1 root i2c 89, 1 Mar 15 12:54 /dev/i2c-1
$ 

Re: Getting i2c to work on Raspberry Pi2

Posted: Sun Mar 15, 2015 5:58 pm
by jerseytechguy
I did try the steps from this thread and no luck.

Re: Getting i2c to work on Raspberry Pi2

Posted: Sun Mar 15, 2015 6:00 pm
by ShiftPlusOne
jerseytechguy wrote:
I did try the steps from this thread and no luck.
Are the required modules loaded (check with lsmod)? Joan's post provides a bit more detail.

Re: Getting i2c to work on Raspberry Pi2

Posted: Sun Mar 15, 2015 6:03 pm
by jerseytechguy
joan wrote:Add the following lines to /boot/config.txt and reboot.

Code: Select all

dtparam=i2c1=on
dtparam=spi=on
The spi devices should be present if you do

Code: Select all

$ ls -l /dev/spi*
crw-rw---- 1 root spi 153, 0 Mar 13 22:17 /dev/spidev0.0
crw-rw---- 1 root spi 153, 1 Mar 13 22:17 /dev/spidev0.1
$
For I2C you'll probably have to install the modules

Code: Select all

sudo modprobe i2c_bcm2708
sudo modprobe i2c_dev
Then

Code: Select all

 $ ls -l /dev/i2c*
crw-rw---- 1 root i2c 89, 0 Mar 15 12:54 /dev/i2c-0
crw-rw---- 1 root i2c 89, 1 Mar 15 12:54 /dev/i2c-1
$ 
This seemed more promising and did help. Thanks!

Re: Getting i2c to work on Raspberry Pi2

Posted: Sun Mar 15, 2015 8:24 pm
by DougieLawson
Add these two lines to /etc/modules

Code: Select all

i2c_bcm2708
i2c_dev
and the modprobe stuff gets run automagically during boot.

Re: Getting i2c to work on Raspberry Pi2

Posted: Wed May 13, 2015 6:47 am
by Distro
Hi,

Try enabling I2C since the RPi's booting.

Code: Select all

sudo raspi-config
Select 8: Advanced options.

Select A7: I2C

Then YES, OK and YES, OK for both questions RPi will ask.

Finally reboot:

Code: Select all

sudo reboot
For now, the I2C will be enabled when you run your RPi.

Hoping it be helpful.

Regards.

Re: Getting i2c to work on Raspberry Pi2

Posted: Tue Feb 23, 2016 2:35 am
by Zork
I have tried everything covered here, and still no success. I have confirmed I am editing the 'real' config.txt and not a copy. Dtparam=act_led_trigger=heartbeat works, but dtparam=i2c_arm=on,i2s=on,spi=on does not. I have also tried just i2c and i2c1.

Re: Getting i2c to work on Raspberry Pi2

Posted: Tue Feb 23, 2016 7:37 pm
by FTrevorGowen
Zork wrote:I have tried everything covered here, and still no success. I have confirmed I am editing the 'real' config.txt and not a copy. Dtparam=act_led_trigger=heartbeat works, but dtparam=i2c_arm=on,i2s=on,spi=on does not. I have also tried just i2c and i2c1.
I enabled spi & i2c via raspi-config which appended two lines to /boot/config.txt with a somewhat different syntax than that above:

Code: Select all

# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on

# Uncomment this to enable the lirc-rpi module
#dtoverlay=lirc-rpi

# Additional overlays and parameters are documented /boot/overlays/README

dtparam=spi=on
dtparam=i2c_arm=on
(Hopefully not a "red herring")
Trev.

Re: Getting i2c to work on Raspberry Pi2

Posted: Tue Feb 23, 2016 8:01 pm
by joan
Zork wrote:I have tried everything covered here, and still no success. I have confirmed I am editing the 'real' config.txt and not a copy. Dtparam=act_led_trigger=heartbeat works, but dtparam=i2c_arm=on,i2s=on,spi=on does not. I have also tried just i2c and i2c1.
Things have changed since last year when that advice was given.

In addition to what FTrevorGowen says make sure /etc/modules contains i2c-dev but any other i2c or spi modules should now be commented out in /etc/modules.

Re: Getting i2c to work on Raspberry Pi2

Posted: Wed Feb 24, 2016 3:55 am
by Zork
I have also tried the params on singular format. My modules file includes i2c-dev and i2c-bcm2708.

Re: Getting i2c to work on Raspberry Pi2

Posted: Wed Feb 24, 2016 4:02 am
by Zork
I can get "i2cdetect -y 1" to display but "gpio load i2c" just tells me that I don't have i2c loaded and device tree is enabled.

Re: Getting i2c to work on Raspberry Pi2

Posted: Wed Feb 24, 2016 8:30 am
by DirkS
Zork wrote:I can get "i2cdetect -y 1" to display but "gpio load i2c" just tells me that I don't have i2c loaded and device tree is enabled.
You don't need a gpio load. That's already loaded through the device tree stuff.
Also get rid of 'i2c-bcm2708' from /etc/modules.
You only need

Code: Select all

dtparam=i2c
in config.txt and

Code: Select all

i2c-dev
in /etc/modules

Re: Getting i2c to work on Raspberry Pi2

Posted: Wed Feb 24, 2016 7:05 pm
by Zork
Ah, I see. I was following i structions that said to use gpio load to get an accelerometer to work properly.