ESP32 firmware to interact with MCP23008

Is it possible to control the relays using only ESP32 and firmware?
I’ve been looking at examples online and some other forum answers but I’m not sure if I need to use some other interface for i2c communication.

I’ve been loading MCP23008 examples to the ESP32 but keep getting :

MCP23008 Disconnected!

My ideal solution would be just to be able to load some arduino sketch to the ESP32 and be able to interact with the MCP23008 GPIOs.

Thanks in advance and sorry if my question has an obvious/simple answer.


this error will come

  1. wiring issue
  2. wrong address ( check your i2c address)

Should I use the default ESP32 pins for i2c communication?

By using the proper pins, would I be able to interact with the relays?

yes you can use all default ESP32 settings.

the lib will work as soon as i2c address is correct

So far I have tried using the default pins for the i2c connection and also using the 18,19 gpios, but keep getting the “MCP23008 Disconnected!” message.

I have not done any wiring, I just took the product that includes the ESP32, plugged it in and uploaded this code:

Would you happen to know what am I doing wrong?
Your help is very much appreciated.

#include <Wire.h>
#include <MCP23008.h>

MCP23008 mcp;

void setup(void)


// The address can be changed making the option of connecting multiple devices
mcp.getAddr_MCP23008(MCP23008_DEFAULT_ADDRESS);             // 0x20
mcp.pinMode(4, OUTPUT);         // Pin 0 and Output Mode


void loop(void)
byte error;
int8_t address;

address = mcp.mcp_i2cAddress;
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
error = Wire.endTransmission();
if (error == 0)
    uint8_t result;

    Serial.println("Getting Relay Response from MCP23008");
    Serial.println(" ");
    mcp.digitalWrite(4, HIGH);
    Serial.println("Turning Relay '5' ON");
    Serial.println(" ");
    mcp.digitalWrite(4, LOW);
    Serial.println("Turning Relay '5' OFF");
    Serial.println(" ");
    Serial.println("        ***************************        ");
    Serial.println(" ");
    Serial.println("MCP23008 Disconnected!");
    Serial.println(" ");
    Serial.println("        ************        ");
    Serial.println(" ");


can you run the i2c scan and see what address you get.
can you share your setup picture as well

I ran the i2c scanner and did not find any device.
Do you know what could I be doing incorrectly?

This is the picture of my setup:

you will need 12V supply as well.
can you share your scan code