0

MCP23017 with Grand Central
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

MCP23017 with Grand Central

by Mnuckols on Fri Oct 23, 2020 8:03 pm

I'm trying to use the MCP23017 with the Grand Central M4, but it cannot read the pin values. I'm using the button example from the Adafruit MCP23017 Arduino Library. When I hooked it up to the Arduino Uno, everything worked fine. I migrated it to the Grand Central, and the button pin always reads HIGH (never changes to LOW). The only change I made to the circuit is pins 12 and 13 going to SCL and SDA through a 10k resister, and I removed the LED, so I just write to the serial console on button press. Is that library compatible with the Grand Central?

Below is my code:

Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>
#include "Adafruit_MCP23017.h"

// Basic pin reading and pullup test for the MCP23017 I/O expander
// public domain!

// Connect pin #12 of the expander to Analog 5 (i2c clock)
// Connect pin #13 of the expander to Analog 4 (i2c data)
// Connect pins #15, 16 and 17 of the expander to ground (address selection)
// Connect pin #9 of the expander to 5V (power)
// Connect pin #10 of the expander to ground (common ground)
// Connect pin #18 through a ~10kohm resistor to 5V (reset pin, active low)

// Input #0 is on pin 21 so connect a button or switch from there to ground

Adafruit_MCP23017 mcp;
 
void setup() { 
  Serial.begin(9600);

  // Wait for serial port to be opened, remove this line for 'standalone' operation
  while (!Serial) { delay(1); }
  delay(500);

  Serial.println("Beginning MCP");
 
  mcp.begin();      // use default address 0

  mcp.pinMode(0, INPUT);
  mcp.pullUp(0, HIGH);  // turn on a 100K pullup internally

  //pinMode(13, OUTPUT);  // use the p13 LED as debugging

  Serial.println("Here");
}



void loop() {

  if (mcp.digitalRead(0) == HIGH) {
    Serial.println("HIGH");   
  }
  else {
    Serial.println("LOW");
  }

  delay(100);
 
  // The LED will 'echo' the button
  //digitalWrite(13, mcp.digitalRead(0));
}

Mnuckols
 
Posts: 25
Joined: Wed Sep 30, 2020 9:18 am

Re: MCP23017 with Grand Central

by dastels on Fri Oct 23, 2020 9:36 pm

Why are you going through resistors?

It should be fine on the grandcentral.

I've generally found that I need to connect a digital output to the 23017's reset pin and reset it (pulsing the rest pin low for a few mS) in setup().

Dave

dastels
 
Posts: 6849
Joined: Tue Oct 20, 2015 3:22 pm

Re: MCP23017 with Grand Central

by Mnuckols on Fri Oct 23, 2020 10:10 pm

Initially I didn't have any resisters on the SCL and SDA wires, but the code just hung on the mcp.begin() line. I read somewhere (although I can't find it now) that some boards require a 10k resistor there, so I tried it and the code didn't hang anymore. I'll give your suggestion about the reset a try. Thanks!

Mnuckols
 
Posts: 25
Joined: Wed Sep 30, 2020 9:18 am

Re: MCP23017 with Grand Central

by dastels on Sat Oct 24, 2020 3:18 pm

I2C lins need a pullup resistor near the device (not the controller) and it's typically a 10K. All of Adafruit's breakouts include them, but if you're wiring up the 23017 yourself then you'll need a 10K between 3.3v and SDA and another between 3.3v and SCL.

Dave

dastels
 
Posts: 6849
Joined: Tue Oct 20, 2015 3:22 pm

Re: MCP23017 with Grand Central

by Mnuckols on Sat Oct 24, 2020 3:52 pm

Hi Dave,

I tried your suggestion with the reset pin (or at least I think it set it up correctly). I used pin 7 on the Grand Central. I tried it with both LOW and HIGH and there is no change to the behavior. Hitting the button still does nothing. I've included the code below.

Code: Select all | TOGGLE FULL SIZE
void setup() { 
  Serial.begin(9600);

  // Wait for serial port to be opened, remove this line for 'standalone' operation
  while (!Serial) { delay(1); }
  delay(500);

  Serial.println("Beginning MCP");
   
  mcp.begin();      // use default address 0

  // Dave's suggestion
  pinMode(7, OUTPUT);
  digitalWrite(7, LOW);
  delay(100);

  mcp.pinMode(0, INPUT);
  mcp.pullUp(0, HIGH);  // turn on a 100K pullup internally
}

Mnuckols
 
Posts: 25
Joined: Wed Sep 30, 2020 9:18 am

Re: MCP23017 with Grand Central

by Mnuckols on Sat Oct 24, 2020 4:22 pm

Here is a fritz of my circuit, except I'm using the Grand Central instead of the metro and the resistors are 10k.

MPC23017_Button.jpg
MPC23017_Button.jpg (922.43 KiB) Viewed 122 times

Mnuckols
 
Posts: 25
Joined: Wed Sep 30, 2020 9:18 am

Re: MCP23017 with Grand Central

by dastels on Sat Oct 24, 2020 9:07 pm

When you set up the reset output set it high. Then set it to low and a few milliseconds and then high again, and leave it high.

dastels
 
Posts: 6849
Joined: Tue Oct 20, 2015 3:22 pm

Re: MCP23017 with Grand Central

by dastels on Sat Oct 24, 2020 9:21 pm

Right. That circuit is wrong. Connect SCL and SDA directly together, and a 10K to each (with the other ends of each resistor to 3.3v).

Also, power the 23017 with 3.3v since you're using it with a 3.3v MCU.

Dave

dastels
 
Posts: 6849
Joined: Tue Oct 20, 2015 3:22 pm

Re: MCP23017 with Grand Central

by Mnuckols on Sun Oct 25, 2020 7:16 pm

Hi Dave,

Those wiring changes worked! However, I was able to get it to work without the reset high,low,high code. I have the reset pin on the 23017 going through a 10k resistor to 3.3v. Thanks for your help.

-Matt

Mnuckols
 
Posts: 25
Joined: Wed Sep 30, 2020 9:18 am

Re: MCP23017 with Grand Central

by dastels on Mon Oct 26, 2020 9:58 am

Cool. Watch for odd behavior ... it may be reset related.

dastels
 
Posts: 6849
Joined: Tue Oct 20, 2015 3:22 pm

Please be positive and constructive with your questions and comments.