Thursday, October 10, 2013

Post 31: Expanding the number of IO ports with I2C
(added to a few hours later)

First I bought the MCP23008 8-port expansion chip from Adafuit.

Then I followed the install procedure given in:

http://www.raspberrypi-spy.co.uk/2013/07/how-to-use-a-mcp23017-i2c-port-expander-with-the-raspberry-pi-part-1/

(sorry about the line break)

Next I wired up a small breadboard as follows (nothing else on the board):

Here's the pin-out of a plain MCP23008 (there are several variants):

I have a Rev 2 Pi so I ran the following from SSH:

$ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: 20 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --    

Which shows that the MCP chip is recognized and is at the expected address. Then I ran the command that set pins 0 - 6 as output:

$ sudo i2cset -y 0x20 0x00 0x80

And then I tried this--

$ sudo i2cset -y 0x20 0x14 0x01

Which should light the LED wired from GP0. But nothing happens. And no error messages.

Any comments?

LATER that same day:

I went to the site:

http://www.skpang.co.uk/blog/archives/637

And followed their procedure -- a directory of source written in C.

It didn't work either until I read the comments and made the change for my Rev. B Pi. Then the demo C program worked. However, I find the code obscure. I see how you turn an LED on but (not directly) how to turn it off. Plus, I'd much rather work in Python. Drat!

Comments?

No comments:

Post a Comment