Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By martinayotte
#27956 Using the pinout of the MCP23017 here :
Image
Place all VSS/A2/A1/A0 to GND of the ESP, VDD to 3.3V VCC, add 4K7 PullUps to RES/SDA/SCL pins, and connect SDA to GPIO0 and SCL to GPIO2.
Then, you can use Adafruit_MCP23017, as is if I remember, and initialize it in you sketch with Wire.begin(0, 2) and Adafruit_MCP23017 mcp; along with mcp.begin()
User avatar
By johntech2014
#27965 I remember, and initialize it in you sketch with Wire.begin(0, 2)

Thank you very much!! This was the piece of the puzzle I was missing. I had found all the connections and wiring about an hour ago on another site but I couldn't get the code to work. Once I added in Wire.begin(0,2) everything started to work.!! Below is the working sketch I'm using with a ESP8266-01 !!

Now the next step is to get the WIFI setup so I can turn on and off the LED's via a web page using this setup :D

Code: Select all#include <Wire.h>

void setup() {
  // put your setup code here, to run once:

   // set I/O pins to outputs
  Wire.begin(0, 2);

  Wire.beginTransmission(0x20);
  Wire.write(0x00); // IODIRA register
  Wire.write(0x00); // set all of port A to outputs
  Wire.endTransmission();
  Wire.beginTransmission(0x20);
  Wire.write(0x01); // IODIRB register
  Wire.write(0x00); // set all of port B to outputs
  Wire.endTransmission();
}
void binaryCount()
{
  for (byte a = 0; a < 8; a++)
  {
    Wire.beginTransmission(0x20);
    Wire.write(0x12); // GPIOA
    Wire.write(a); // port A
    Wire.endTransmission();
    Wire.beginTransmission(0x20);
    Wire.write(0x13); // GPIOB
    Wire.write(a); // port B
    Wire.endTransmission();
    delay(1000);
  }
}
void loop()
{
  binaryCount();
  delay(500);
}

John
User avatar
By martinayotte
#27966 Take a look also at the Adafruit_MCP23017, you will see that it really ease the MCP23017 usage by providing similar function found on Arduino :

Code: Select all    mcp.pinMode(3, OUTPUT);
    mcp.digitalWrite(0, HIGH);
    mcp.pinMode(14, INPUT);
    mcp.pullUp(14, HIGH);
    int button = mcp.digitalRead(14);
User avatar
By johntech2014
#27972 I just tried the Adafruit library you suggested and it didn't allow me to change the clock and data pins. ex Wire.begin(0, 2) in my sketch - mcp.begin() in theirs. I tried mcp.begin(0, 2) . This is the error I got
^
C:\Users\Owner\Documents\Arduino\libraries\Adafruit-MCP23017-Arduino-Library-master/Adafruit_MCP23017.h:27:8: note: candidate expects 0 arguments, 2 provided
no matching function for call to 'Adafruit_MCP23017::begin(int, int)'

Not knowing how or what to change in the library to allow this, I'll have to stick with my version.

Thank you

John