Go Down

Topic: Arduino UNO 3 Digital I/O count (Read 1 time) previous topic - next topic

SPlatten

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.
Kind Regards,
Sy

robtillaart


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 -

Rob Tillaart

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

bill2009

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

James C4S


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...
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Go Up