I was looking today some functions for programming my Arduino and I found this sentence I would like someone to explain me. When reading about digitalWrite() I found this: "NOTE: If you do not set the pinMode() to OUTPUT, and connect an LED to a pin, when calling digitalWrite(HIGH), the LED may appear dim. Without explicitly setting pinMode(), digitalWrite() will have enabled the internal pull-up resistor, which acts like a large current-limiting resistor."
I will like to know if someone knows why this. I look in the Atmel datasheet to see pull-up resistors configuration and this matches with what I studied. What I understand is what I show in the picture attached.
So in what I have drawn we have 5 Volts in one terminal of the pull Up resistor due to Vcc and 5V in the other terminal due to output buffer (as it is said by Atmel digital output have 5V o 3.3V depending on the controller). So no current is going trough pull-up resistor. This does not match with what I wrote because there it is said that the pull-up resistor is a current-limiting resistor and this is only possible if pull up resistor is in series with led, and it is not.
For sure I have do not draw series LED resistance to avoid destroying it. Thank to everyone, maybe I understand the sentence incorrectly because I am not english speaker.
DrAzzy:
It is in series with the LED, though - you did digitalWrite(pin,1) while the pin was in it's default state (ie, input).
That enables the pullup (ie, connects it to the pin). So the LED is connected to Vcc through that internal pullup resistor.
Yes, this is exactlly what it is written in where I read the other thing. The led is connected to Vcc through two things: internal pullup resistor and output buffer. Because you connected to the output so it is connected to both the buffer and the pull up resistor.
Scroll down and read the paragraph "Configuring the Pin" below the figure you posted.
Yes, I read that. But does not is what I am looking for, and do not want to know who to configurate it, I want to know why is like that because is that not matcht with the diagrams shown. If pull up resistor have 0Volts no current is going through it so all the current from the pin goes to the led. So what it is said that the pull up resistor acts as a current limiter I do not see it.
grupoExcellentia:
I want to know why is like that because is that not matcht with the diagrams shown.
I'm not really sure what you're asking.
Your diagram shows the pull-up and the output buffer but doesn't show the output buffer enable. Is the pin an input or an output in your diagram? If it is an output then the pull-up is disabled, just like it says in that paragraph.
Your diagram shows the pull-up and the output buffer but doesn't show the output buffer enable. Is the pin an input or an output in your diagram? If it is an output then the pull-up is disabled, just like it says in that paragraph.
What I did not see was the output buffer enable. Now it matches me that when pin is set input led is connected to pull up resistor when digitalWrite is set to 1. Thank you.
(btw - on some newer Atmel processors,( ATTiny841, 441, 1634 and 828) there's a separate register to control pullups, instead of the rather strange "write high with pin as input" scheme)
The strange scheme is no doubt because it was an afterthought and it meant not having to create new registers or much extra circuitry on chip as each pad already has the DDR and PORT lines available. Contrary to the diagram
the pull up "resistor" is likely just a pFET with a long thin channel - thus lots of on-resistance.
DrAzzy:
(btw - on some newer Atmel processors,( ATTiny841, 441, 1634 and 828) there's a separate register to control pullups, instead of the rather strange "write high with pin as input" scheme)
What it strange about that? It's extremely elegant - making efficient use of just two register bits with four possible states (need I enumerate?).
The only obvious advantage of a separate register is to make software I2C more efficient.
MarkT:
The strange scheme is no doubt because it was an afterthought and it meant not having to create new registers or much extra circuitry on chip as each pad already has the DDR and PORT lines available.
I very much doubt it is an afterthought. It is efficient design.
What is particularly elegant about the internal pullup, is that it is essentially implemented using one single component, since it is basically switched directly by the output register in the HIGH state. It does not matter in this regard if the pin is set as an output or an input.