I’m working on interfacing a ZTW523A touch controller with an ESP32 via I2C, but I’m facing issues with I2C timeouts (Wire.h error 5: timeout) and I am unable to detect the device using an I2C scanner. Despite following the recommended setup and adding pull-up resistors, the bus doesn’t seem to communicate with the touch controller.
#include <Wire.h>
#include <Arduino.h>
#include <I2CScanner.h>
#define RESET_PIN D7
#define SCL_PIN D5 // ESP32 GPIO connected to Reset (pin 24)
I2CScanner scanner;
void resetTouchPanel()
{
pinMode(RESET_PIN, OUTPUT);
digitalWrite(RESET_PIN, LOW); // Pull Reset low
delay(5); // Hold for 5ms
digitalWrite(RESET_PIN, HIGH); // Release Reset
delay(1000); // Wait for initialization
Serial.println("Touch panel reset complete.");
}
void resetI2CBus()
{
pinMode(SCL_PIN, OUTPUT);
for (int i = 0; i < 9; i++)
{ // Generate clock pulses
digitalWrite(SCL_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(SCL_PIN, LOW);
delayMicroseconds(10);
}
pinMode(SCL_PIN, INPUT); // Restore SCL to input
}
void setup()
{
Serial.begin(115200);
delay(100);
resetTouchPanel();
Wire.end();
Wire.begin();
Wire.setClock(100000);
delay(100);
resetI2CBus();
scanner.Init();
}
void loop()
{
delay(10);
resetTouchPanel();
scanner.Scan();
}
- Added 2.2kΩ pull-up resistors to SDA and SCL lines (also tried 4.7kΩ).
- Tried lowering the I2C clock speed to 50kHz and 100kHz.
- Ensured the ZTW523A is properly reset (RESETn held low for 1ms, then released, with a 100ms wait before communication).
- Ran the I2C scanner with no devices detected.
- Tested the ESP32 I2C bus with another I2C device (successful detection, confirming the bus works).
Could this be an issue with the ZTW523A initialization sequence or reset behavior? Is there a specific I2C address or configuration I might be missing? Are there additional debugging techniques (e.g. logic analyzer) I should try?
Can someone help me debug this issue? Thank you so much!