Site icon Renzo Mischianti

PCF8575 READ INPUTS

Hi! I am trying to read inputs of PCF8575 with ESP32. I had problems reading it with Arduino IDE but I found a "solution". If I define ALL pins as outputs, then I set them to 1 and then define them as inputs. I can read correctly the voltage changes on the inputs. Now I load the same code with platform io and it doesnt work. I use the same version of your library 1.1.1 Could please help me? This is my code: #include "PCF8575.h" PCF8575 pcf(0x20); bool estado=0,value=0,machine_state=0; void set_pcf(); void setup() { // put your setup code here, to run once: Serial.begin(115200); set_pcf(); machine_state=0; // pcf.digitalWrite(10, LOW);//En cuanto cambio el estado de la salida digital el resto se quedan a 0 también. } void loop() { // put your main code here, to run repeatedly: switch (machine_state) { case (0): Serial.println("CASE WAITING"); value=pcf.digitalRead(P1); Serial.println(value); delay(50); break; } } void set_pcf(){ pcf.pinMode(0, OUTPUT); pcf.pinMode(1, OUTPUT); pcf.pinMode(2, OUTPUT); pcf.pinMode(3, OUTPUT); pcf.pinMode(4, OUTPUT); pcf.pinMode(5, OUTPUT); pcf.pinMode(6, OUTPUT); pcf.pinMode(7, OUTPUT); pcf.pinMode(8, OUTPUT); pcf.pinMode(9, OUTPUT); pcf.pinMode(10, OUTPUT); pcf.begin(); Serial.println("RELÉ OFF"); pcf.digitalWrite(0,HIGH); pcf.digitalWrite(1,HIGH); pcf.digitalWrite(2,HIGH); pcf.digitalWrite(3,HIGH); pcf.digitalWrite(4,HIGH); pcf.digitalWrite(5,HIGH); pcf.digitalWrite(6,HIGH); pcf.digitalWrite(7,HIGH); pcf.digitalWrite(8,HIGH); pcf.digitalWrite(9,HIGH); pcf.digitalWrite(10, HIGH); pcf.pinMode(0, INPUT); pcf.pinMode(1, INPUT); pcf.pinMode(2, INPUT); pcf.pinMode(3, INPUT); pcf.pinMode(4, INPUT); pcf.pinMode(5, INPUT); pcf.pinMode(6, INPUT); pcf.pinMode(7, INPUT); pcf.pinMode(8, INPUT); pcf.pinMode(9, INPUT); pcf.pinMode(10, OUTPUT); }
Exit mobile version