Site icon Renzo Mischianti

Connecting esp32 with PCF8574

Hello Renzo, love your post about PCF8574. I'm doing now a engineer project for my degree and i have a problem. Im using a freenove esp32-wrover-cam(i can post a link to a pinout of this esp32). Pinout: https://makeradvisor.com/wp-content/uploads/2023/02/Freenove-ESP32-Wrover-CAM-pinout.jpg I'm using a cam and wifi on this board, and also i need 7 pins to run other elements (3 buttons, 2 i2c(SDA SLC) for a 64x128 oled display, 1 pin to control POWER LED converter and 1 pin to control transistor controling a small motor). Because of my need of usage a cam and wifi i only left with two ports, 32 and 33, because CAM is disabling all cam ports and wifi is disabling all ACD2 ports. And one of sollutions i found is i2c expander like PCF8574, I managed to emulate i2c on 32 and 33 ports to turn on an display so i thought it would work with expander that way. I bought PCF8574 and i connected it with esp32 esp32 -> pcf8574 vcc -> vcc GND->GND 32 -> SCL 33-> SDA I tried to programm a simple code to test a button state read, but it doesn't work #include <Wire.h> #include "PCF8574.h" // Instantiate Wire for generic use at 400kHz TwoWire I2Cone = TwoWire(0); // Instantiate Wire for generic use at 100kHz TwoWire I2Ctwo = TwoWire(1); // Set i2c address PCF8574 pcf8574(&I2Ctwo, 0x20); //PCF8574 pcf8574(&I2Ctwo, 0x20, 32, 33); // PCF8574(TwoWire *pWire, uint8_t address, uint8_t interruptPin, void (*interruptFunction)() ); // PCF8574(TwoWire *pWire, uint8_t address, uint8_t sda, uint8_t scl, uint8_t interruptPin, void (*interruptFunction)()); //#define I2C_SDA 33 //#define I2C_SCL 32 //Wire.begin(I2C_SDA, I2C_SCL); void setup() { Serial.begin(115200); // put your setup code here, to run once: I2Cone.begin(33,32,400000); // SDA pin 33, SCL pin 32, 400kHz frequency pcf8574.pinMode(P2, INPUT_PULLUP); pcf8574.begin(); } void loop() { // put your main code here, to run repeatedly: int buttonState = pcf8574.digitalRead(P2); Serial.println(buttonState); } I connecter the bottom with P2 port and it doesn't work. I don't know if my esp32 is connecting to this expander or not. Also another important question, can I emulate a SDA and SCL ports for my display on PCF8574 ports(P0-P7), or i can use other SDA SCL ports on other side of the PCF8574 board? If not then only solluction i have is to use 2 esp32 for this project.
Exit mobile version