photomankc
Posts: 80
Joined: Fri Aug 24, 2012 12:58 pm

Anyone sucessful in getting I2C /dev entries to show up?

Fri Aug 24, 2012 2:16 pm

Hello,

I'm currently working on the idea to give my mobile robot a brain upgrade with the Raspberry Pi and now have my hands on 3 boards to start working with. I foolishly assumed that with the I2C broken out on the GPIO header that there would be already integrated drivers for this. Thus far I have had zero success in getting even as far as having /dev/i2c-0 show up to start from. My robot was designed all around I2C with microcontrollers so getting this working is pretty central to the concept.

I have followed the instructions out here to get a kernel that was supposed to have the drivers compiled into it and update the firmware as well:
http://www.bootc.net/archives/2012/05/1 ... pberry-pi/

After installing his kernel package and copying it over to kernel.img I see no indication in dmesg that anything related to I2C occurs? I'm pretty far from a linux guru and so this whole process seems rather painful to get to the point that you can use the stuff broken out on the GPIO. That's not a dig, just an observation coming to this as someone that does not eat and breathe linux.

User avatar
fbutler
Posts: 302
Joined: Thu Mar 15, 2012 4:09 pm
Location: Surrey, England

Re: Anyone sucessful in getting I2C /dev entries to show up?

Fri Aug 24, 2012 6:15 pm

Have a look at the /etc/modprobe.d/raspi-blacklist.conf file, comment out the two lines:

blacklist spi-bcm2708
blacklist i2c-bcm2708

and reboot. The devices :

spidev0.0
spidev0.1

should then appear in the /dev/ directory

User avatar
PeterO
Posts: 5024
Joined: Sun Jul 22, 2012 4:14 pm

Re: Anyone sucessful in getting I2C /dev entries to show up?

Fri Aug 24, 2012 9:05 pm

It seems the information about needing a custom kernel is out of date.

My PI is running 3.2.27+ #60 , and after removing the entry in /etc/modprobe.d/raspi-blacklist.conf
and running "sudo modprobe i2c-dev" the devices appeared and are working.

I used the code at http://www.robot-electronics.co.uk/files/rpi_cmps03.c and modified it for the MCP23017's address, and I can read back one of the port registers. I just need to sort out the ownership of the files in /dev.

It was much simpler than I expected !

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

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

Re: Anyone sucessful in getting I2C /dev entries to show up?

Fri Aug 24, 2012 9:34 pm

After the modprobe I do

sudo chmod o+rw /dev/i2c*

to allow access to the i2c devices as a standard user.

photomankc
Posts: 80
Joined: Fri Aug 24, 2012 12:58 pm

Re: Anyone sucessful in getting I2C /dev entries to show up?

Fri Aug 24, 2012 10:22 pm

Awesome. That would have been cool info to know! Anyway, removing the blacklist fixed it right up and I see the /dev/i2c-0 and /dev/i2c-1 entries in there now. Thanks for the info!

catmaker
Posts: 50
Joined: Thu May 24, 2012 8:32 am

Re: Anyone sucessful in getting I2C /dev entries to show up?

Fri Aug 24, 2012 10:54 pm

joan wrote:After the modprobe I do

sudo chmod o+rw /dev/i2c*

to allow access to the i2c devices as a standard user.
I also noticed that after you install i2c-tools with apt-get

Code: Select all

sudo apt-get update
sudo apt-get install i2c-tools
the group i2c is made. After which you can upgrade a user's premissions [edit:incomplete sentence] to gain access to the i2c devices.

Code: Select all

sudo usermod -aG i2c yourusername

User avatar
PeterO
Posts: 5024
Joined: Sun Jul 22, 2012 4:14 pm

Re: Anyone sucessful in getting I2C /dev entries to show up?

Fri Aug 24, 2012 11:19 pm

catmaker wrote:[
I also noticed that after you install i2c-tools with apt-get

Code: Select all

sudo apt-get update
sudo apt-get install i2c-tools
the group i2c is made. After which you can upgrade a user's premissions [edit:incomplete sentence] to gain access to the i2c devices.

Code: Select all

sudo usermod -aG i2c yourusername
Thanks for that "Top Tip" :-)
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

catmaker
Posts: 50
Joined: Thu May 24, 2012 8:32 am

Re: Anyone sucessful in getting I2C /dev entries to show up?

Mon Sep 03, 2012 1:45 am

catmaker wrote:Thanks for that "Top Tip" :-)
PeterO
Ha ha, you're welcome. Really, it was an accidental discovery :)

garym1957
Posts: 11
Joined: Fri Aug 24, 2012 6:04 am

Re: Anyone sucessful in getting I2C /dev entries to show up?

Tue Sep 18, 2012 3:05 am

This is great. Thanks very much for the good advice.

How do I automatically modprobe AND change permissions to the /dev/i2c-0 file at boot time?
Can I run a shell script at boot time?

catmaker
Posts: 50
Joined: Thu May 24, 2012 8:32 am

Re: Anyone sucessful in getting I2C /dev entries to show up?

Tue Sep 18, 2012 4:21 am

garym1957 wrote:This is great. Thanks very much for the good advice.

How do I automatically modprobe AND change permissions to the /dev/i2c-0 file at boot time?
Can I run a shell script at boot time?
In my experiments, I found that there isn't a need to remove the blacklisting from /etc/modprobe.d/raspi-blacklist.conf -- I just added two lines to the /etc/modules and they look like below (it must be some override thingy, but YMMV) :

Code: Select all

# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# Parameters can be specified after the module name.

snd-bcm2835
i2c-dev
i2c-bcm2708
This makes the kernel automatically load up the necessary I2C modules and gives you the /dev/i2c-* devices.
I don't know how to adjust the permissions of the devices at boot time yet, so I just made myself a groupie to the I2C group with the usermod command described in the above message. (There are many sub-directories under /etc/rc*.d or /etc/init which will run a script at boot time, but I prefer not to touch them).

User avatar
tedhale
Posts: 114
Joined: Thu Sep 20, 2012 4:52 pm
Location: Williamsburg, VA, USA
Contact: Website

Re: Anyone sucessful in getting I2C /dev entries to show up?

Thu Sep 20, 2012 4:56 pm

The simplest way to add commands that will be executed at startup is to edit the file

/etc/rc.local

This script is intended for misc. stuff needed at startup, so it's pretty safe to mess with.
It will run at the end of the startup process.

-Ted Hale
- Ted B. Hale
http://raspberrypihobbyist.blogspot.com

catmaker
Posts: 50
Joined: Thu May 24, 2012 8:32 am

Re: Anyone sucessful in getting I2C /dev entries to show up?

Fri Sep 21, 2012 2:28 am

tedhale wrote: /etc/rc.local

This script is intended for misc. stuff needed at startup, so it's pretty safe to mess with.
It will run at the end of the startup process.
Nice one, Ted. Thanks!

konsumer
Posts: 2
Joined: Sun Sep 23, 2012 8:57 am

Re: Anyone sucessful in getting I2C /dev entries to show up?

Sun Sep 23, 2012 9:00 am

this helps with permissions.

konsumer
Posts: 2
Joined: Sun Sep 23, 2012 8:57 am

Re: Anyone sucessful in getting I2C /dev entries to show up?

Sun Sep 23, 2012 11:15 am

More specifically, put this in a file called /etc/udev/udev.rules:

Code: Select all

# i2c devices
KERNEL=="i2c-[0-9]*",	NAME="i2c/%n", SYMLINK+="%k"
There are other useful lines in there, though.

Return to “Automation, sensing and robotics”