adafruit / Adafruit-MCP23017-Arduino-Library

Arduino Library for Adafruit MCP23017
Other
351 stars 204 forks source link

MCP23017 not working with Raspberry Pi Pico #80

Closed sommerper closed 2 years ago

sommerper commented 2 years ago

First of all: Thanks for a great library that I have used with success on multiple occasions with Arduino Nano. I'm trying to get this library to work on the Pico without success. I know the MCP23017 works because I have tested it with an Arduino Nano.

MCP23017 is connected via GP0 (SDA) and GP1 (SCL)

When I run the sketch below mcp.begin_I2C() always returns 0 and the sketch doesn't progress further. I suspect it has something to do with the Pico having 2 I2C busses?

#include <Arduino.h>
#include <Adafruit_MCP23X17.h>

Adafruit_MCP23X17 mcp;
int mcpLedPin = 0;

void setup()
{
  delay(2000);
  Serial.begin(9600);

  if (!mcp.begin_I2C())
  {
    Serial.println("Error.");
    while (1)
      ;
  }
  mcp.pinMode(mcpLedPin, OUTPUT);
}

void loop()
{
  mcp.digitalWrite(mcpLedPin, HIGH);
  delay(1000);
  mcp.digitalWrite(mcpLedPin, LOW);
  delay(1000);
}
caternuson commented 2 years ago

Try GP4 for SDA and GP5 for SCL.

sommerper commented 2 years ago

Hey!

I tried GP4 and GP5 which didn't work either. But you led me on to try the other I2C pins and it turns out GP6 (SDA1) and GP7(SLC1) work!

So thank you for leading on the right path.

Is there a way to define which pins the chip is connected to? Something like

mcp.begin_I2C(9,10)

Then it would be possible to use the other I2C bus on the Pico.

Or maybe that is out of scope for this library?

Anyway, huge thanks to you!

caternuson commented 2 years ago

The default pins are set by the core in the various variants files for the specific boards: https://github.com/earlephilhower/arduino-pico/tree/master/variants For other pins, can try pin reassignment: https://arduino-pico.readthedocs.io/en/latest/

Closing since this is not a library issue.

sommerper commented 2 years ago

Found the info, thanks. I appreciate you taking the time to help anyway.