Page 1 of 1

MCP23017 For noobs???

Posted: Mon Sep 01, 2014 1:38 pm
by darkgeej
Hi

a week ago i bought a MCP23017 and hooked it up

Image

Just without the leds and button,and i tried to get the GPIO's on it to put out 3.3v
by doing this

gpio load i2c
gpio i2cd

gpio -x mcp23017:100:20 mode 100 out
gpio -x mcp23017:100:20 write 100 1


Ive checked and the mcp is on 0x20, but i cant get 3.3v on pin 21 (GPA0)

Im not sure if i get things mixed up, or what ells im doing wrong

Hope someone can help me :D

Re: MCP23017 For noobs???

Posted: Mon Sep 01, 2014 3:00 pm
by PeterO
Have you followed the adafriuit guide on getting i2c set up ?

https://learn.adafruit.com/adafruits-ra ... guring-i2c

Does your 23017 show up in the i2cdetect output ?

PeterO

Re: MCP23017 For noobs???

Posted: Mon Sep 01, 2014 3:02 pm
by darkgeej
Its does show up as 0x20
but there is a UU device showing also

Re: MCP23017 For noobs???

Posted: Mon Sep 01, 2014 3:05 pm
by PeterO
You can safley ignore the UU device...

Ok so the problem must be in the programming of the 23017.

I'm sorry but I'm not familiar with the commands you are using to configure the 23017 (I do it from 'C' code).

PeterO

Re: MCP23017 For noobs???

Posted: Mon Sep 01, 2014 3:12 pm
by darkgeej
is it easy to do the same thing in C?

Re: MCP23017 For noobs???

Posted: Mon Sep 01, 2014 3:18 pm
by darkgeej
What im looking for is a way to control a bunch of relays from the
pi , using a mcp23017 :)

Re: MCP23017 For noobs???

Posted: Mon Sep 01, 2014 3:23 pm
by DougieLawson
Install wiringPi and take a look at this: http://wiringpi.com/extensions/i2c-mcp23008-mcp23017/

Re: MCP23017 For noobs???

Posted: Mon Sep 01, 2014 3:32 pm
by darkgeej
Guess ill have a look again,

Got my command from Gordon(wiringpi) him self ;)
wrote to him about howto.

But this looks like C? im only just learning C, been
using #bash for some years now :)

Re: MCP23017 For noobs???

Posted: Mon Sep 01, 2014 3:36 pm
by PeterO
I was not suggesting you should do it in 'C', I was pointing out that because I'm only familar with using I2C from C I couldn't help you further.

PeterO

Re: MCP23017 For noobs???

Posted: Mon Sep 01, 2014 3:52 pm
by DougieLawson
gpio load i2c
gpio -x mcp23017:100:0x20:1 write 100 1
gpio -x mcp23017:100:0x20:1 write 101 1
gpio -x mcp23017:100:0x20:1 write 102 1
gpio -x mcp23017:100:0x20:1 write 103 1
gpio -x mcp23017:100:0x20:1 write 104 1
gpio -x mcp23017:100:0x20:1 write 105 1
gpio -x mcp23017:100:0x20:1 write 106 1
gpio -x mcp23017:100:0x20:1 write 107 1

gpio -x mcp23017:100:0x20:1 write 100 0
gpio -x mcp23017:100:0x20:1 write 101 0
gpio -x mcp23017:100:0x20:1 write 102 0
gpio -x mcp23017:100:0x20:1 write 103 0
gpio -x mcp23017:100:0x20:1 write 104 0
gpio -x mcp23017:100:0x20:1 write 105 0
gpio -x mcp23017:100:0x20:1 write 106 0
gpio -x mcp23017:100:0x20:1 write 107 0

Re: MCP23017 For noobs???

Posted: Mon Sep 01, 2014 4:31 pm
by darkgeej
what is :1 for :D

Re: MCP23017 For noobs???

Posted: Mon Sep 01, 2014 4:49 pm
by DougieLawson
darkgeej wrote:what is :1 for :D
I think it's for output - that worked for me. Read the code (because the man page for gpio is incomplete on the subject of -x extensions).

Re: MCP23017 For noobs???

Posted: Mon Sep 01, 2014 4:50 pm
by darkgeej
Still nothing on pin 21 = 0v

Re: MCP23017 For noobs???

Posted: Mon Sep 01, 2014 4:54 pm
by darkgeej
it worked XD just a bad connection :D

so the :1 did the trick :D its magic :D

Re: MCP23017 For noobs???

Posted: Mon Sep 01, 2014 5:28 pm
by DirkS
darkgeej wrote:it worked XD just a bad connection :D

so the :1 did the trick :D its magic :D
I thought the 0x20 instead of 20 would actually do the trick :shock:

Re: MCP23017 For noobs???

Posted: Mon Sep 01, 2014 7:52 pm
by gordon@drogon.net
darkgeej wrote:Guess ill have a look again,

Got my command from Gordon(wiringpi) him self ;)
wrote to him about howto.

But this looks like C? im only just learning C, been
using #bash for some years now :)
And I missed the 20 which should have been 0x20. Probably not enough coffee when I replied to the email!

-Gordon

Re: MCP23017 For noobs???

Posted: Mon Sep 01, 2014 7:57 pm
by gordon@drogon.net
DirkS wrote:
darkgeej wrote:it worked XD just a bad connection :D

so the :1 did the trick :D its magic :D
I thought the 0x20 instead of 20 would actually do the trick :shock:
The bit of code that parses the -x flags to the gpio command stops parsing when it has had enough - so:

gpio -x mcp23017:100:0x20:1 write 105 1

works, but the extra :1 on the end is ignored. You can put anything there and it's ignored...

The real issue here was not prefixing the I2C address with 0x - of-course we could have used decimal (32)...

-Gordon

Re: MCP23017 For noobs???

Posted: Tue Sep 02, 2014 10:33 am
by darkgeej
Anyway, it worked :D thanks to u all for guiding a lost noop :D

Re: MCP23017 For noobs???

Posted: Mon Sep 15, 2014 7:39 pm
by Richard-TX
I have boards for driving 8 relays and it has a mcp23017 on board. The boards are designed so that a second board can be driven from the first (Port A)

I wrote some demo code for the MCP23017 relay board. It turns on and off various Port B pins (IC Pins 1-8)

Here it is.

Code: Select all

#!/bin/sh
echo "what I2C bus? (0 or 1)"
read BUS

echo "What I2C address? (nn)"
read ADDR

#set PORT B as output
i2cset -y $BUS 0x$ADDR 0x01 0x00
echo "turning on all relays"
i2cset -y $BUS 0x$ADDR 0x13 0xff
sleep 1
echo "turning off all relays"

i2cset -y $BUS 0x$ADDR 0x13 0x00
sleep 1
echo "sequencing all relays"
for a in 1 2 4 8 10 20 40 80
do
i2cset -y $BUS 0x$ADDR 0x13 0x$a
sleep 1
done

echo "all done"
i2cset -y $BUS 0x$ADDR 0x13 0x00

Re: MCP23017 For noobs???

Posted: Sun May 08, 2016 7:18 pm
by nxet
gordon@drogon.net wrote:
DirkS wrote:
darkgeej wrote:it worked XD just a bad connection :D

so the :1 did the trick :D its magic :D
I thought the 0x20 instead of 20 would actually do the trick :shock:
The bit of code that parses the -x flags to the gpio command stops parsing when it has had enough - so:

gpio -x mcp23017:100:0x20:1 write 105 1

works, but the extra :1 on the end is ignored. You can put anything there and it's ignored...

The real issue here was not prefixing the I2C address with 0x - of-course we could have used decimal (32)...

-Gordon

First of all thanks a lot for the amazing work you've done with WiringPi.
Can I just suggest you to update the example on the extension page? Since I have myself lost a decent half hour trying to figure out why nothing was being output, when in fact the I2C adress was incomplete (using 20 instead of 0x20), I'm sure many will benefit from the update.
http://wiringpi.com/the-gpio-utility/i2 ... xtensions/