DUE analog input trouble, not working properly

Hello, i recently bought an arduino Due. And while testing the analog input i found it isnt working properly.
However, before saying the analog ports are broken maybe there is something im not aware about the due.

The circuit is very simple. A resistor in series with a photoresistor and then ground. In front of the photoresistor there is a blinking led. So in serial plotter a kind of square wave should be observed. However the valued measured was always constant despite the switching on\off led.

This experiment worked perfcectly in an arduino UNO, so it isnt a circuit problem. Also triying differnt analog ports didnt help. And with analogReadResolution the number shown was bigger but always constant.

I hope there is somthing im missing and not a board issue. If you have any idea or recomendation let me know

A resistor in series with a photoresistor and then ground.

Diagram, please.

AWOL:
Diagram, please.

Done! But there cannot be a simpler circuit than that haha, and it Works very well in an UNO

Post the code you are using to read the analog input pin.

ariel_2077:
But there cannot be a simpler circuit than that haha

Maybe not, but there could have been a better description of it

Okay, even simpler. Im using now exactly the code and circuit that is given in the analogRead reference https://www.arduino.cc/en/Reference/AnalogRead

Using the same code and circuit the differences are clear between my UNO and DUE, do you think this is hardware or software??

Also i just realized this post maybe isnt in the right topic :frowning: and should be moved to troubleshouting.

I left attached the data taken from the analog input in both an UNO and a DUE, using a 10k potentiometer.

Please post your sketch exactly as you are using it. We aren't asking this to be awkward, its how problems get solved.

A photo of your circuit might be good too. Perhaps the layout has issues?

int analogPin = 0;     // potentiometer wiper (middle terminal) connected to analog pin 0

                       // outside leads to ground and +5V

int val = 0;           // variable to store the value read



void setup()

{

  Serial.begin(9600);          //  setup serial

}



void loop()

{

  val = analogRead(analogPin);    // read the input pin

  Serial.println(val);             // debug value

}

And the circuit is also attached

From the Due datasheet:

"The Due’s analog inputs pins measure from ground to a maximum value of 3.3V. Applying more than 3.3V on the Due’s pins will damage the SAM3X chip."

Leo..

Wawa:
From the Due datasheet:

"The Due’s analog inputs pins measure from ground to a maximum value of 3.3V. Applying more than 3.3V on the Due’s pins will damage the SAM3X chip."

Leo..

Yes my mistake while writting, i only used 3,3. In fact in the images i attached from the UNO it can be seen that the read value never goes close to 1023(5V), it's alway much lower

A0 is definitly not 0, therefore to read A0 pin, you need a:

analogRead(A0);

And if you Serial print A0, you will discover what is its number !

ard_newbie:
A0 is definitly not 0, therefore to read A0 pin, you need a:

analogRead(A0);

And if you Serial print A0, you will discover what is its number !

analogRead treats small pin numbers as analog pins implicitly. Unless the Due
is different (hmm, don't remember this being the case, but its a while since I used my
Due).

You don't need to know the difference between 0 and A0 - analogRead sorts it out for you.

ard_newbie:
A0 is definitly not 0, therefore to read A0 pin, you need a:

analogRead(A0);

And if you Serial print A0, you will discover what is its number !

Indeed it showed as 54, but the problem remains :frowning: ....

When i move the potentiomer the only values that are returned are 512 or 768, and if i read from a pin without anything connected it shows as 512 constantly. I dont knowm, maybe there is a shortcircuit somewhere in the board???

What happens when you short it to ground?

Which version of the IDE are you using? Can you try another version? Use another analog pin?

AWOL:
What happens when you short it to ground?

Shorting to vcc shows 768 and to ground 512. And i just tried this potentiometer before with the UNO and works fine.

Sounds like you broke it.