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?MISO, MOSI and SCK:
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 15RX 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:
TXLED0; //To turn TXLED pin onNote: 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:
TXLED1; //To turn TXLED pin off
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.