you know the problem that you have a cable with a connector on one side but sigle wires on the other side? I often have to mount RS232 cables for example on a PCB. It's always a pain to find out which wire belongs to which pin of the connector. Therefor I built a smal test device based on a Digispark, a LCD-Shield and a Port-Expander:
On the Port-Expander on the top of that stack will be a test cable mounted that end up in a 9-Pin SubD connector. For the 9th pin I use PB5 of the digispark. In addition there is a measure tip connected with GND. If you have now to find out which wire of a give RS232 cable belongs to which PIN, simply plug the connector of the cable into the 9-Pin SubD of the test device. If you now type with the measure tip to the unisolated end of a single wire, the LCD display tells you the pin number in the first row (ACT PIN) and in addition also in the second row (labeld as PREV PIN). If you release the wire, the display number of ACT PIN will be cleared to indicate the currently no wire is identified. As PREV PIN it is still displayed to help you to remember which wire it was.
If the wire is connected to more then one pin then the device identifies this as a short circuit and provides a message on the display.
here the requiered programm code:
// ------------------
// required libraries
// ------------------
#include <TinyWireM.h> // I2C
#include <LiquidCrystal_I2C.h> // LCD
// ----------------
// define constants
// ----------------
#define LCD_ADDR 0x27 // I2C Address for LCD controller
#define PORT_ADDR 0x20 // I2C Address for Port-Expander
// ----------------
// global variables
// ----------------
LiquidCrystal_I2C lcd(LCD_ADDR,16,2); // object instance for LCD
boolean data_received = false; // flag to identify if data
// are loaded or not
uint8_t actPin = 0; // reminder for actual pin
uint8_t prevPin = 0; // reminder for last pin
// ---------------
// setup procedure
// ---------------
void setup(){
// initialize I2C interface
TinyWireM.begin();
// initialize LCD display
lcd.init();
// switch on backlight
lcd.backlight();
// write fix text
lcd.print(" ACT PIN:");
lcd.setCursor(0,1);
lcd.print("PREV PIN:");
// initialize Port-Expander
writePort(PORT_ADDR, 0xff);
// define PIN 6 as input
pinMode(5, INPUT);
// activate internal Pull-Up
digitalWrite(5, HIGH);
}
// --------------
// main procedure
// --------------
void loop(){
byte data;
int count=0;
int pin=0;
int i=0;
// read Port-Expander
data=readPort(PORT_ADDR);
// check if Port-Expander sent data
if (data_received){
// check pin state of Port-Expanders returned value
// walk thru pins with loop
for (i=0; i<8; i++){
// pin pulled down by measuring tip
if (bitRead(data, i)==false){
// Pin recognized
pin = i + 1;
count++;
}
}
// check additional input pin from Digispark
if (digitalRead(5)==LOW){
pin = 9;
count++;
}
// set cursor position in display
lcd.setCursor(10, 0);
// output depending on count of recognized pins
if (count==0){
// no pin recognized
lcd.print("NO ");
actPin = 0;
} else if (count==1){
// one valid pin recognized
// if ACT PIN is different
// clear output and write pin number
if (actPin != pin){
lcd.print(" "); // clear previous output
lcd.setCursor(10, 0); // repositioning cursor
lcd.print(pin); // write pin number
actPin = pin; // store pin number
}
// if PREV PIN is differnt
// clear output and write pin number
if (prevPin != pin){
lcd.setCursor(10, 1); // repositioning cursor
lcd.print(" "); // clear previous output
lcd.setCursor(10, 1); // repositioning cursor
lcd.print(pin); // write pin number
prevPin = pin; // store pin number
}
} else {
// more then one pin recognized --> short-circuit
lcd.print("SHORT");
}
}
}
// -----------------------------------------
// procedure for reading value Port-Expander
// -----------------------------------------
byte readPort(int address) {
byte data=0xff;
TinyWireM.requestFrom(address,1);
if(TinyWireM.available()){
data=TinyWireM.receive();
data_received=true;
}
else {
data_received=false;
}
return data;
}
// -----------------------------------------------------
// procedure for writing a byte value to a Port-Expander
// -----------------------------------------------------
void writePort(int address, byte data) {
TinyWireM.beginTransmission(address);
TinyWireM.send(data);
TinyWireM.endTransmission();
delay(5);
}
If you have to identify more then 12 pins (that's the maximum of that configuration), you can add up to 7 more Port-Expander (with unique address pin configuration) to the stack. This would bring you up to 68 pins. If you change the version of the PCF8574 you will be able to add another 8 expanders. That would end up in a device that could identify 132 pins ... and i guess that would be enough for most cables

. Of course you have also to adjust the code ... but that is not too difficult. Let me know if you are facing problems.
I will post another picture of the whole test device once I have finished the housing if someone is interested in