Use the same pin as digital output and analog input with an ARM (sam3x / Arduino Due)

adcarduinoarmgpiooutput

I have an application where I need to use one pin as a digital output and analog input. I switch between input and output at a "high" frequency (>1 kHz) and it takes to much time to disable and enable the ADC-Channel all the time. When the ADC-Channel is enabled, it's not possible to use the pin as output pin and set it ti low or high. The voltage level will be at (Vgnd – Vcc)/2.

This works with the AVR Arduino boards (like the Arduino Uno) but not with the ARM version (like the Arduino due).

Best Answer

Here is a work around: Tie two pins electrically together.

  • One pin configured as digital tri-state output;
  • One configured as analog input.

Then use the digital pin to set a HIGH or LOW level and switch the digital pin to INPUT (tri-state) while you read the analog voltage from the analog pin.