Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with MCP23017 library #56

Closed
RolfSste opened this issue Mar 9, 2021 · 7 comments
Closed

Problem with MCP23017 library #56

RolfSste opened this issue Mar 9, 2021 · 7 comments

Comments

@RolfSste
Copy link

RolfSste commented Mar 9, 2021

Adafruit MCP23017 library includes

void Adafruit_MCP23017::pinMode(uint8_t p, uint8_t d) { updateRegisterBit(p, (d == INPUT), MCP23017_IODIRA, MCP23017_IODIRB); }

Unfortunately INPUT is in Arduino.h 0, which works correct for lot's of uC's,
but not for ESP32, which comes with its own header file.
There, INPUT is defined as 1, so MCP23017 is not correctly initialized.
The Adafruit header file for MCP23017 should include

#define MCP23017_INPUT 0

so that pinMode can be written as

void Adafruit_MCP23017::pinMode(uint8_t p, uint8_t d) { updateRegisterBit(p, (d == MCP23017_INPUT), MCP23017_IODIRA, MCP23017_IODIRB); }

@ladyada
Copy link
Member

ladyada commented Mar 9, 2021

better to change the function to just test if d == INPUT and write 0
please submit a PR :)

@RolfSste
Copy link
Author

RolfSste commented Mar 9, 2021

I have tested the above solution and I think it would be a clean consitent solution for the library.

@ladyada
Copy link
Member

ladyada commented Mar 9, 2021

great, please submit a PR!

@RolfSste
Copy link
Author

Sorry, I'm new to github and have to check out, how to submit an PR. It will take a little bit.

@caternuson
Copy link
Contributor

Please try the newly released 2.0.0 version of the library which should resolve this issue:
https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library/releases/tag/2.0.0

@caternuson
Copy link
Contributor

Closing for now. Should be fixed with 2.0.0 release. Tested on a Feather ESP32 with following sketch.

#include <Adafruit_MCP23X17.h>

#define IN_PIN 0

Adafruit_MCP23X17 mcp;

void setup() {
  Serial.begin(9600);
  Serial.println("MCP23xxx Input Test!");

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

  mcp.pinMode(IN_PIN, INPUT);
}

void loop() {
  Serial.print("Input = "); Serial.println(mcp.digitalRead(IN_PIN ));
  delay(500);
}

and works as expected.

Screenshot from 2021-06-28 08-16-58

@businescat
Copy link

businescat commented Oct 10, 2022

The 2.0.0/2.1.0 library still does not work with esp32 devkit v1 for some reason........ caused me quite a bit of headache. But works with my esp32-s2, so I'm happy it at least works on something. Hopefully this comment willl save someone a headache seems to be very picky about what esp32 it works on so try different ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants