Pages: [1]   Go Down
Author Topic: [solved]mcp23018 not working  (Read 790 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Sr. Member
****
Karma: 11
Posts: 349
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I forgot that dip package is counter clock wise and plugged some stuff on the 15+ pins on the wrong end it works now.
You can delete this thread if you want.
I bought the mcp23018 because I wanted more i/o ports on my uno so I wired it up to get an open drain circuit only the yellow led is supposed to be on however both of them are on even when I set portb to zero both of them are still on and I can not understand why I am using the mcp23018 library:
https://github.com/maniacbug/Arduino/tree/master/libraries/MCP23018
and here is my code Also I have attached a picture of my breadboard and here is the datasheet http://ww1.microchip.com/downloads/en/DeviceDoc/22103a.pdf
Code:
#include <mcp23018.h>

#include <Wire.h>
MCP23018 pex(0);
//led i/o expander

#define bit0 0
#define bit1 2
#define bit2 4
#define bit3 8
#define bit4 16
#define bit5 32
#define bit6 64
#define bit7 128
unsigned char current_led;
unsigned char bit_array[]={bit0,bit1,bit2,bit3,bit4,bit5,bit6,bit7};

void setup()
{
          Serial.begin(9600);
  Wire.begin();
        pex.begin();
       // pex.SetPullups(0,2);
  pex.SetPortB(1);
}
void loop()
{
  // pex.SetPortB(1);
  
  /*if (current_led==8)
  {
   current_led=0;
  }
    Serial.println(bit_array[current_led]);
  pex.SetPortB(0xFF);
  current_led++;

  delay(500);*/
}


* IMG_8895.JPG (2747.04 KB, 4000x3000 - viewed 42 times.)
« Last Edit: April 29, 2012, 08:09:43 pm by Mr_arduino » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 220
Posts: 13834
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

to start

#define bit0 0

should be

#define bit0 1


as current led is 0 I think no led is set ...
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8913
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The second line of the datasheet says "I/O pins default to input".  Do you need to set your output pins as outputs?

The outputs are Open Drain which means they switch between DISCONNECTED and GROUND.  Do you have the LED connected between +5 and the output (with an appropriate current limiting resistor in series)?
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Sr. Member
****
Karma: 11
Posts: 349
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The libary that I am using sets them all to output when I call begin()
Code:
void MCP23018::begin(void)
{
// Set all pins to outputs
Serial.println("started mcp23018");
writePairToRegister(IODIRA,0,0);
}
johnwasser you mean something like this
Code:
gnd   5v
 |     |
 |     |
 |      R (220}
 led-  led+
 Vss   gpio
That is what I did and they are still all on.


* IMG_8896.JPG (2436.57 KB, 4000x3000 - viewed 37 times.)
Logged

Pages: [1]   Go Up
Jump to: