Pages: [1]   Go Down
Author Topic: Newbie question  (Read 1099 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, this question may be answered over 9000 times, but I cannot find any answer.

What's the main difference between digital and analogic outputs?
If I connect a LED to digital 12 pin and I say
Code:
digitalWrite(12, HIGH);
Should the LED turn on?

And if I connect a LED to analogic 4 pin (for example) and I write
Code:
analogicWrite(4, HIGH);
Should the LED turn on or shouldn't it?

I hope you can help me! smiley
Logged

Bonn, Germany
Offline Offline
God Member
*****
Karma: 2
Posts: 903
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

From one noob to an other:
As far as i understand it - or learned it - Digital ports are only having to states: ON or OFF (High, Low) - and Analog Ports should have a range of Values (e.g. 0 to 255). Might be possible that High and Low have corresponding values for Analog Ports, but i dont know that (and cant test it since i havent received my Arduino yet)

If i am wrong, please slap me with an Arduino manual ;0)
Logged

Believe me, Mike, I calculated the odds of this succeeding against the odds I was doing something incredibly stupid[ch8230] and I went ahead

0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay, so with analog ports we can regulate intensity?

Also, slap me with other Arduino manual xD
Logged

Bonn, Germany
Offline Offline
God Member
*****
Karma: 2
Posts: 903
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

i would dare to say so?
Logged

Believe me, Mike, I calculated the odds of this succeeding against the odds I was doing something incredibly stupid[ch8230] and I went ahead

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 620
Posts: 33992
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The analogue ports on the Arduino are only input ports not output ports.
There is no analogue output port on an Arduino.
However, some digital pins can work in the PWM mode. This switches the LED on and off rapidly and so allows it to be dimmed.
Look in the playground for this. Start here:-
http://www.arduino.cc/en/Tutorial/LEDCross-fadesWithPotentiometer
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, so you can use analogWrite() with digital pins?

I'm absolutely newbie, since I haven't received my Arduino yet
Logged

Bonn, Germany
Offline Offline
God Member
*****
Karma: 2
Posts: 903
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

ok, thank you smiley-mad)
Logged

Believe me, Mike, I calculated the odds of this succeeding against the odds I was doing something incredibly stupid[ch8230] and I went ahead

0
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

digitalWrite will set a pin which has been enabled for output to a 1 or a 0. In analog terms this would be 0=0 or 1=255. But for the digital function the pin is either set to 0V or 5V for 0 or 1 respectively.

The analogWrite function works on PWM output pins. It actualy sets the PWM output percentage with 0=0% high and 255=100% high. This can be used as an analog output depending on what you are connecting it to. Most things will work just fine. LEDs for example do not need a hardware filter. If you select a PWM output enabled pin and connect the LED there, use analogWrite to control the brightness of that LED.

I have some more information about using PWM pins for analog output in an article at uCHobby. http://www.uchobby.com/index.php/2008/01/08/arduino-audio-dac-options/

Does this help?
« Last Edit: January 04, 2009, 06:00:14 pm by uchobby » Logged

uCHobby: Hobby Microcontrollers

0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It does.
So all digital pins are PWM enabled?
If so: digitalWrite(12, 1); will have the same effect as analogWrite(12,255); ?

Thanks!
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

No not all the Digital lines are PWM capable. Digital lines 3, 5, 6, 9, 10, and 11 are PWM. You should see the PWM label on the Arduino board for these pins.
Logged

uCHobby: Hobby Microcontrollers

0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok heres another newbie question since this thread is live...

Can you increase the frequency of the PWM rather than the duty %?  The reference claims 490hz which isnt fast enough for what I require - 4khz would be the desired number smiley

G.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hmm the data sheet for the chip claims the PWM output has 250khz to maintain the 255 step resolution - so I presume its possible...

G.
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 354
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Grumpy_Mike:

What you are saying is not completely true. Analog pins can be used for output. They can be used as digital outputs. They are mapped as pins 14-19 for output.

So using the ops example, if I wanted to set analog pin 4 high.

Code:
pinMode(17, OUTPUT); //13+4
digitalWrite(17, HIGH);

remember to change the pin to an output ping using pinmode. If you don't do that, the pin still acts like an input but with its internal pull up resistor enabled
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 620
Posts: 33992
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What you are saying is not completely true.

Can you point to the bit in my reply you believe not to be true?

Yes you can use analogue input pins as digital inputs or outputs, I do that all the time if you have ever seen any of my projects:-
http://www.thebox.myzen.co.uk/Hardware/Projects.html

But that was not the question, the original question stated:-
Quote
What's the main difference between digital and analogic outputs
I pointed out that there is no analogue output on this controller but there was a PWM digital one.

That is not to be confused with saying there is no output possible from an analogue input pin. Which is an altogether different statement. Being dyslexic I believe words are important and they should say what they mean not hint ambitiously. So please try and read what the words say.
« Last Edit: January 07, 2009, 08:51:23 am by Grumpy_Mike » Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 354
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

wow this is heavy. I didn't mean in any way to offend you.

In your original post you stated:

Quote
The analogue ports on the Arduino are only input ports not output ports.
I was just pointing out that the analog ports can be used for digital output.

I have used your website on many occasions and find it very helpful. I've refered many people to your tutorial section.

Maybe saying "not completely true" was a little harsh. However,  the quoted statement above is "not completely true". I'm sorry if I offended you, it was not the goal of my post. My goal was just to inform the op that he can use the analog port for output if he runs out of pins.
Logged

Pages: [1]   Go Up
Jump to: