Use all pins As digital I/O Increase the number of digital pins

There are many post that explain how to use more than just the standard pins on the various arduinos but none of them explain the limitations and the proplems properly.



Arduino Uno:

1.You can use the analog pins

Pin 14 = Analog in 0
Pin 15 = Analog in 1
Pin 16 = Analog in 2
Pin 17 = Analog in 3
Pin 18 = Analog in 4
Pin 19 = Analog in 5

digitalWrite(14,HIGH);
or
digitalWrite(A0,HIGH);


2.You can't use both SDA , SCL &amp; A4 , A5 as they are basically the same (18,19).

3.You can also use the TX/RX. 


  "Don't do it, you break the serial communication..."
  
  "Never use pins 0 and 1"
  
  "you can't use the TX/Rx Pins"


You can... but you need to take precautions. Which ones?

It should have software serial over USB, right? 

Or do i break the USB serial?

Are there internal Chip problems if i use TX/RX?

As i use those TX/RX pins in the code i probably should not use Serial.print()?

What happens if i forget to remove Serial.print() after uploading the code that use pins 0,1?

How to hardware reset the arduino/bootloader if something goes wrong? 

As there are various other Arduino's that use different chips, is the above valid for all Atmel chips?

So, what shuold i know before using those TX/RX or also maybe the other analog pins?


  There are cheap shiftregisters, pwm drivers, led drivers, spi, i2c and
  more ic's to expand your I/O




But if there are not to big problems it means that the arduino has 20 I/O pins...

You could theoretically control:

17x3 = 51 = 17 RGB leds (multiplexing, pwm sourcing&amp;sinking);
14x6 = 84 leds (multiplexing, pwm on 6 rows/colums );
10x10 = 100 leds (multiplexing, high low);
20x(20-1) = 380 leds (charlieplexing, high low);
// yes it would flicker


Correct me if i'm wrong. That means you are able to control 380 "Whatever" using diodes and one arduino.
The main issue is with pins 0 and 1.

Many pins have multiple functions assigned to them, such as A4 and A5 are also the I2C pins, pins 10/11/12/13 are also the SPI pins, etc.  But pins 0 and 1 are the only multi-function pins that actually have something attached to them on the board.

All the other pins, while being multi-function, have their function defined basically by what you attach to them.  Since the pins 0 and 1 are already attached on the board to the USB interface chip their usage possibilities are somewhat more limited.


As soon as you enable Serial in your sketch (Serial.begin()) those two pins can no longer be reliably used for digital IO.


That means that you can either use the hardware serial port or you can use the pins for digital IO, but not both.


Devices connected to pins 0 and 1 can interfere with the serial connection


That includes uploading of sketches.  You have serial data coming in from the PC while the same pins are being affected by other things connected to them.  The most common one is things like GPS modules which connect to those pins and constantly send serial data.  That serial data will conflict with the PC's serial data and neither will arrive right.


How do you upload sketches if the serial is being interfered with by your sketch? How do you "reset" the board?


You don't.  It's not your sketch that's interfering with the serial, it's what is physically connected to those two IO pins that are interfering.  Just disconnect those two pins from whatever is connected and you will be able to upload sketches again.  Many shields now are starting to add a small switch on them to disconnect those pins so you can upload sketches without unplugging the shield.  You can also use the same trick with other devices you wire up to those pins - add a double-pole-single-throw or double-pole-double-throw (and not use one position) to easily isolate both pins from the rest of your hardware when you need to.


Does this affect all Arduino boards?


No, only those that use a USB to Serial bridge chip - that's things like the Uno, Due, Mega, etc.  Boards that have a direct USB connection don't use the TX and RX pins for uploading sketches - they use the dedicated USB D+ and D- pins.  That's boards like the Leonardo, some of the smaller (mini? micro? I forget which) boards, etc.