I am trying to activate internal pull-up resistors on a MCP23018 I/O expander.
This is my first I/O expander, so maybe I am missing something basic.
Here is the setup with external pull-up resistors: There are two a grounded buttons and two 2.2k ohm external pull-up resistors on pins GPA0 and GPA1.
Here is the sketch (this works):
#include "Wire.h"
#define ADDR 0x20 // 0x20 is MCP23018 address when ADDR pin is grounded
#define GPPUA 0x0C // pullups bank A
#define GPIOA 0x12 // I/O bank A
void setup()
{
Serial.begin(9600);
Wire.begin(); // MCP23018
}
void loop() // send MCP23018's bank A data and display the data
{
// with external pullups, grounding GPA0 prints 11111110, grounding GPA1 prints 11111101
Wire.beginTransmission(ADDR);
Wire.write(GPIOA);
Wire.endTransmission();
Wire.requestFrom(ADDR, 1);
byte inputs = Wire.read();
if (inputs < 0xFF) // if a button was pressed
{
Serial.println(inputs, BIN); // display in binary
delay(200); // debounce
}
}
Now that I have proven that the circuit works, I want to do the same using internal pull ups.
I remove the external pull-up resistors and attempt to bring up the internal pull-ups.
Here is the sketch (this fails):
#include "Wire.h"
#define ADDR 0x20 // 0x20 is MCP23018 address when ADDR pin is grounded
#define GPPUA 0x0C // pullups bank A
#define GPIOA 0x12 // I/O bank A
void setup()
{
Serial.begin(9600);
Wire.begin(); // MCP23018
}
void loop() // send MCP23018's bank A data and display the data
{
// with internal pullups, just prints a 0 every .2 seconds
Wire.beginTransmission(ADDR);
Wire.write(GPPUA); // internal pull-up resistors on bank A
Wire.write(0xFF); // all pins
Wire.endTransmission();
Wire.requestFrom(ADDR, 1);
byte inputs = Wire.read();
if (inputs < 0xFF) // if a button was pressed
{
Serial.println(inputs, BIN); // display in binary
delay(200); // debounce
}
}
What is the protocol for bringing the internal pull ups on line?
I could not find a tutorial on internal pull ups and some parts of the data sheet are over my head.
Here is the MCP23018 data sheet: http://ww1.microchip.com/downloads/en/devicedoc/22103a.pdf
Here is the Wire library: Wire - Arduino Reference
https://github.com/arduino/Arduino/tree/master/libraries/Wire
Thank you for your advice.
The two lower buttons are not connected to anything: