User avatar
darkgeej
Posts: 35
Joined: Mon Sep 01, 2014 1:16 pm
Location: Ballerup - Denmark
Contact: Website

MCP23017 For noobs???

Mon Sep 01, 2014 1:38 pm

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
Yes all the rumors about me are true...
Computers since 1980

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

Re: MCP23017 For noobs???

Mon Sep 01, 2014 3:00 pm

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
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
darkgeej
Posts: 35
Joined: Mon Sep 01, 2014 1:16 pm
Location: Ballerup - Denmark
Contact: Website

Re: MCP23017 For noobs???

Mon Sep 01, 2014 3:02 pm

Its does show up as 0x20
but there is a UU device showing also
Yes all the rumors about me are true...
Computers since 1980

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

Re: MCP23017 For noobs???

Mon Sep 01, 2014 3:05 pm

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
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
darkgeej
Posts: 35
Joined: Mon Sep 01, 2014 1:16 pm
Location: Ballerup - Denmark
Contact: Website

Re: MCP23017 For noobs???

Mon Sep 01, 2014 3:12 pm

is it easy to do the same thing in C?
Yes all the rumors about me are true...
Computers since 1980

User avatar
darkgeej
Posts: 35
Joined: Mon Sep 01, 2014 1:16 pm
Location: Ballerup - Denmark
Contact: Website

Re: MCP23017 For noobs???

Mon Sep 01, 2014 3:18 pm

What im looking for is a way to control a bunch of relays from the
pi , using a mcp23017 :)
Yes all the rumors about me are true...
Computers since 1980

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

Re: MCP23017 For noobs???

Mon Sep 01, 2014 3:23 pm

Install wiringPi and take a look at this: http://wiringpi.com/extensions/i2c-mcp23008-mcp23017/
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
darkgeej
Posts: 35
Joined: Mon Sep 01, 2014 1:16 pm
Location: Ballerup - Denmark
Contact: Website

Re: MCP23017 For noobs???

Mon Sep 01, 2014 3:32 pm

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 :)
Yes all the rumors about me are true...
Computers since 1980

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

Re: MCP23017 For noobs???

Mon Sep 01, 2014 3:36 pm

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
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
DougieLawson
Posts: 36813
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: MCP23017 For noobs???

Mon Sep 01, 2014 3:52 pm

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
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
darkgeej
Posts: 35
Joined: Mon Sep 01, 2014 1:16 pm
Location: Ballerup - Denmark
Contact: Website

Re: MCP23017 For noobs???

Mon Sep 01, 2014 4:31 pm

what is :1 for :D
Yes all the rumors about me are true...
Computers since 1980

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

Re: MCP23017 For noobs???

Mon Sep 01, 2014 4:49 pm

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).
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
darkgeej
Posts: 35
Joined: Mon Sep 01, 2014 1:16 pm
Location: Ballerup - Denmark
Contact: Website

Re: MCP23017 For noobs???

Mon Sep 01, 2014 4:50 pm

Still nothing on pin 21 = 0v
Yes all the rumors about me are true...
Computers since 1980

User avatar
darkgeej
Posts: 35
Joined: Mon Sep 01, 2014 1:16 pm
Location: Ballerup - Denmark
Contact: Website

Re: MCP23017 For noobs???

Mon Sep 01, 2014 4:54 pm

it worked XD just a bad connection :D

so the :1 did the trick :D its magic :D
Yes all the rumors about me are true...
Computers since 1980

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

Re: MCP23017 For noobs???

Mon Sep 01, 2014 5:28 pm

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:

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: MCP23017 For noobs???

Mon Sep 01, 2014 7:52 pm

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
--
Gordons projects: https://projects.drogon.net/

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: MCP23017 For noobs???

Mon Sep 01, 2014 7:57 pm

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
--
Gordons projects: https://projects.drogon.net/

User avatar
darkgeej
Posts: 35
Joined: Mon Sep 01, 2014 1:16 pm
Location: Ballerup - Denmark
Contact: Website

Re: MCP23017 For noobs???

Tue Sep 02, 2014 10:33 am

Anyway, it worked :D thanks to u all for guiding a lost noop :D
Yes all the rumors about me are true...
Computers since 1980

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: MCP23017 For noobs???

Mon Sep 15, 2014 7:39 pm

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
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

nxet
Posts: 7
Joined: Fri Jan 15, 2016 7:04 pm

Re: MCP23017 For noobs???

Sun May 08, 2016 7:18 pm

[email protected] 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/
Raspbian, Raspberry Pi 2 Model B V1.1

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