Arduino Due analog pin

Hi everyone.

I am having a very weird problem.

I am trying to control a backlight of my screen using an analog pin from Arduino DUE. I want to be able to Dim the backlight of screen (3.4 inch TFT).

When i write this analogWrite(A2, 255);

It lights on the backlight to full power and keeps working fine.

However when i write this analogWrite(A2, 0);

it doesn't shut it off completely. It dims it to about 50% but not off.

I have removed the screen and i see that analogWrite(A2, 0); actually keeps spitting out 0.78 V

Furthermore, when i print something on the serial port this voltage goes down. As soon as the serial port data stops, it gets back to 0.78V

Perhaps a faulty ground line or what?

Has anyone else faced this problem too?

Any suggestions? :-[

Try changing the pin you are connecting to:

From the Arduino Reference page: http://arduino.cc/en/Reference/AnalogWrite

"The Arduino Due supports analogWrite() on pins 2 through 13, plus pins DAC0 and DAC1. Unlike the PWM pins, DAC0 and DAC1 are Digital to Analog converters, and act as true analog outputs. "

Let us know if that works, as I believ ethat it will!

David G.

Thanks David.

Yes it works fine with PWM pins. I actually thought analogWrite can also work on Analog pin but i was wrong.

However the thing that was confusing me is.. when i analogWrite on an analog In pin (for example A0 or A1 etc). It used to dip voltage while printing on serial port. Why was this happening?

So basically, the voltage fluctuates with serial port's output.

Glad your code now works, but:

when i analogWrite on an analog In pin (for example A0 or A1 etc). It used to dip voltage while printing on serial port. Why was this happening?

is unknown to me....

David G.

However the thing that was confusing me is.. when i analogWrite on an analog In pin (for example A0 or A1 etc). It used to dip voltage while printing on serial port. Why was this happening?

Using analogWrite with any value from 0 to 127 on any of the analog pins creates a 3-4 µs LOW_HIGH_LOW pulse on the pin. It is only compatible with the DAC and PWM pins. Using digitalWrite on any of the analog pins does not create this problem.

So basically, the voltage fluctuates with serial port's output.

Writing to the serial port is a blocking function, it increases the gap between the 4µs pulse for each analogWrite, therefore lowering the avg. voltage you would read on the port.