Standalone Arduino test sketches for IS31FL3193 LED driver and PCF8575/PCF8574 relay bring-up (not part of the PlatformIO build), a known-issues note, and two Dart files from the tablet app kept as reference for the comms protocol. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
116 lines
4.7 KiB
Arduino
116 lines
4.7 KiB
Arduino
/*
|
|
* ═══════════════════════════════════════════════════════════════════════════════
|
|
* pcf8575_external_diagnostic.ino — Per-pin write + readback test, external PCF8575
|
|
* ═══════════════════════════════════════════════════════════════════════════════
|
|
*
|
|
* TEMPORARY TEST SKETCH — not part of the Vesper firmware build.
|
|
* Open directly in Arduino IDE and flash it on its own (does NOT go through
|
|
* PlatformIO / src/main.cpp). Delete once the chip is verified.
|
|
*
|
|
* Purpose: isolate whether P00-P02 (indices 0-2) failing to fire is a software
|
|
* problem (write never reaching the chip / shadow register not flushing) or a
|
|
* hardware problem (chip accepts the write but can't sink the pin).
|
|
*
|
|
* For each pin 0-15:
|
|
* 1. Write LOW.
|
|
* 2. Immediately read back via digitalRead() — this tells us what the
|
|
* library's shadow register / the chip itself reports.
|
|
* 3. Hold LOW for HOLD_MS so you can probe the physical pin with a meter.
|
|
* 4. Write HIGH, read back again, hold OFF_MS.
|
|
*
|
|
* How to interpret:
|
|
* - Readback says LOW, meter says ~3.3V -> chip accepted the write but
|
|
* can't sink the pin -> hardware fault (bad driver transistor on that pin).
|
|
* - Readback says HIGH (write didn't take) -> library/addressing issue,
|
|
* not chip damage. Check pin index mapping / I2C bus health on retry.
|
|
* - Readback says LOW, meter says ~0V -> pin is fine.
|
|
*
|
|
* Hardware:
|
|
* - Board: Kincony KC868-A6 (ESP32-D0WD-V3)
|
|
* - I2C bus: SDA = GPIO4, SCL = GPIO15 (see src/main.cpp Wire.begin(4, 15))
|
|
* - Chip: PCF8575, address 0x20 (external expansion board)
|
|
*
|
|
* Library: Adafruit PCF8575 (same library the firmware uses in
|
|
* src/OutputManager/OutputManager.cpp)
|
|
*
|
|
* Convention: ACTIVE-LOW outputs, matching OutputManager::firePhysicalOutput()
|
|
* — LOW = relay energized/fired, HIGH = relay off.
|
|
* ═══════════════════════════════════════════════════════════════════════════════
|
|
*/
|
|
|
|
#include <Wire.h>
|
|
#include <Adafruit_PCF8575.h>
|
|
|
|
// ── Config ───────────────────────────────────────────────────────────────────
|
|
#define I2C_SDA_PIN 4
|
|
#define I2C_SCL_PIN 15
|
|
#define PCF8575_ADDR 0x20
|
|
#define NUM_OUTPUTS 16
|
|
|
|
#define HOLD_MS 3000 // time held LOW — probe the pin during this window
|
|
#define OFF_MS 500
|
|
|
|
#define FIRED LOW // active-low: LOW = relay on
|
|
#define OFF HIGH // active-low: HIGH = relay off
|
|
|
|
Adafruit_PCF8575 pcf;
|
|
|
|
// P00-P02 (indices 0-2) are the pins reported as not firing on the board.
|
|
bool isSuspect(uint8_t i) { return i <= 2; }
|
|
|
|
void allOff() {
|
|
for (uint8_t i = 0; i < NUM_OUTPUTS; i++) pcf.digitalWrite(i, OFF);
|
|
}
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
delay(1000);
|
|
Serial.println();
|
|
Serial.println("=== External PCF8575 — per-pin write/readback diagnostic ===");
|
|
|
|
Wire.begin(I2C_SDA_PIN, I2C_SCL_PIN);
|
|
|
|
if (!pcf.begin(PCF8575_ADDR, &Wire)) {
|
|
Serial.printf("FAILED to initialize PCF8575 at 0x%02X — check wiring/address.\n", PCF8575_ADDR);
|
|
while (true) { delay(1000); }
|
|
}
|
|
Serial.printf("PCF8575 initialized at 0x%02X\n", PCF8575_ADDR);
|
|
|
|
for (uint8_t i = 0; i < NUM_OUTPUTS; i++) pcf.pinMode(i, OUTPUT);
|
|
allOff();
|
|
|
|
Serial.println("Each pin holds LOW for 3s — probe the physical pin with a");
|
|
Serial.println("multimeter during that window. Compare against the printed");
|
|
Serial.println("readback value.");
|
|
Serial.println();
|
|
}
|
|
|
|
void loop() {
|
|
for (uint8_t i = 0; i < NUM_OUTPUTS; i++) {
|
|
const char* tag = isSuspect(i) ? " <-- SUSPECT PIN (P0x reported dead)" : "";
|
|
|
|
bool writeOk = pcf.digitalWrite(i, FIRED);
|
|
delay(10);
|
|
bool readLow = (pcf.digitalRead(i) == LOW);
|
|
|
|
Serial.print("Pin ");
|
|
Serial.print(i);
|
|
Serial.print(" (P");
|
|
Serial.print((i < 8) ? 0 : 1);
|
|
Serial.print(i % 8);
|
|
Serial.print(") -> write_ok=");
|
|
Serial.print(writeOk);
|
|
Serial.print(" readback=");
|
|
Serial.print(readLow ? "LOW" : "HIGH");
|
|
Serial.println(tag);
|
|
|
|
delay(HOLD_MS);
|
|
|
|
pcf.digitalWrite(i, OFF);
|
|
delay(OFF_MS);
|
|
}
|
|
|
|
Serial.println("=== cycle complete, restarting ===\n");
|
|
delay(200);
|
|
}
|