• Tue. Jun 18th, 2024

DIY Game Controllers

Homemade hardware to take your gaming experience to the next level!

Getting Acquainted with the Magical Arduino Leonardo

A standard Arduino Leonardo.
An Arduino Leonardo board.
An Arduino Leonardo board.

The Arduino Leonardo was the first Arduino to use Atmel’s ATmegaXU4 series chip with built-in USB. This change is big, and it has big benefits. In addition to the built-in USB, it offers more digital and
analog pins. This guide gives you the basic details that you’ll need to know to get started using one. If you’d like to dive right in to making a basic Joystick with the Arduino Leonardo, check out our post outlining the process. Game Controller with an Arduino Leonardo or Pro Micro. To jump directly to a section of interest use the Table of Contents below.

More Digital Pins

A bare Arduino Leonardo board.
A bare Arduino Leonardo board.

The Arduino Leonardo has four more digital pins than the Uno which has 14 digital pins: D0-D13. The Leonardo has 18: D0-D17. The extra pins have been mapped to the ICSP header. — On the bottom of the above illustration. — Their mappings are:

  • D14 – MISO – PB3
  • D15 – SCK – PB1
  • D16 – MOSI – PB2
  • D17 – SS – PB0

Pin D17 (SS) does not have a corresponding pin on the ICSP header, nor anywhere on the board. In order to use it, you must solder a wire to either the end of the Rx LED, or at the end of the trace on the board
after it.

Extra PWM Pin

The Arduino Leonardo has 7 PWM pins instead of the 6 found on the Uno. ATmega32U4 also has a new timer, timer4 which has 10 bits and uses a PLL to count at 64MHz. — They are labeled in pink in the above illustration. — Their mappings are different as well:

  • D3:  8-bit timer0
  • D5:  16-bit timer1&3
  • D6:  10-bit timer4
  • D9:  16-bit timer1&3
  • D10:  16-bit timer1&3
  • D11:  8-bit timer0
  • D13:  10-bit timer4

More Analog Pins

There are a total of 12 analog input pins available on the Arduino Leonardo. The board has the same 6 analog pin header along the side for pins A0-A5 as found on the Uno. For the extra 6 pins (A6-A11), they are located among the digital pin headers. They are marked with a dot on the top side of the board with the numbering drawn on the backside. –They are labeled in light green in the illustration above. — As usual, analog pins can also be used for digital I/O.

The correspondence of each analog with their digital counterparts is as follows:

  • A0 – D18
  • A1 – D19
  • A2 – D20
  • A3 – D21
  • A4 – D22
  • A5 – D23
  • A6 – D4
  • A7 – D6
  • A8 – D8
  • A9 – D9
  • A10 – D10
  • A11 – D12
A “headless” Arduino Leonardo microcontroller.
A “headless” Arduino Leonardo microcontroller.

SDA/SCL Pins Are Different

The pins supporting I2C/TWI protocols previously on the Uno they used analog pins A4 & A5. Now these pins are located at digital pins D2 & D3. — Labeled in baby blue above. — While the SDA and SCL pins are in the same location on the board, because of the underlying hardware mapping changes, it may affect the operation of certain shields and is something to keep in mind when reusing any code used in a project with a board that uses these two pins.

There are Serial Port Differences

There is now a second serial port. The primary port is built into the USB interface and the Tx/Rx LEDs are attached to it. The secondary port is located at pins D0 & D1. — Label in black text on white above. —
The secondary port does not have any LEDs attached.

To use the primary serial port, use the class Serial as usual. For the secondary port, a new serial class called Serial1 has been created. It is used the exact same way as the Serial class.

Keyboard and Mouse Emulation

This where the magic is at and what we around here are the most excited about. The feature is direct USB support. That means it can operate the same as any USB HID compliant device. It can emulate anything and everything from a computer mouse, full keyboard, keypad, joystick, partial keyboard, macro pad, you name it!

The Arduino library has made it super easy to get the ball rolling with two classes – one for emulating a mouse, and the other a keyboard.

Get Started

There are two things you must do before using your new Arduino Leonardo board.

First, you must your Arduino IDE must be no older than version 1.01. That is the version where it adds the support needed for this type of board, plus it has a lot of nice new features.

Second, unless you are using Linux, you will need to install USB drivers for the Leonardo. Arduino Leonardo 64bit Windows Driver Installation

This hopefully was enough information for you to begin to explore the world of possibilities this little board opens up for us hardware hackers, makers and enthusiasts.

We’ve got a whole series of posts where we breakdown different Arduino microcontrollers plus some from other manufacturers you may not know about yet. There is also a handy table to quickly reference which microcontroller boards support which features.

If you’re looking for how to actually create your own device be sure to see the post where we give a good rundown of the Arduino Game Controller Library.

2 thoughts on “Getting Acquainted with the Magical Arduino Leonardo”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.