Hi,
I'm running a very simple sketch to test an adafruit MCP23008 IC, using the adafruit library on an ESP32 Dev-Kit. The code for the sketch is;
#include <Adafruit_MCP23X08.h>
Adafruit_MCP23X08 mcp;
int ledArray[] = {0, 1, 2, 3, 4, 5, 6, 7};
void setup() {
delay(1000);
Serial.begin(9600);
mcp.begin_I2C();
int i = 0;
for (i; i < 8; i++) {
mcp.pinMode(i, OUTPUT);
mcp.digitalWrite(i, LOW);
}
}
void loop() {
int i = 0;
for (i; i < 8; i++) {
mcp.digitalWrite(ledArray[i], HIGH);
Serial.print("Active Pin: ");
Serial.println(i);
delay(1000);
mcp.digitalWrite(ledArray[i], LOW);
Serial.print("Deactiving Pin: ");
Serial.println(i);
}
}
I don't know how to draw a circuit diagram online but my pinout for the MCP23008
1. SCL line to ESP32 pin D22 <I2C Clock line>
2. SDA line to ESP32 pin D21 <I2C Data line>
3. Add2 -> Ground of ESP32
4. Add1 -> Ground of ESP32
5. Add0 -> Ground of ESP32 <should give MCP23008 address of 20 which is adafruit default>
6. Reset -> +5V from ESP32 VIN
7. NC (Float) therefore disconnected
8. INT (Float) therefore disconnected
9. VSS -> Ground on ESP32
10. GPIO 0pin -> LED -> 1k Resistor -> Ground of ESP32.
11. GPIO 1pin -> LED -> 1k Resistor -> Ground of ESP32.
12. GPIO 2pin -> LED -> 1k Resistor -> Ground of ESP32.
13. GPIO 3pin -> LED -> 1k Resistor -> Ground of ESP32.
14. GPIO 4pin -> LED -> 1k Resistor -> Ground of ESP32.
15. GPIO 5pin -> LED -> 1k Resistor -> Ground of ESP32.
16. GPIO 6pin -> LED -> 1k Resistor -> Ground of ESP32.
17. GPIO 7pin -> LED -> 1k Resistor -> Ground of ESP32.
18. VSS (+5V) -> ESP32 VIN
The ESP32-DevKit is on a bread board, with dupont cables running to another breadboard with the MCP23008 IC. All points have been tested for continuity from ESP32 pins to MCP23008 pins (to rule out cable issues) and +5 voltage has been confirmed too on pins requiring them.
When I use and arduino I2C scanner I can confirm that the I2C portion is working;
16:22:56.084 -> Scanning...
16:22:56.130 -> I2C device found at address 0x20 !
16:22:56.130 -> done
When I run my sketch I would expect the LEDs to sequentially turn on and off again, and for the most part they do. However, quite often and seemingly random (not in sequence to the loop) ALL or MOST of the LED's turn on simultaneously, and only turn off when the sequence forces them to toggle on / off again.
N.B. This issue seemingly reduces and the symptoms get better when I run from a mains powered USB charger and is worse when plugged into my laptop USB socket to power the ESP32-DevKit.
N.B.2. I have swapped out three different MCP23008 ICs to rule out a single point of failure of the IC.
N.B.3. I purchased a multipack of these ESP32-DevKits (ESP-WROOM32) from amazon, could it be that there is a fault with the 'cheap' ESP boards that i have picked up?
This is part of a wider project for me and I'm trying to work out how best to use 3x MCP23008 to add significantly more (24 more) GPIO than a single ESP32-DevKit has by default.
I additionally tried running two MCP23008 chips (one with ADD1+2 -> +5V for an address of 26 (mcp2.begin(6) but i couldn't get this to respond in the sketch, despite both being visible on the I2C scanner at address 20+26). I'm unsure if this is the same ???noise??? issue that i'm seeing with just one IC as described again or an unrelated issue.
Thanks for taking the time to read and I appreciate any comments especially if there is a better way to either wire it up, sketch test it. Currently I'm unable to source MCP23017 ICs which would add more pins easier ... the great chip shortage!
edited to format sketch
Thanks again
Josh