Pages: [1]   Go Down
Author Topic: Arduino UNO 3 Digital I/O count  (Read 1007 times)
0 Members and 1 Guest are viewing this topic.
United kingdom
Offline Offline
Full Member
***
Karma: 0
Posts: 108
just think how much free time you would have if everything worked first time!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've looked at the standard "pins_arduino.h" and there are definitions:

NUM_DIGITAL_PINS with a value of 20 and NUM_ANALOG_INPUTS with a value of 6. 

The page for the Arduino Uno says they're are 14 digital I/O and 6 analogue inputs.

I've run a bit of code to query the digital I/O information, and the results I got back are:
Pin: 1, bit: 2, port: 4
Pin: 2, bit: 4, port: 4
Pin: 3, bit: 8, port: 4
Pin: 4, bit: 16, port: 4
Pin: 5, bit: 32, port: 4
Pin: 6, bit: 64, port: 4
Pin: 7, bit: 128, port: 4
Pin: 8, bit: 1, port: 2
Pin: 9, bit: 2, port: 2
Pin: 10, bit: 4, port: 2
Pin: 11, bit: 8, port: 2
Pin: 12, bit: 16, port: 2
Pin: 13, bit: 32, port: 2
Pin: 14, bit: 1, port: 3
Pin: 15, bit: 2, port: 3
Pin: 16, bit: 4, port: 3
Pin: 17, bit: 8, port: 3
Pin: 18, bit: 16, port: 3
Pin: 19, bit: 32, port: 3

I can see from the header that some of the digital pins are also used for analog output.  Is there a function I can call that will tell me if a pin is available for use?

I would like to create a class which enables me to read and write packed bytes to a port, so I can read and write to mutiple digital I/O pins with a single call.  It certainly looks like this is possible from the source.
Logged

Kind Regards,
Sy

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12483
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


The point is that the analogports A0..A5 can also be used with digitalRead() and digitalWrite() - PIN numbers are 14..19.
- don't forget to set pinMode()...

So if you need e.g. 16 IO pins you just use some of the analog pins as digital pins.

unfortunately you can't use the digital pins as analogpins, but hey there are multiplexers for - http://www.sparkfun.com/products/9056 -

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

ottawa, canada
Offline Offline
God Member
*****
Karma: 5
Posts: 989
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have a look at PORTB and direct port manipulation. This may be exactly what you need.
Logged

Austin, TX
Offline Offline
Faraday Member
**
Karma: 64
Posts: 6055
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I would like to create a class which enables me to read and write packed bytes to a port, so I can read and write to mutiple digital I/O pins with a single call.  It certainly looks like this is possible from the source.

Do you really need a class for that? 

int lowDigital8 = PORTB;   // reads the value of pins 0 through 7.
int highDigital6 = (PORTD & 0x3F);   // reads pins 9 through 13.
etc...
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Pages: [1]   Go Up
Jump to: