Home › Forums › The libraries hosted on the site › PCF8575 16bits i2c digital I/O expander › PCF8575 I/O Expander with ESP32 to read multiple IR Sensor module
- This topic has 2 replies, 2 voices, and was last updated 3 years, 11 months ago by Felanino. 
Viewing 2 reply threads
	
- 
		AuthorPosts
- 
		
			- 
4 December 2021 at 03:47 #16905Hi Mr.Renzo, I need help using PCF8575 with esp32. My project want to use PCF8575 to read 45 IR sensor, i already follow your tutorial and succeed using button as in input, but for IR sensor i have no idea how to implement it. Can you give some idea about the connection and the codes then i can test it? Felani 
- 
4 December 2021 at 08:57 #16909Hi Felanino, 
 I found an example about that for pcf8574, but I think you can reuse that for pcf8575 also.Here an image of Arduino connection schema 
  Here the complete code #include "Arduino.h" #include "PCF8574.h" const byte INTERRUPTED_PIN = 2; // Function interrupt void infraRedActive(); // Set i2c address PCF8574 pcf8574List [] = { PCF8574(0x20, INTERRUPTED_PIN, infraRedActive), PCF8574(0x21, INTERRUPTED_PIN, infraRedActive) } ; bool irActive = false; int i = 0; uint8_t val = -1; const int pcf8574Count = 2; void setup() { Serial.begin(9600); for ( i = 0; i < pcf8574Count ; i++) { // Set pinMode to OUTPUT pcf8574List[i].pinMode(P0, OUTPUT); pcf8574List[i].pinMode(P1, OUTPUT); pcf8574List[i].pinMode(P6, INPUT); pcf8574List[i].pinMode(P7, INPUT); Serial.print("Init pcf8574..." + i ); if (pcf8574List[i].begin()) { Serial.println("PCF8574 INIT SUCCESS "); } else { Serial.println("PCF8574 INIT FAILED "); } } } void loop() { delay(500); doOperation(pcf8574List[0], 1); doOperation(pcf8574List[1], 2); irActive = false; } void doOperation(PCF8574 pcf8574, int no) { pcf8574.digitalWrite(P0, LOW); if (irActive) { Serial.println(no); pcf8574.digitalWrite(P0, HIGH); pcf8574.digitalWrite(P1, LOW); val = pcf8574.digitalRead(P6); if (val == 0) { Serial.print("P6 "); Serial.println(val); } val = -1; val = pcf8574.digitalRead(P7); if (val == 0) { Serial.print("P7 "); Serial.println(val); } delay(1000); pcf8574.digitalWrite(P1, HIGH); val = -1; } } void infraRedActive() { //Serial.println("*"); irActive = true; }Thanks to adarshkumarsingh83 Bye Renzo 
- 
4 December 2021 at 09:09 #16910Many thanks Mr.Renzo. I will try and later will update here 
 
- 
- 
		AuthorPosts
Viewing 2 reply threads
	
- You must be logged in to reply to this topic.


 
 
																			


 
