Arduino Uno ATmega328P-PU usable I/O pins

I'm starting an LED array build and I'm wondering how many pins of the ATmega I can actually address to control said LED's in the arduino environment.
i was looking at this atmel data sheet for the atmega328P, along with the pin out provided by arduino. But i do really enjoy pighixxx's pin out comparisons.

The atmel data sheet says there's 23 I/O pins, but how many can we use while keeping the chip easily programmable?

As I see it, there are 28 pins on the chip, 2 GND, 2 VCC, AREF leaving 23 pins to play with...

Well I intend to keep program-ability so TX/RX will not be used in the build.(unless there's a work around?) there's another 2 I/O pins lost, bringing the max count down to 21.(the exact number i need)

Arduino pins 2-13 are all good = atmega pins 4, ~5, 6, ~11, ~12, 13, 14, ~15, ~16, 17, 18, 19) with some PWM (~) always nice. pin count = 12
I can also use arduino pins A0-A5 = atmega pins 23-28, adding 6 to the pin count now 18,
so those are all easy enough.

And now for the real questions:

This project will become a stand alone project what will use the internal oscillator,
so how do i address the oscillator pins = atmega pins 9 and 10 in code? (hopeful gain of 2 total now 20)

and lastly the reset button/pin ... how do i disable the reset fuse and use the "reset" pin = atmega pin 1, in code?

thanks for the help

dej

For reference i have 100 led's and i would like to use one analog input to control them (that's 21 pins with only transistors, resistors, and an external power source needed).

You can useCharlieplexing, 12 pins to drive 132 LEDs.
http://playground.arduino.cc/code/charlieplex

thank you, didn't think of that,
but its a lot more complex wiring... and if an LED fails, troubleshooting it would be a pain...
i also want as high a duty cycle as possible.

any ideas on the 3 pins in question with code writing?

I’d consider just regular multiplexing, which can be done with a shift register, a MAX7219/7221 (which is sort of a fancy shift register), or rig the multiplexing directly from the Arduino.

Edit: Added schematic of a project I built, it uses 12 pins to multiplex a 4-digit seven-segment common anode LED display directly from the MCU.

i will be multiplexing, but for 100 LED's i need 20 pins,
charlieplexing might be a feasible option and would use 11 pins(though it has some serious downfalls IMHO)

but i want it to be done with only the ATmega, some resistors, and some transistors, some caps and a power supply. (no i'm not about to make a shift register)

dejman:
(no i'm not about to make a shift register)

Agree, I much prefer to just buy them :wink:

i see theres a bit of trouble using the crystal resonator pins here. its not that pretty

Use the SPI pins to send data to two MAX7219s. They are inexpensive ($1.25 each at TaydaElectronics.com), can control 64 LEDs each, and take care of the multiplexing for you.

Otherwise, use the standard 20 IO pins and drop the serial capability. You may have to intervene manually on the reset switch for serial downloading to have the bootloader watch for programming insructions at the correct time; alternately, use the SPI pins for ICSP programming and skip the serial downloading via bootloader altogether.

thanks, im not sure what you mean exactly,
what needs to happen in order to use the TX and RX pins as output pins but still program.
it was my understanding that if i used these pins i could not use the uno board via usb to reprogram the chip,

am i mistaken?

If you are building a standalone atmega328p design, don't program via the bootloader and serial port, program via ICSP instead. This has several advantages:

  1. It frees up the Tx and Rx pins completely.

  2. It means that you do not need an accurate clock, so you can use the internal 8MHz oscillator and free up the two XTAL pins.

  3. You don't need a USB-to-serial converter.

Don't change the fuse to use reset as an I/O pin, you need the reset function to program/reprogram the chip using ICSP. You still have 22 I/O pins available.

what needs to happen in order to use the TX and RX pins as output pins but still program.

Nothing - but sometimes the sketch blasts so much stuff out on the Rx pin that the PC can't get a byte in- so you have to help out by holding Reset down, and releasing it when the IDE shows "compiled xxx of 32xxx bytes" or similar.
Might take a couple of tries to find the right spot.

thank you both,
any recommendations on ICSP programmers or builds to make an ICSP programmer? (i doubt ill tackle it this early in the project, but it sounds extremely useful)

dej

Best for all AVRs: Atmel AVR ISP MKii

Other options
Arduino as ISP:

Other ISPs:

Similar units as mdfly.com, sparkfun.com, adafruit.com

many thanks