User avatar
jerseytechguy
Posts: 7
Joined: Sun Mar 15, 2015 4:06 pm
Location: Highland Lakes, NJ
Contact: Website

Getting i2c to work on Raspberry Pi2

Sun Mar 15, 2015 4:20 pm

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?
Software Architect, Electronic Engineer, Car Enthusiast, Chef, Blogger, Paranormal Investigator (and Skeptic). I'm like MacGyver, Alton Brown, Doc Brown and Peter Venkman all in one.

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4698
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Getting i2c to work on Raspberry Pi2

Sun Mar 15, 2015 4:49 pm


User avatar
joan
Posts: 12782
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Getting i2c to work on Raspberry Pi2

Sun Mar 15, 2015 4:55 pm

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
$ 

User avatar
jerseytechguy
Posts: 7
Joined: Sun Mar 15, 2015 4:06 pm
Location: Highland Lakes, NJ
Contact: Website

Re: Getting i2c to work on Raspberry Pi2

Sun Mar 15, 2015 5:58 pm

I did try the steps from this thread and no luck.
Software Architect, Electronic Engineer, Car Enthusiast, Chef, Blogger, Paranormal Investigator (and Skeptic). I'm like MacGyver, Alton Brown, Doc Brown and Peter Venkman all in one.

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4698
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Getting i2c to work on Raspberry Pi2

Sun Mar 15, 2015 6:00 pm

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.

User avatar
jerseytechguy
Posts: 7
Joined: Sun Mar 15, 2015 4:06 pm
Location: Highland Lakes, NJ
Contact: Website

Re: Getting i2c to work on Raspberry Pi2

Sun Mar 15, 2015 6:03 pm

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!
Software Architect, Electronic Engineer, Car Enthusiast, Chef, Blogger, Paranormal Investigator (and Skeptic). I'm like MacGyver, Alton Brown, Doc Brown and Peter Venkman all in one.

User avatar
DougieLawson
Posts: 30188
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Getting i2c to work on Raspberry Pi2

Sun Mar 15, 2015 8:24 pm

Add these two lines to /etc/modules

Code: Select all

i2c_bcm2708
i2c_dev
and the modprobe stuff gets run automagically during boot.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

Distro
Posts: 7
Joined: Wed Apr 29, 2015 9:13 am

Re: Getting i2c to work on Raspberry Pi2

Wed May 13, 2015 6:47 am

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.

Zork
Posts: 4
Joined: Tue Feb 23, 2016 2:20 am

Re: Getting i2c to work on Raspberry Pi2

Tue Feb 23, 2016 2:35 am

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.

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 4115
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: Getting i2c to work on Raspberry Pi2

Tue Feb 23, 2016 7:37 pm

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.
Usually running Raspbian Jessie on up to 12 of 13 Pi's (an A, B1, 2xB2, 2xB+, A+, P2B, 3xP0, P0W) and Stretch on my P3B. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

User avatar
joan
Posts: 12782
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Getting i2c to work on Raspberry Pi2

Tue Feb 23, 2016 8:01 pm

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.

Zork
Posts: 4
Joined: Tue Feb 23, 2016 2:20 am

Re: Getting i2c to work on Raspberry Pi2

Wed Feb 24, 2016 3:55 am

I have also tried the params on singular format. My modules file includes i2c-dev and i2c-bcm2708.

Zork
Posts: 4
Joined: Tue Feb 23, 2016 2:20 am

Re: Getting i2c to work on Raspberry Pi2

Wed Feb 24, 2016 4:02 am

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.

DirkS
Posts: 7651
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Getting i2c to work on Raspberry Pi2

Wed Feb 24, 2016 8:30 am

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

Zork
Posts: 4
Joined: Tue Feb 23, 2016 2:20 am

Re: Getting i2c to work on Raspberry Pi2

Wed Feb 24, 2016 7:05 pm

Ah, I see. I was following i structions that said to use gpio load to get an accelerometer to work properly.

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

Who is online

Users browsing this forum: No registered users and 7 guests