Arduino Leonardo versus Uno – What’s New

Arduino Leonardo

Arduino Leonardo

Arduino’s latest incarnation – the Leonardo is now shipping. It is the first Arduino to use Atmel’s ATmegaXU4 series chip with built-in USB. This change is big and it has big benefits.

Early Arduinos required a serial port connection to your computer for programming. As the platform matured, the board acquired a USB to serial conversion chip. The latest version of the classic Arduino board – the Uno – still uses this method, although with the Uno a switch was made from an expensive FTDI conversion chip to using an ATmegaXU2 series microcontroller chip. This chip is a cousin to the U4 series, but lacks analog input pins.

Using a USB conversion chip was only a slight improvement over using a serial connection. It removed the requirement for a special conversion cable, but added significant cost to each and every board. With the Uno, the switch to using the ATmeag8U2 lowered the cost by a few dollars, but it seems kind of silly to use an entire microcontroller just to perform USB to serial conversion for another microcontroller of roughly the same capability.

This ironic situation is finally resolved with the introduction of the Leonardo. Not only does this AVR chip offer built-in USB connectivity, but it has many other benefits as well. This newest addition to the Arduino is not only cheaper but packs several additional features. I will be very surprised if the Uno continues in production much longer. I see no need for it at all – cheaper and better wins every time.

Without further ado, here are the differences and advantages of the Leonardo over classic Arduino boards such as the Uno and Duemilanove.

More Digital Pins

There are 4 extra digital pins. The Arduino Uno has 14 digital pins – D0-D13. On the Leonardo, these same 14 pins correspond to the same header locations along the side. To gain access to the additional four pins, the first three have been mapped to the ICSP header. Instead of the ICSP pins corresponding to pins D11-D13, they correspond to the first three new extra pins D14-D17. The specific mappings are:

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

D17 pin attachment points D17 pin attachment points

The last 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 the via attached to it. This is the cathode end of the LED. See the photo for the attachment points.

More and Better PWM Pins

While only one extra PWM pin is available (the Leonardo has 7, the Uno has 6), the timers on the ATmegaXU4 are considerably more capable. On the ATmegaXU4 there are: one 8-bit timer, two 16-bit timers, and one 10-bit high speed (64MHz) timer. There are a total of 9 pins supporting independent timer output, 2 of the pins are shared, leaving 7 pins total for PWM.

Details for each timer are as follows:

Timer 0

  • #bits = 8
  • Clock speed = 16 MHz (system clock speed)
  • Default prescale = 64
  • Pins D3 & D11

Timers 1 and 3

  • #bits = 16
  • Clock speed = 16 MHz (system clock speed)
  • Default prescale = 64
  • Pins D5, D9 & D10
  • Pin D11 can also be set to use timer 1 output (OC1C), but the Arduino library uses it for timer 0 (8-bit). To use it on timer 1, it must be done by setting the appropriate registers.

Timer 4

  • #bits = 10
  • Clock speed = 64 MHz
  • Default prescale = 64
  • Pins D6, D13
  • Pin D10 (PB6) also has a timer 4 output (OC4B), but the Arduino library uses it for timer 1 (16-bit). To use it on timer 4, it must with the registers.

Of course as with the timers on other Arduinos, the PWM speeds and types can be customized by setting the appropriate registers. This tutorial can be very helpful if you are new to customizing the timers in AVR chips.

More Analog Pins

In the ATmegaxx8 based Arduinos, such as the Uno, there 6 analog input pins that can also be used as digital pins. In the Leonardo, there are a whopping 12 analog input pins which can also be used for digital pins. In order to maintain compatibility with existing Arduino shields, analog pins A6-A11 are located among the digital pins. They are marked with a dot on the top side of the board with the numbering drawn on the backside. The correspondence with their digital counterparts is as follows:

  • A6 – D4
  • A7 – D6
  • A8 – D8
  • A9 – D9
  • A10 – D10
  • A11 – D12

The original 6 analog input pins have new digital pins mappings as well. They are:

  • A0 – D18
  • A1 – D19
  • A2 – D20
  • A3 – D21
  • A4 – D22
  • A5 – D23

In order to use these analog pins, you must of course forgo using them as digital pins. However, since you also get four new digital pins, the trade-off costs very little, and is up to you how to allocate them.

SDA/SCL Pins

The pins supporting I2C/TWI used to be the same as analog pins A4 & A5. In order to use this service, you had to forgo two precious analog pins. In the Leonardo, these protocol pins are now located at digital pins D2 & D3. They also still have their own special place in the output headers just like the Uno.

Serial Port Differences

The standard serial port at pins D0 (Rx) and D1 (Tx) have become a second serial port. The primary serial port is implemented as part of the USB interface and uses no digital pins. The Rx & Tx LEDs are tied to the first serial port and are not active when using the second one. In software, the primary serial port is still accessed using the object Serial. To access the second serial port, use a new object called Serial1 in the same manner.

There are also some differences in how the primary serial port acts when attached to your computer. Formerly, when the serial port was implemented in hardware, resetting the Arduino had no effect at the computer end. Now, the serial port is a creation of software. Therefore, when the Arduino is reset, the connection is broken and a new serial port is established. The Leonardo documentation provides details:

Since the Leonardo does not have a dedicated chip to handle serial communication, it means that the serial port is virtual — it’s a software routine, both on your operating system, and on the Leonardo itself. Just as your computer creates an instance of the serial port driver when you plug in any Arduino, the Leonardo creates a serial instance whenever it runs its bootloader. The Leonardo is an instance of USB’s Connected Device Class (CDC) driver.

This means that every time you reset the board, the Leonardo’s USB serial connection will be broken and re-established. The Leonardo will disappear from the list of serial ports, and the list will re-enumerate. Any program that has an open serial connection to the Leonardo will lose its connection. This is in contrast to the Arduino Uno, with which you can reset the main processor (the ATmega328P) without closing the USB connection (which is maintained by the secondary ATmega8U2 or ATmega16U2 processor). This difference has implications for driver installation, uploading, and communication; these are discussed below.

The other key difference with the virtual serial port is that when you open the serial monitor in the Arudino IDE, it doesn’t trigger a reset on your board. This change means you won’t see serial data that has already been sent since your sketch started. Again from the Leonardo guide:

Unlike the Arduino Uno, the Leonardo doesn’t restart your sketch when you open its serial port on the computer. That means you won’t see serial data that’s already been sent to the computer by the board, including, for example, most data sent in the setup() function.

This change means that if you’re using any Serial print(), println() or write() statments in your setup, they won’t show up when you open the serial monitor. To work around this, you can check to see if the serial port is open like so:

// while the serial stream is not open, do nothing:
   while (!Serial) ;

One last change in serial behavior is the fact that it is a lot faster. If you used to rely on its slow speed to throttle writes to the monitor, you may need to add some delay statements to do that for you now.

Keyboard and Mouse Emulation

Now that the Leonardo supports USB directly, that means it can operate as an actual USB device. Two of the tricks it can do is to emulate either a computer mouse or a keyboard. It can even emulate both. The Arduino library has made it really easy to do by creating a Mouse class and a Keyboard class. This page provides complete documentation, but here are some highlights:

Mouse

  • Mouse.move – move the cursor by an X,Y amount, and even move the scroll wheel
  • Mouse.click – simulate a click
  • Mouse.press – press the button down and hold until release is called
  • Mouse.release – release a mouse press

Keyboard

  • Keyboard.press – simulate the press of a certain key until released; can be used to press a modifier key while typing another character
  • Keyboard.release – release a key that has been pressed
  • Keyboard.write – simulate a single character being typed
  • Keyboard.print – simulate the typing of an entire string

Before using either of these emulation classes, you must use caution. If you do not have a way of turning them off, the Leonardo could prevent you from reprogramming it by sending keystrokes and mouse movements/clicks all the time. The Leonardo Guide has some guidelines to prevent such a mishap. Basically, you need some hardware means like a switch to shut off emulation. If you fail to provide for such a means beforehand, you may have to use a ICSP programmer to reflash your Leonardo – be sure to exercise care before playing with this new power!

USB Caveats

There are some things to be aware of when converting over to using the Leonardo. First you must upgrade your Arudino IDE to version 1.01. It has a lot of great improvements and implements support of the Leonardo. Second, unless you are using Linux, you will need to install USB drivers for the Leonardo. The Leonardo guide provides directions.

Conclusion

The Leonardo is a great addition to the Arduino family. It sports more pins, faster PWM, lots of analog input pins and best of all true USB. On top of all that, it is cheaper than its predecessors. If you are in need of a new Arduino, I wouldn’t consider anything else.

[UPDATE: With the lower price of the Uno version of the Arduino, I now recommend it over the Leonardo in most cases, due to the USB reset complications of the latter. See the comments for more information.]

If you have any experiences or tips of your own to share, please do so in the comments below.

Happy Arduino-ing!

Arduino Leonardo versus Uno – What’s New by Provide Your Own is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

This entry was posted in Tech and tagged . Section: . Bookmark the permalink. Both comments and trackbacks are currently closed.

12 Comments

  1. Posted July 5, 2012 at 1:07 am | Permalink

    While the Leonardo is a really nice Arduino board with some cool new functionalities, I still don’t think it’s very good for beginners. It has its limitations because some pins are different. Some shields will no longer work as a direct result of this. I think the Uno is often a better choice, especially for beginners.

  2. Posted July 24, 2012 at 3:58 am | Permalink

    While I think it’s a good idea to upgrade the microcontroller, I don’t think it’s a good idea to have used the ATmega32u4 microcontroller mainly because it’s a surface mount device (SMD). This makes it very difficult to prototype a standalone on a breadboard which is what beginners normally have access to. You can also use the Uno to program a fresh Atmega328 microcontroller. The Leonardo makes it very difficult to design a standalone circuit without using the Arduino board itself and for that reason alone, I recommend sticking with the Uno.

    • goebish
      Posted August 16, 2012 at 4:58 am | Permalink

      @Plasty Grove
      I totally agree with you but the problem is that no AVR chip with integrated USB exists in DIP format, blame ATMEL for that 😉
      I love making standalone circuits using DIP AVRs with the Arduino bootloader but I still just ordered a Leonardo to try it out.

  3. w4ni
    Posted August 19, 2012 at 7:20 am | Permalink

    yes both goebish and plastygrove got it right – the uno is better –
    the reloadable dip socket lets you crank out copies , once burned,
    which leonardo cannot do – then stick in a new $4 chip and
    burn another – it would be sad to see the uno go- new is often
    not better – hey arduino how bout a doublesided adc ?

  4. Hutschi
    Posted January 17, 2013 at 2:55 am | Permalink

    Another disadvantage is that the Arduino Leonardo uses a micro usb plug because of its instability considering the length of the plug and the laws of mechanics.
    I found that it is very instable compared with the connection used at the UNO.

    I am not very glad about it.

    Additionally I had to buy an extra cable.

    What about the current and reliability of the pins for the plug? Do you have experiences how often you can plug and unplug without breaking the contacts?

    I prefer the UNO for most usages, especially for programming the processor and use it somewhere else.

    If you want to use it as keyboard the Leonardo seems to be better, however.

    Best regards
    Bernd

    Please excuse errors in grammar – it is not my native language.

    • Posted January 17, 2013 at 8:05 pm | Permalink

      You have raised some good points. On the USB issue, I kind of like the micro-usb. I have those cables laying around more often. On the other hand, the large plug is certainly easier to get plugged and unplugged.

      As far as reliablility, the micro is supposedly much more reliable than the standard USB (see http://en.wikipedia.org/wiki/Universal_Serial_Bus). However, I have read that some real world experience shows quite the opposite. I think if care is taken when connecting, it ought to last close to its 10,000 cycle rating, unlike cell phones which tend to get quite a bit of abuse.

      As I have had more time with the Leonardo, I find its serial port connecting and disconnecting to be somewhat a hassle at times. As a result, I am using the UNO for most of my work. The UNO is a nice improvement over its predecessor in my opinion. The Leonardo does help one understand the issue with the serial adapter, and for maximum cost effectiveness, an Arduino-clone using a separate serial adapter might be a better way to me. Not as plug and play, but more cost effective if one ends up leaving units deployed.

      I agree with you – for USB device emulation, the Leonardo comes into its own; otherwise, use the Uno.

      BTW, your English is perfect.

  5. UMANG
    Posted March 25, 2013 at 10:05 am | Permalink

    Hey guyz i am a beginner and completly new to ARDUINO plz suggest me which board should i buy as i am a begineer Leonardo or uno?

    • Posted April 24, 2013 at 12:45 pm | Permalink

      After playing around with both boards, I have found the Uno to be much more useful. The USB reset issues with the Leonardo makes it much more difficult for experimentation. The cost difference with the Uno has dropped to very little, so I recommend the Uno for both beginners through experts over the Leonardo for most purposes. The Leonardo is useful for USB emulation however, so if you want to emulate an USB input device, then that is the board you will need to use. For all other applications, use the Uno.

      • Ted
        Posted June 22, 2014 at 12:05 pm | Permalink

        Hi,

        Could you explain usb emulation and how it might be important to me, as if I’m two years old please….

        Thanks much.

  6. jefferson arcos
    Posted March 21, 2014 at 12:17 pm | Permalink

    Hola, quisiera agradecerles porque necesitaba un consejo sobre cual de las dos comprar, ahora entiendo que debo empezar con el arduino uno para mi proyecto de implementacion de un automata. Muchas gracias y un saludo desde Colombia

  7. Anonymous
    Posted September 18, 2014 at 10:44 pm | Permalink

    I use Linux and while the UNO ( and Pro Mini clones from Inland) work fine, the Leonardo doesn’t. I found over the years that no two Linux boxes are ever alike. Each Linux box has its own personality and even subsequent reinstalls on the same box have different personalities! So, Leonardos on Linux is hit or miss depending on distro, the source of the distro (official, distro from magazines, etc.) and machine. I now avoid Arduinos with that Leonardo-like chip. Definitely, Leonardos and others with that type chip are not for beginners.

    Unrelated: If you use Linux, STAY AWAY from that piece of junk RFDuino!

  8. Peter Vazquez
    Posted January 16, 2017 at 12:16 pm | Permalink

    I think that the best Arduinos for learning are the Uno and the Mega2560. You start simple programming and then you move to use the Mega. The mega is about 3 or 4 Unos in one. So, when you go learning and decide that you need more outputs and inputs you play with the Mega. Please read the books that are viral in this, like the Arduino Cookbook, and the web sites that specialize in Arduino, like Adafruit, Element14, Make, Atmel, and many others (my apologies for those sites that I cannot remember when I write here…). But, anything you do to learn Arduino will be appropriate, Arduino is just a super learning experience and fun at the same time. Thanks for your attention.

6 Trackbacks

  • […] this Arduino Leonardo versus Uno – What’s Unaccustomed The Arduino club is instantly shipping their latest cosmos – the Leonardo. It is the initial Arduino to wield Atmel?s ATmegaXU4 series splinter among built-in USB. This replace is bulky and it has important profits. In appendage to the built-in USB, it submits more digital and analog broochs. This thorough conductor provides you the details you demand to experience to originate using it – pinout arguments, hardware capabilities, unfamiliar software libraries and more. Arduino Leonardo versus Uno – What’s Untried – read more about this project detail […]

  • By Arduino Leonardo | Fotografia Colombiana on July 1, 2012 at 12:35 pm
  • […] this Arduino Leonardo versus Uno – What’s Unaccustomed The Arduino club is instantly shipping their latest cosmos – the Leonardo. It is the initial Arduino to wield Atmel?s ATmegaXU4 series splinter among built-in USB. This replace is bulky and it has important profits. In appendage to the built-in USB, it submits more digital and analog broochs. This thorough conductor provides you the details you demand to experience to originate using it – pinout arguments, hardware capabilities, unfamiliar software libraries and more. Arduino Leonardo versus Uno – What’s Untried – read more about this project detail […]

  • By Arduino UNO + 3 LEDs | Arduino collector blog on July 13, 2013 at 5:49 am

    […] Thanks to a write-up detailing what improvements the Leonardo brings I added additional notations including pins not readily available on the actual Leonardo […]

  • […] Im Gegensatz zu Uno und Nano basiert der Leonardo auf einem anderen Microcontroller (ATmega32u4). Dieser hat den großen Vorteil, dass er keinen zusätzlichen USB-Chip benötigt, zudem lässt sich der Leonardo dadurch als HID-Eingabegerät (Tastatur oder Maus) am PC nutzen. Was zunächst komisch klingen mag, ist für manche Projekte sehr hilfreich. So lässt sich mit einem Leonardo und einem Beschleunigungssensor beispielsweise recht einfach ein Prototyp eines gestenbasierenden Eingabegerätes entwickeln. Auch ein eigener Joystick o.ä. lässt sich damit einfach verwirklichen. Zudem kann der Controller natürlich auch für die allermeisten anderen Arduino-Projekte verwendet werden. Die meiste Zusatzsoftware funktioniert auch mit dem Arduino Leonardo. Lediglich exotischere Libraries funktionieren damit u.U. nicht, was erfahrungsgemäß oft mit den Unterschieden bei den Timern im Gegensatz zum Uno zusammenhängt – aber das nur am Rande als Info. Genaueres dazu z.B. hier. […]

  • By Arduino Leonardo | wer bastelt mit? on July 18, 2016 at 7:07 pm

    […] D17 / SS / RX_LED ist nicht herausgeführt, man kann aber ein Kabel an die Kathodenseite der RX-LED anlöten. […]