hi guys and girls, i was wondering if anyone can help me, Im working on a project where I have a multi purpose connector, the idea is that in one usecase a charger would be connected, and in another use case some GPIO pins would be accessed. I need to distinguish between the use cases, and also know when no connector is present.
I have a gnd and three gpio pins set as input., at the moment im using one gpio shorted to ground to detect when a connector is present for one use case. A seperate GPIO is shorted to gnd to detect the second use case. this however isnt ideal as the GPIO needs to be used for other things. in each use case, the code checks if the pins are shorted to gnd in order to respond.
If I had access to 5v also then I would put a different value resistor in each connector and do an analogRead on the pin, but with only a GND im stumped.
can anyone think of a better way of doing this with just the GND and three GPIO? I could possibly set a GPIO as HIGH during setup and measure the result of analogRead on the other, then set it back as an input.... but that would briefly spike any connected gear with 5V on that line.
thanks for your suggestion, I have set the Analogue IO as input with pullups, then using a 100k resistor and a 22k resistor I can distiguish between which cable is attached to the unit at bootup.
thanks a million.
You would be better off using an external pull up resistor for that. The internal resistance varies quite a lot.
Actually, reading contacts this way is a very common Arduino trick. It's just that you didn't mention a lot of details, such as whether you had an extra pin available, or expected to do this detection via an active signal pin. In other words, whether you have signal lines that are indifferent to resistive sense resistors in parallel.
We get a lot of posts here, where what seem like obvious statements, turn out not to be.
yes, the connector pin in question was being used before to sense if it was connected to GND at bootup with digitalRead. So as it happens all I had to do was switch it to an analogue pin on the arduino and use analogRead instead, allowing a variety of different options at bootup based on the resistor used.
if I were to use an external pullup resistor, what would be a good value to use?