AnalogRead still breaks output (IDE 1.6.5)

Dear All,

I've been trying to build a relatively simple set-up between TWO DUEs, using LEDs to flash/receive messages between each other in Morse-code style (LedComm).

Up to a point, this went well in 1.5.4 (!) but ever since 1.5.6-r2 things got really BROKEN!!
I've seen and read many other reports regarding DUE's "analogue problems".

In the below example: once I have used AnalogRead() - I can NOT seem to get the analogue-port back to OUTPUT mode. Compiling this code in 1.5.4 works fine and as expected - ANY release afterwards does not - including 1.6.5 (!!) :frowning:

And even though I've seen and read many threads regarding Due's AnalogRead() problems, some also suggested several issues have been fixed in the meanwhile?!?!

// LED anode on Digital Pin 22, Cathode (via 220R) to A0

// for Arduino DUE:
const int anode = 22;
const int cathode = A0;

int reading = 0;

void setup() {
//  analogReadResolution(12);
  pinMode(anode, OUTPUT);
  pinMode(cathode, OUTPUT);
  Serial.begin(9600);
  Serial.println("Analog readings:");
}

void loop() {
  
  // LED off
  digitalWrite(anode, LOW);
  digitalWrite(cathode, LOW);

  // Reverse Charge
  digitalWrite(anode, LOW);
  digitalWrite(cathode, HIGH);
  delay(1);
  
  // Measure
  pinMode(cathode, INPUT);
  reading = analogRead(cathode);    //--> THIS is the culprit (!)

  // report
  Serial.println(reading,DEC);
  
  // Led ON
  //## --> DOES'T WORK SINCE 1.5.6-r2 upto & including 1.6.5 (!)
  //## --> The LED remains OFF and never blinks ON again!
  //## --> Works fine on 1.5.4, blinks -as expected.
  pinMode(cathode, OUTPUT);
  digitalWrite(anode, HIGH);
  digitalWrite(cathode, LOW);
  delay(50);
  
}

Note: My intention is to have multiple "Ledcomm-ports" on each DUE (but only using one at a time), so I will have multiple LEDs on multiple analogue/digital ports. And instead of running it from a main-loop, I've been using the DueTimer library and have the interrupt provide some stable frequency for communication.

Any help or insights would be GREATLY appreciated; to be honest this problem has been haunting me for over a year and has been a real show-stopper for me!!

Danny

You can spend 1h researching on-line, or spend 6 months on it. But, it won't be until you post something to the forum that you'll find what you're looking for :wink:

Due bug: Cannot use pin as digital after analogRead

Bug: analogRead() for Arduino Due should disable previous ADC channel before enabling new one

A work around for my above problem is said to use AnalogRead() on another (spare) port, to release the previous one. Okay... installing 1.6.5 again and giving that a try....

I hope these (clever) guys will release a fix for this as soon as...