I am trying to build a 36-line cable tester, using the Digistump DigiX (99 i/o pins). Digital pins 0-35 are outputs, connected via the cable in question, to (in a perfect world) digital input pins 36-72. The plan is to have 36 neopixels (to conserve DigiX pins), one corresponding to each line in the cable. Currently they light up green for connection and red for no connection.

It's easy to check if output 0 goes to input 36, but there are more potential problems in a cable than no connection...

What if there is a short and output 0 goes to 36 and 42? It will still show up as correct when it tests 0 to 36... I somehow need to "ask" it what, if any, inputs (pins 36-72) are HIGH when only output 0 is HIGH.

I'm not sure how I'm going to display this extra data yet (Lcd maybe? Or maybe any pins shorted together all use a unique led color...), but I want to make sure the idea will work before I move on to that. Here is what I have working so far, just using a 3-line cable for now. And yes, I'm new to this. Any advice would be greatly appreciated!

#include <FastLED.h>
#define NUM_LEDS 3
#define LED_PIN 6
#define brightness 25
int var = 0;

void setup() {
  for (int sendPins=0; sendPins <= 2; sendPins++) {
    pinMode(sendPins, OUTPUT); }

  for (int recPins=3; recPins <= 5; recPins++) {
    pinMode(recPins, INPUT); }

    FastLED.addLeds<NEOPIXEL, LED_PIN>(leds, NUM_LEDS);

void loop() {
  while (var < 3) {    //so it only runs once for each line in the cable.
  for (int sendPins=0; sendPins < 3; sendPins++) {
    digitalWrite(sendPins, HIGH);

    int recPins = map(sendPins, 0, 2, 3, 5);  //made more sense to me than another for loop.

     int recPin = digitalRead(recPins);
     if (recPin == HIGH)
      leds[sendPins].g = brightness;
      leds[sendPins].r = 0;
      leds[sendPins].r = brightness;
      leds[sendPins].g = 0;

      digitalWrite(sendPins, LOW);
      delay(250);      //just for testing so i know it's going through them all.
  • 1
    Low-level access to the ports, which will give you all input bits at once. Sep 20, 2014 at 5:11
  • 1
    If you are testing for shorts, but sure to only set one pin to output at a time. If all pins 0-36 are outputs, and you set pin 0 to HIGH (and the rest to LOW). Then in you example a short between inputs 36 and 42 would mean there's also a short between outputs 0 and 6. Which would mean there is a dead-short between a HIGH and a LOW output, resulting the AVR browning out and maybe even damaging the output pins.
    – Gerben
    Sep 20, 2014 at 15:55

3 Answers 3


There is a technique, which I used some 40 years ago to test for changes on a set of input pins. This can easily be configured to test serially.

Put a 1 on an output pin say 5. Create an integer e.g. 010000 with a 1 in the appropriate position. Read ALL inputs and XOR with the created integer. If one and only one input is 1 the resultant value will be 0. This is easy to implement in a loop just by shifting the 1 left each time.

The technique works if you can read all inputs into a integer. This was OK for our 32 bits, but could be extended.

It is probably easier to code than explain, but depends on what you have to do to read all inputs.


I believe you can read the port register that contains the current state for your pin. The port names take the form of "PORTA" - "PORTE". (The number of port registers varies with the processor in your arduino, and the pin to port mappings are also different across processor models, so this approach will tie you to Arduino models that use the same processor chip)

Another approach would be to store the state you write to each pin to a boolean variable and just read that. Create a central method that takes a pin number and a new state. That method would save the new value to an array, indexed using the pin number, and then also set the pin. You could then write a method that would read the current pin value from the same array .


Use nested loops. Test each pin one by one. For each one pin test, look for the correct wire to be on and check all the others and either look for an "on" or count how many bad on's there are.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.