utility to make an I/O list

I checked seven pages of google search, couldn't find what I'm looking for.

Which is: a utility which would scan a sketch and produce a list of the I/O pins used and whether they're configured as input or output and whether any are duplicates.

I was thinking this would be useful when merging code.

Does such a thing exist?

Should be straightforward to write a Python program to do that if the coder has been careful to use pinMode() for every pin. But it is not necessary to use pinMode(pin, INPUT) so it would also probably be necessary to check every digitalRead() and analogRead()

It would at least list all the lines you need to check.

...R

I doubt you'll find something like that. To be useful, it would have to be able to parse several situations, such as these:

pinMode(2,INPUT);
#define PIN_WHATEVER 4
pinMode(PIN_WHATEVER,INPUT_PULLUP);
#define START_PIN 5
#define NUMBER_PINS 4
for(int i = 0;i < NUMBER_PINS;i++) {
  pinMode(i+START_PIN,OUTPUT);
}
uint8_t pins[] = {2,5,8,11,4};
for(int i = 0;i < sizeof(pins);i++) {
  pinMode(pins[i],INPUT);
}

Then there's the problem of libraries which set the pinMode internally - e.g. SD.h
It isn't difficult to do this yourself since you just need to search the code for "pinMode" and then make a list of the pins that are referenced.

BTW, this doesn't handle the analog pins which don't need to have pinMode set.

Pete

I think it's better to just have a section at the start of your sketch where you define a variable for every pin. This is best practices so you should be doing that in all your code anyway. You can split the definitions into sections according to the usage of the pin if you want. If there are pins used by libraries that the sketch includes then you can define those pins also, even though they're not used in the sketch, or just add a comment for each. Then when you want to merge code you just compare the pins definitions for each sketch to make sure there are no duplicates.

Another complication I hadn't thought of:

 for (int i = 0; i < numOfInputs; i++) {
    pinMode(inputPins[i], INPUT); // set 8-11 as inputs with pullups [0]=8, etc.
    digitalWrite(inputPins[i], HIGH); // pull-up 20k
  }

I guess it'll just be the search-and-make-a-list technique.

Thanks for the replies.

pert:
I think it's better to just have a section at the start of your sketch where you define a variable for every pin. This is best practices so you should be doing that in all your code anyway. You can split the definitions into sections according to the usage of the pin if you want.

Now on my to do list.

dougp:
I guess it'll just be the search-and-make-a-list technique.

I use the Geany editor and it allows me to highlight (for example) every instance of digitalRead. That make it easy to find stuff.

Of course if you are writing all the programs yourself what @pert says is excellent advice.

...R

Robin2:
Of course if you are writing all the programs yourself what @pert says is excellent advice.

Even if you're merging code that you found somewhere else, you're still going to need to modify it in order to do the merge so going through the code to de-magic-number all the pins should be the first step.

The ability to highlight all instances of a word is the feature I miss most when using the Arduino IDE.

Robin2:
I use the Geany editor and it allows me to highlight (for example) every instance of digitalRead. That make it easy to find stuff.

Of course if you are writing all the programs yourself what @pert says is excellent advice.

...R

It's a mish-mash. The keypad/LCD handler was lifted from LCD menu programming and I need to figure out EEPROM support but the rest is up to me.

I have found the find & replace feature of the IDE useful.