Pages: [1] 2   Go Down
Author Topic: Alternative use of pins  (Read 822 times)
0 Members and 1 Guest are viewing this topic.
Sweden
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
Be patient, I'm a total newbie.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can't find any clear information at all on whether it is possible to use special pins like those for serial communication and analog input for "normal" digital I/O.

For example, on http://arduino.cc/en/Reference/serial it reads:
Quote
All Arduino boards have at least one serial port (also known as a UART or USART): Serial. It communicates on digital pins 0 (RX) and 1 (TX) as well as with the computer via USB. Thus, if you use these functions, you cannot also use pins 0 and 1 for digital input or output.
That vaugely implies that maybe I can use those two pins for digital I/O if I don't need them for serial communication, if I dare to read the unwritten information between the lines.

Same goes with the analog input pins. It seems I can assign the as digital inputs, even though they are presented as analog, all I have to do is define their tasks in the sketch. It looks as if I even can make them digital outputs, in spite of the fact that they are labelled analog inputs!

But the information on alternative use of pins is hard to find, if there even is any out there(?)
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.gammon.com.au/uno

The analog pins can certainly be used as digital pins.

You can use the serial pins too except that they have pull-ups connected internally. It would be OK to use them as outputs, not quite as useful to use them as inputs.
Logged

Offline Offline
God Member
*****
Karma: 27
Posts: 829
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nick, when you say they have internal pullups on them, couldn't that be disabled? Or does the arduino code keep re-enabling that (or are we talking about the 32u4 connected to them?) If serial is never invoked in your code, I don't understand why the pins would be pulled up. But, wouldn't simply setting them as inputs and writing zero to them disable the pullups?
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm not sure about the TxD pin (pin D1) but the RxD pin (pin D0) would be kept high by the Atmega8U2 chip via a 1K series resistor, because the 8U2 is trying to send to the main processor what it is receiving from the USB port, which, if nothing, will be a HIGH state.

As a test I uploaded this sketch to my Uno:

Code:
void setup () { }
void loop () { }

I measured 5V on both D0 and D1, and 0.5V on D2 onwards.

Checking for current I got 5 mA on D0 which would be consistent with a 1K resistor. On D1, I got 0.15 mA which is consistent with a 33K resistor, which the 8U2 chip may well use (as an internal pull-up) to make sure it doesn't interpret high impedance data as random rubbish.

Neither of those can be changed by programming the Atmega328P chip because they are external to it.

Setting the pins to OUTPUT however would override the pull-ups. Then you could drive them LOW or HIGH at your leisure.
Logged

Ayer, Massachusetts, USA
Offline Offline
Edison Member
*
Karma: 53
Posts: 1832
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Same goes with the analog input pins. It seems I can assign the as digital inputs, even though they are presented as analog, all I have to do is define their tasks in the sketch. It looks as if I even can make them digital outputs, in spite of the fact that they are labelled analog inputs!
On the Uno, all 6 of the analog input pins can be used for digital output.  However, on some of the non-official Arduino machines that are programmed with the Arduino IDE that have more analog input pins, those extra pins cannot be used for digital output.
Logged

Offline Offline
God Member
*****
Karma: 27
Posts: 829
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Michael, are you positive about that? I ask because I have made more than a couple "non-official" arduinos for my own purposes and as long as I have the proper variants and cores for them (in my case I had to make some of them), I have no trouble using the extra analog pins for digital input. The only reaosn that I could see not being able to is if you did not have the right pins_arduino.h for your variant. And if you didn't have that, you couldn't use the extra analog pins as analog pins either. In fact, you couldn't use ANY of the extra pins at all.
Logged

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

Michael, are you positive about that? I ask because I have made more than a couple "non-official" arduinos for my own purposes and as long as I have the proper variants and cores for them (in my case I had to make some of them), I have no trouble using the extra analog pins for digital input. The only reaosn that I could see not being able to is if you did not have the right pins_arduino.h for your variant. And if you didn't have that, you couldn't use the extra analog pins as analog pins either. In fact, you couldn't use ANY of the extra pins at all.
No.
Some non official arduino's use a diffrent processor. It is that that determins if you can use some analog pins as digital ones. This also applies to some official arduino boards that do not use the AT328 processor.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25706
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
However, on some of the non-official Arduino machines that are programmed with the Arduino IDE that have more analog input pins, those extra pins cannot be used for digital output.
...or, indeed, as digital inputs.
The Nano is an "official" board with A6 and A7 brought out to pins. These two are connected only to the analogue input mux, and can be used only as analogue inputs.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
God Member
*****
Karma: 27
Posts: 829
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My "non-official" variants are using other processors (Attiny2313, Atmega1284, ATmega32, etc..) Unless we are talking about non-AVRs, I don't get it. All that is defined right in pins_arduino.h for your variant. And if it were necessary, you make a different core for your variant.

Do you have an example? I am just perplexed by this. It isn't a limitation of any AVR that I am aware of and as I said, the pin mapping is all in the variants files so I don't think it is a limitation in Arduino either (at least not in 1.0.3 which is what I started with.)

{edit} Oh. Thanks for the example!
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Nick, when you say they have internal pullups on them, couldn't that be disabled?

Another approach would be to use the pins as inputs in situations where you want the internal pullup anyway (eg. to a switch which has the other side wired to ground). In that case the pull-up voltage won't worry you.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

My "non-official" variants are using other processors (Attiny2313, Atmega1284, ATmega32, etc..)

My reply specifically addressed the Uno (and similar variants, like the Duemilanove) not all the boards with different processors in them. The original question needs to be clarified if you are asking about Leonardos, Megas, and so on.
Logged

Offline Offline
God Member
*****
Karma: 27
Posts: 829
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yep. I was completely unaware of the difference in the LQPF version of the ATmega328. Learn something new every day!
Logged

Ayer, Massachusetts, USA
Offline Offline
Edison Member
*
Karma: 53
Posts: 1832
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

..or, indeed, as digital inputs.
The Nano is an "official" board with A6 and A7 brought out to pins. These two are connected only to the analogue input mux, and can be used only as analogue inputs.
Thanks for the example.  I couldn't remember which processors had the A6 and A7 that could not be used for digital I/O, but I knew I had seen in in following various posts.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17259
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As I best recall The Uno SMD board also used the LQPF version of the ATmega328, but not sure they brought out the two extra analog only pins to extra pads or pins. Can't find a link to the SMD schematic on the product page.

Lefty
Logged

London
Offline Offline
Edison Member
*
Karma: 46
Posts: 1368
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As I best recall The Uno SMD board also used the LQPF version of the ATmega328, but not sure they brought out the two extra analog only pins to extra pads or pins. Can't find a link to the SMD schematic on the product page.

Lefty
I've a SMD Uno. There are no extra pins, but there appears to be 2 unconnected pads by the chip. From the dot, anti-clockwise, they are pads 3 and 5.
Logged

Pages: [1] 2   Go Up
Jump to: