Control the MOD-IO2 via i2c on Raspbian
This is just a short summary, the full guide is located here.
Edit /etc/modprobe.d/raspi-blacklist.conf and comment out the line that says blacklist i2c-bcm2708, then reboot.
pi@raspberrypi ~ $ sudo vim /etc/modprobe.d/raspi-blacklist.conf
pi@raspberrypi ~ $ cat /etc/modprobe.d/raspi-blacklist.conf
# blacklist spi and i2c by default (many users don't need them)
blacklist spi-bcm2708
#blacklist i2c-bcm2708
pi@raspberrypi ~ $ sudo reboot
Broadcast message from root@raspberrypi (pts/1) (Mon Jan 21 11:28:05 2013):
The system is going down for reboot NOW!
pi@raspberrypi ~ $
After the reboot:
pi@raspberrypi ~ $ sudo modprobe i2c-dev
pi@raspberrypi ~ $ ls /dev/i2c*
/dev/i2c-0 /dev/i2c-1
pi@raspberrypi ~ $ ls -l /dev/i2c*
crw-rw---T 1 root i2c 89, 0 Jan 21 11:38 /dev/i2c-0
crw-rw---T 1 root i2c 89, 1 Jan 21 11:38 /dev/i2c-1
pi@raspberrypi ~ $ sudo chmod o+rw /dev/i2c*
pi@raspberrypi ~ $ ls -l /dev/i2c*
crw-rw-rwT 1 root i2c 89, 0 Jan 21 11:38 /dev/i2c-0
crw-rw-rwT 1 root i2c 89, 1 Jan 21 11:38 /dev/i2c-1
pi@raspberrypi ~ $ sudo apt-get install i2c-tools
pi@raspberrypi ~ $ sudo i2cdetect -l
i2c-0 i2c bcm2708_i2c.0 I2C adapter
i2c-1 i2c bcm2708_i2c.1 I2C adapter
pi@raspberrypi ~ $
Edit /etc/rc.local and add the modprobe and chmod commands so that you don’t have to run them after every reboot.
pi@raspberrypi ~ $ sudo vim /etc/rc.local
pi@raspberrypi ~ $ cat /etc/rc.local |grep i2c
modprobe i2c-dev
chmod o+rw /dev/i2c*
pi@raspberrypi ~ $
The MOD-IO2 has the address 0x48:
pi@raspberrypi ~ $ sudo i2cdetect 0
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-0.
I will probe address range 0x03-0x77.
Continue? [Y/n] y
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
pi@raspberrypi ~ $
Download and compile i2c-tool.c, have a look at the SOFTWARE section under https://www.olimex.com/Products/Modules/IO/MOD-IO2/, there is also a README.
pi@raspberrypi ~ $ wget http://www.jann.cc/_downloads/i2c-tool.c
--2013-01-21 12:01:08-- http://www.jann.cc/_downloads/i2c-tool.c
Resolving www.jann.cc (www.jann.cc)... 107.22.36.32
Connecting to www.jann.cc (www.jann.cc)|107.22.36.32|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 11583 (11K) [text/plain]
Saving to: `i2c-tool.c'
100%[============================>] 11,583 --.-K/s in 0.1s
2013-01-21 12:01:10 (80.3 KB/s) - `i2c-tool.c' saved [11583/11583]
pi@raspberrypi ~ $ gcc i2c-tool.c -o i2c-tool
pi@raspberrypi ~ $
Turn booth relays on:
pi@raspberrypi ~ $ ./i2c-tool -w 0 0x48 4 0x02 0xA0 0x40 0x03
SLAVE ADDRESS: 0x48
NUMBER OF BYTES TO WRITE: 4
MEMORY ALLOCATED AT ADDRESS: 0xD6B008
/dev/i2c-0 OPENDED!
WRITE:SUCCESS
pi@raspberrypi ~ $
Turn booth relays off:
pi@raspberrypi ~ $ ./i2c-tool -w 0 0x48 4 0x02 0xA0 0x40 0x00
SLAVE ADDRESS: 0x48
NUMBER OF BYTES TO WRITE: 4
MEMORY ALLOCATED AT ADDRESS: 0x1992008
/dev/i2c-0 OPENDED!
WRITE:SUCCESS
pi@raspberrypi ~ $
Update
If you have a MOD-IO2 with firmware version 3 then have a look here too: https://www.olimex.com/forum/index.php?topic=2034.msg9155#msg9155