Go Down

Topic: [solved]mcp23018 not working (Read 860 times) previous topic - next topic

Mr_arduino

Apr 29, 2012, 08:01 pm Last Edit: Apr 30, 2012, 03:09 am by Mr_arduino Reason: 1
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: [Select]

#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);*/
}

robtillaart

to start

#define bit0 0

should be

#define bit0 1


as current led is 0 I think no led is set ...
Rob Tillaart

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

johnwasser

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)?
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Mr_arduino

The libary that I am using sets them all to output when I call begin()
Code: [Select]

void MCP23018::begin(void)
{
// Set all pins to outputs
Serial.println("started mcp23018");
writePairToRegister(IODIRA,0,0);
}

johnwasser you mean something like this
Code: [Select]

gnd   5v
|     |
|     |
|      R (220}
led-  led+
Vss   gpio

That is what I did and they are still all on.

Go Up