Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By shoelessone
#32463 Is there a "library" or something of the sort to allow me to easily use an IO expander (specifically I'm interested in the MCP23017)?

When I google, I find lots of random talk about i2c, etc, but it's unclear to me if something is built in that I can use, or if not if there is a current "best" library/package/etc I should use.

FWIW, I'm using the MCP23017 to independently control 8 LEDs. At least that's the plan :).

Thank you!
User avatar
By shoelessone
#32486 Thank you martin! You were exactly the person I thought of when I posted this question (you recommended the MCP23017 in the first thread I posted on this forum a while back... I've come a ways since then, but I'm still basically figuring everything out step by step) :).

I really really appreciate it, I'll check out the library!

Also, if you read this, another stupid question that I'll find out soon enough and I think I already know but I'd like to confirm: In my use case I'll be powering 8 LEDs (10mA roughly each, which I believe is fine for the mcp23017), but I'm wondering where I should get "power" from. Can I just hook up Vcc and Ground from the esp8266? I don't want to "steal" power from the esp8266, or run too much current "through" the chip, but if I use the Vcc and Ground pins on the 8266 I'm basically just "sharing" power with it, is that correct? So assuming my power supply can handle the current draw (which in theory shouldn't be a problem as it's rated to 1A), that should be OK? Does this make sense/is it true?

Thanks again!
User avatar
By shoelessone
#32508 Bonus question: Do I have to set the GPIO 0 and GPIO 2 pins in any special way in my code? I have what I'd consider about as simple of an example as possible, and no luck.. Here is my code

Code: Select all#include <Wire.h>
#include "Adafruit_MCP23017.h"

Adafruit_MCP23017 mcp;
 
void setup() { 
  mcp.begin();      // use default address 0

  mcp.pinMode(0, OUTPUT);

}



void loop() {
  // The LED will 'echo' the button
  mcp.digitalWrite(0, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  mcp.digitalWrite(0, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
}