What is Arduino Leonardo? All You Need to Know

1,202 views

The Arduino Leonardo is a sophisticated microcontroller development platform built around the ATmega32u4 microcontroller. It marks a progression from earlier boards like the Arduino Uno, offering built-in USB communication capabilities through the Arduino Leonardo.

At the core of the Leonardo is the 8-bit ATmega32u4 AVR RISC microcontroller running at 16 MHz and featuring 32KB of flash memory, 2.5KB of SRAM, and 1KB of EEPROM. The chip inherently supports USB communication, allowing the Leonardo to interact with a connected computer by appearing as a virtual serial port and also functioning as a keyboard/mouse. This removes the need for additional chips found on previous boards.

The Leonardo offers 20 digital I/O pins that can be employed for digitalRead()/digitalWrite() or as analog inputs using analogRead(). 7 of these pins can deliver 8-bit PWM output leveraging analogWrite(). Additionally, there is a conventional 6-pin ISP header for external programming and debugging. Power can be supplied through USB or an external source.

Arduino Leonardo pinout diagram

Arduino Leonardo Specifications

  • Microcontroller: ATmega32u4 with integrated USB communication
  • Operating Voltage: 5V
  • Digital I/O Pins: 20
  • PWM Pins: 7
  • Analog Input Pins: 12
  • Flash Memory: 32 KB
  • SRAM: 2.5 KB
  • EEPROM: 1 KB
  • USB 2.0 capabilities
  • Built-in LED on pin 13

Arduino Leonardo-related Boards:

  • Arduino Leonardo without Headers
  • Arduino Micro

Arduino Leonardo Use Cases:

  • USB HID (Human Interface Device) applications (e.g., mouse, keyboard)
  • Versatile remote controls
  • Advanced robotics and animatronics
  • Musical instruments and effects
  • – Educational and prototyping endeavors
  • – Home automation systems

Arduino Leonardo Project Example:

USB Game Controller using Arduino Leonardo

The Arduino Leonardo features integrated USB communication, enabling it to emulate a mouse, keyboard, or other types of USB devices. This makes the board an ideal choice for developing a custom USB game controller.

Components Needed:

  • 1. Arduino Leonardo
  • 2. Joystick Module
  • 3. Push Buttons (as many as required for the game controls)
  • 4. 10k Ohm Resistors (for the push buttons)
  • 5. Breadboard and Jumper Wires

Wiring Connections:

1. Connect the VCC and GND of the joystick module to the 5V and GND on the Arduino, respectively. Connect the VRx to A0 and VRy to A1 on the Arduino.

2. Connect one terminal of each push button to a digital pin on the Arduino (starting from 2) and the other terminal to GND through a 10k Ohm resistor (for pull-down).

Arduino Code:

You’ll need to include the Joystick library in your Arduino IDE before uploading the following code:

```C++

#include <Joystick.h>

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_GAMEPAD, 12, 0, true, true, false, false, false, false, false, false, false, false, false);

void setup() {

  Joystick.begin();

  pinMode(2, INPUT_PULLUP);

  // Add more pinModes for more buttons

}

void loop() {

  int xValue = analogRead(A0);

  int yValue = analogRead(A1);

  Joystick.setXAxis(map(xValue, 0, 1023, 0, 255));

  Joystick.setYAxis(map(yValue, 0, 1023, 0, 255));

  if (digitalRead(2) == LOW) {

    Joystick.setButton(0, 1);

  } else {

    Joystick.setButton(0, 0);

  }

  // Add more if conditions for more buttons

}

```

This code reads the joystick and button inputs and transmits them to the computer as a USB gamepad. The gamepad has two axes (x and y) and as many buttons as needed. This USB game controller is an engaging and interactive project that showcases the unique capabilities of the Arduino Leonardo.

Frequently Asked Questions

Does the Leonardo require a separate power supply?

No, the Leonardo can be powered through USB, so a separate power supply is optional.

What is the operating voltage range for the Leonardo?

The recommended input voltage is 7-12V, though the board can function from 6-20V. Going below 7V risks instability.

What is the maximum current per I/O pin on the Leonardo?

Each I/O pin can sink or source up to 40 mA. The total for all I/O pins should not exceed 200 mA.

Does the Leonardo support wireless communication?

Not directly, but it can communicate with Wi-Fi and Bluetooth modules via its serial ports or I2C/SPI interfaces.

Can I program the Leonardo without the Arduino IDE?

Yes, you can program it directly through the ISP header using another programmer, without utilizing the USB connection.

Related Articles

Comparing FPGA vs Microcontroller: Optimal for Your Needs?