I configured D12 as input with pullup, D9 as output. I would expect D12 to read a stable HIGH (being unconnected and having pullup), but instead it reads the value of D9. This happens on a naked Nano without any hardware attached whatsoever. As a sanity check, I tested it on two different Nanos, the result is the same on both.
Below a simple code to replicate the problem, the values read on D12 will follow the value of D9 instead of being stable 1.
Maybe the pullups are not the problem. Maybe there is a short between the tracks of those those 2 pins somewhere on the Nano board.
Use your multimeter to measure the resistance between those two pins, while the Nano is disconnected. I get about 16~17K between pin 12 and most other digital pins.
Have you tried other pairs of pins to see if you can get the same problem?
My "I really don't think so" meter was firmly in the red, but I tried your code on a couple of different clone Nanos I had here and the value read from D9 was not influenced on either of them by the value of D12. And looking at the PCBs with a magnifier, the traces for the two pins don't go anywhere near each other on either of my boards.
I think this could be one of those "the bitterness of poor quality remains long after the sweetness of low price is forgotten" moments.
In the meantime I realized that the problem may not be the poor quality cheap chip, but the fact that I forgot to tell an important piece of information (for which I apologize, I didn't realize how important it was!!!): it is not a simple Nano, but an RF-Nano (from a batch initially bought for another project).
And the RF-Nano seems to have an onboard nRF24L01+ chip connected to D9-D13. The chip still allows the use of these pins as output pins (well, with a potential unexpected behavior in radiofrequency...), but it seems D12-13 cannot be used as input pins.
So I believe the mystery is solved. Thanks again for your time, and I apologize for hiding this information!!!
Yep, D9 is the chip enable signal for the nRF24L01+ chip, that's where the interference came from. Cutting the D9-D10 wires on the RF-Nano PCB miraculously solved the problem, so this is a short term cure until the batch of regular Nanos arrives.
Sorry again for this, I didn't realize how important piece of information the RF part in the name was!!!