Thank you for your input.
The board cannot be powered using just the USB connection on the MCU due to the plethora of the peripherals.
The problem occurs when i unplug the ESP from the PC. I added an additional 100uf capacitor on the VIN and GND pins of the ESP board, that seems to help a bit but still the problem persists.
The MCP is powered by the 5V power supply as the ESP (it is getting powered from the VIN pin that then goes to the regulator to supply the 3.3V for the ESP module)
I already have a 100uf and a 100nf capacitors on the power supply output.
I am starting to suspect the code after some tests i did.
The code is about 2000 lines so i will post the parts responsible for reading the inputs using the MCP23017.
void setup()
{
for(int i=0; i<=9; i++)
{
mcp.pinMode(button[i],INPUT);
mcp.pullUp(button[i],LOW);
}
}
void loop()
{
if((millis()-input_read_counter) >= 250)
{
read_inputs();
input_read_counter = millis();
}
}
void read_inputs()
{
//Buttons
for(int i=0; i <=9; i++)
{
if(mcp.digitalRead(button[i]) == HIGH)
{
delay(10);
if(mcp.digitalRead(button[i]) == HIGH)
{
button_pressed[i]=true;
Serial.print("Button ");
Serial.print(i);
Serial.println(" pressed");
}
}
}
}