Go Down

Topic: How to use all available pins on Leonardo (atmega32U4) (Read 2557 times) previous topic - next topic


May 20, 2014, 11:48 am Last Edit: May 20, 2014, 09:25 pm by JUGmobile Reason: 1
Q: Help I need more pins from my Arduino Leonardo board. Is it possible?
A: Yes it is! Read lines below for explanation, how to.

Arduino Leonardo board is using an Atmel atmega32U4 microcontroller which have 26 I/O pins. Arduino R3 platform is designed only to use 20 of them. So if you are working on Leonardo board and you are running out of pins on your Leonardo board, don't worry, you can get most pins without changing anything.
So where are my 6 lost I/O pins?

First lets see how does the  atmega32U4 looks like:

From the image above you can see that some pins of atmega32U4 are used as Arduino digital or analog pins, some pins are for power supply, on the left side is a USB port, there are two pins for crystal... but some of the I/O pins aren't used for I/O operations. Or are they?

First there is an SPI header on the Leonardo board. The pins connected to the SPI header are MISO (PB3), MOSI (PB2) and SCK (PB1). If you want to use them as I/O pins here is a secret. You can use them same as any other digital pin on Leonardo. Use the corresponding digital pin number:
MISO as digital pin 14
MOSI as digital pin 16
SCK as digital pin 15

RX and TX LEDs:
If your sketch doesn't require USB communication or you have an atmega32U4 without bootloader and you are programming uC via SPI or Atmel Flip, you can use RX and TX too. To use RX LED pin as I/O, use corresponding digital pin number:
RXLED as digital pin 17
TXLED can be used only (if you don't wan't to change DDR, PORT and PIN registers) as an output pin. Commands for controlling TXLED pin are:
Code: [Select]
TXLED0;      //To turn TXLED pin on
TXLED1;      //To turn TXLED pin off

Note: you can controll RXLED pin just the same way as TXLED pin, with using RXLED1; command to turn RXLED pin HIGH and RXLED0 to turn RXLED pin LOW.

HWB pin:
I haven't researched HWB pin yet, so any comments below are welcome. Some day I will add instructions how to use HWB pin as I/O pin.

So this is it, quite simple right?
Note: all functions above were tested on Arduino Leonardo board, using IDE 1.5.6r2 on Windows 7 x64 based computer.


Mar 11, 2015, 08:09 pm Last Edit: Mar 11, 2015, 08:12 pm by BlackJester
Is there a way to have the RX_LED functionality on TX_LED too?  Meaning the pin will light an LED when either receiving or transmitting?

Also, can the RX pin be reassigned even if you are using USB but don't need to blink the RX_LED?

Go Up