9

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.

enter image description here

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 & 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&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.

7

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.

  • "Many shields now are starting to add a small switch" cool. Micro has "USB to Serial bridge chip" ? Does that mean i can use pins 0,1 on uno but not on micro? – cocco Aug 22 '15 at 11:49
  • You can use them on any that do not have a USB to Serial bridge. The Uno has one, the Mega has one, the Mini doesn't have one, however you do need to connect one externally to the TX/RX pins to program it. All of those are out. The Micro, and the Leonardo do not have one, so you can use those. – Majenko Aug 22 '15 at 11:59
  • Thats what @Nick Gammon is talking about ? Uno and the others you wrote down have pullup resistors that don't allow you to properly use pin 0 and 1 but the Micro has no pullup resistor and so pins 0 and 1 work properlky and also the usb to upload new sketches? – cocco Aug 22 '15 at 12:03
  • For once Nick is mistaken on that point. There aren't any pullup resistors. What is there is a pair small inline resistors to prevent problems if the main MCU and the USB chip both try driving the same line to opposite levels at the same time. You can see them on the Uno schematic as RN4A and RN4B. – Majenko Aug 22 '15 at 12:26
  • If the USB chip happens to try driving the RX pin (you have the USB port plugged in and you open the serial connection [or maybe it's just plugged in, not sure]) then it can affect the voltage on the RX pin independent of whatever you're doing in your sketch, so it may not be safe to use that pin for things like charlieplexing. – Majenko Aug 22 '15 at 12:28
0

20x(20-1) = 380 leds (charlieplexing, high low); Correct me if i'm wrong. That means you are able to control 380 "Whatever" using diodes and one Arduino.

First, the figure of 380 is correct for 20 pins (202 - 20) however pins 0 and 1 are connected to pull-up resistors on the Atmega16U2, so they are never really at 0V. If you load a blank sketch, you will measure 5 V on pins 0 and 1.

Second, you can't drive 380 "whatevers" you can drive 380 LEDs via Charlieplexing. The property of the LED, that current only flows one way through it, is important to the way it works.

Related question Is there a way to have more than 14 Output pins on arduino?

  • First: what happens if i put 2 leds inverted(with resistors) on pin 0 and 1, set pin 0 high pin 1 low delay 1 second and set pin 0 low and pin 1 high delay 1sec? – cocco Aug 22 '15 at 11:35
  • Second: By "whatevers" i mean switches... click switches, reed switches, sensors or every type of combination of inputs outputs that support high low.electronicdesign.com/site-files/electronicdesign.com/files/… done with diodes. – cocco Aug 22 '15 at 11:36
  • Well, not really. Charlieplexing is a form of multiplexing, so unless you want your switches clicking like mad, it won't really work for them. And it is an output situation, so you won't be doing inputs, like you seem to think. I suggest you read the other links. Shift registers, or port expanders, are more practical than Charlieplexing here. – Nick Gammon Aug 22 '15 at 21:49
0

I can't comment due to insufficient reputation but I want to point out that the OP pinout has at least one pin wrong!

PB6 should be PB5

I spent quite a lot of time trying to figure out why I couldn't see SCK on scope (SPI bus). I was working low level, not with the IDE.

As this is the first picture that comes up when googling I wanted to avoid the same trouble to others...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.