First Look – the Arduino Leonardo

Introduction

Recently the Arduino Leonardo was released, and I’ve finally got my hands on one. Some have claimed that the Leonardo as the successor to the Arduino Uno board, however that is somewhat subjective.  In this article we have a look for ourselves and examine the differences between the Uno boards that we’re used to and the new Leonardo.

The board

Here it is unwrapped from the cardboard packet:

It uses the same physical footprint as the Uno, so no surprises there:

 Now to travel around the board and see what’s new. First is the microcontroller – we have the Atmel ATmega32U4:

There are several pros and cons to using the 32U4. The pros include:

  • More analogue inputs. As well as the usual A0~A5, digital pins 4,6,8,9,10 and 12 can be configured as A6~A11
  • It handles USB. So no more external USB controller MCU or the old FTDI chip. Supposedly this saves money, however the retail price in some markets don’t reflect this
  • More PWM pins – well one more. They’re now on D3, 5, 6, 9, 10, 11 and 13
  • There is a little more SRAM than the Uno, it is now 2.5 kB
  • SPI has moved – they’re now wired to the ICSP pins. So you now have D10~D13 seperate to SPI
And the cons:
  • SPI has moved – they’re now wired to the ICSP pins. So if you have any shields that use SPI – too bad, they’re out. The most common example of this will be Ethernet shields – you’ll need to modify them with some jumper leads to contact the ICSP pins
  • I2C has moved over to D2+3. So if you have any shields using I2C – they’ll need to be modified
  • Less flash memory – the bootloader uses 4 kB of the 32 kB flash (the Uno used 0.5 kB)

However you can get an adaptor shield to use older Arduino shields with the Leonardo.

For MCU to Arduino pin mapping, see here. Next, for more on the USB side of things – as the 32U4 takes care of USB – take heed of the following notes from arduino.cc:

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 secondaryATmega8U2 or ATmega16U2 processor).

There are some other changes to the board. Moving on, the next change is the USB socket. Do you recognise this socket?

Yes – micro USB. Thankfully (!) a growing number of mobile phones use this type for charging and USB connection, so you may already have a matching cable. Note that the Leonardo doesn’t include a cable, so if you’re an iPhone user – order yourself a cable with your Leonardo.

Next, the LEDs have been moved to the edge of the board. You can see them in the above image to the right of the USB socket. No more squinting through shields at strange angles to check the TX/RX lights. However this isn’t a new invention, our friends at Freetronics have been doing this for some time. Furthermore, the reset button has been moved to the corner for easier access.

There are also seperate connectors for the I2C bus – next to AREF, which should make modifying existing shields a little easier:

 Finally, due to the reduction in components and shift to SMD – there is what could almost be called a large waste of space on the board:

A few extra user LEDs wouldn’t have been a bad idea, or perhaps circuitry to support Li-Po rechargeable batteries. However the argument will be “that’s what a protoshield is for”. Just saying… As for the rest of the hardware, the specifications can be found here.

Finally, the Leonardo is available in two versions – with and without headers. This makes it easier to embed the Leonardo into fixed applications as you can directly solder to the various I/O pins. An alternative to this would instead be the Freetronics LeoStick, as it is much smaller yet fully compatible.

Software

First – you need to drag yourself into Arduino IDE v1.0.1. Note you can run more than one version of the IDE on the same machine if you don’t mind sharing the same preferences file. Next, the Leonardo doesn’t reset when you open the serial monitor window (from arduino.cc) –

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:

Using the 32U4, you also have two serial ports. The first is the emulated one via the USB, and the second is the hardware UART on digital pins 0 and 1. Furthermore, the Leonardo can emulate a USB keyboard and mouse – however with a few caveats. There is a section on the Leonardo homepage that you should really read and take note of. But this emulation does sound interesting, and we look forward to developing some interesting tools to take use of them, so stay tuned.

Conclusion

There is nothing wrong with the Leonardo board, it works as described. However you could consider this a virtual “line in the sand”, or a new beginning. Due to the changes in the pinouts shields will need to be redesigned, and for those of you still programming in Arduino v23 – it’s time to get up to speed with v1.0.1. If you need the special USB functions, keyboard and/or mouse emulation, or are happy with the changes and can get one for less than the cost of a Uno – great.

Here’s a video from the main man Massimo Banzi:

However if you’re looking for your first Arduino board – this isn’t the board for you right now. There are too many incompatible shields out there, and the inability to cheaply replace the microcontroller will see some beginners burn out their first couple of boards rendering them useless. Get yourself an Arduino Uno or compatible board such as the Freetronics Eleven.

In conclusion, classifying the Leonardo board as good or bad is not a simple decision. It may or may not be an improvement – depending on your needs. Right now – for beginners, this is not the board for you. For those who understand the differences between a Uno and Leonardo, sure – no problem. Frankly, I would get a LeoStick instead.  At the end – it’s up to you to make an informed decision.

In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column? And join our friendly Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.
The following two tabs change content below.

John Boxall

Founder, owner and managing editor of tronixstuff.com.

24 Responses to “First Look – the Arduino Leonardo”

  1. Lauszus says:

    H,
    Great post.
    I found a small bug n the Leonardo frmware, as the power-on reset ddn’t work correctly.
    See my pull request at gthub for more detals: https://gthub.com/arduno/Arduno/pull/93

    Regards
    Lauszus

    • Fractal says:

      That’s odd.
      I dd thnk that my leostck, runnng the v1.0.1 bootloader, had broken auto reset – turns out I hadn’t selected the seral port for the ‘sketch’ USB devce.
      Perhaps ths s somethng smlar, I don’t thnk the hardware s dfferent enough to change the reset behavour – you could try an unmodfed bootloader, and selectng the seral port whle the sketch s runnng.

      When t can’t fnd a leonardo to auto-reset, the IDE wll upload to any usb seral devce that appears n the 10s t says ‘uploadng’. Ths led me to beleve my auto reset wasn’t workng, but n fact, I hadn’t selected the correct seral port.
      If not, then thanks for the patch!

  2. Ajmal Ghanty says:

    H John,

    Thanks for the nce post. One thng I’d lke to ask you. Wouldn’t the Arduno Mega be better n terms of processng power and flash than the Uno and the Leonardo or t doesn’t really make a dfference?

    Knd regards,

    Ajmal

  3. Davidb says:

    The ssues wth seral and the uno bug me enough now. The ssues wth the leonardo that you’ve descrbed would have me throwng t through the wndow.

    Also you cannot run multple IDE’s wthout conflct. They share the same preferences fle whch s an absolute pan f you’re tryng to keep your v23 and v1 sketches separate.

    I thnk mplementatons lke the leoStck are the real future of ths because you can put up wth the ntrcaces of the product for the convenence of the sze. The leonardo as a replacement for the uno s unrealstc. There are a lot of people wth atmega328 chps sttng n breadboards whle they work on ther next project. Not practcal wth a full arduno board.

    BTW seeng as you have one to play wth… What’s the power consumpton lke?

    • John Boxall says:

      Thanks for your feedback. I hadn’t consdered the preferences fle as I never tnker wth that.
      I thnk we can all agree that the LeoStck s a great mplementaton, and can be consdered ‘breadboard frendly’ wth the pns n t :)
      Sorry but I gave the Leonardo away ths mornng so can’t measure t.
      cheers
      John

  4. Fractal says:

    Excellent post, especally hghlghtng the varous seral comms changes!
    There are a few bugs n the leonardo mplementaton, manly due to tmer2 beng used for USB.
    Turns out, f you use the tone() lbrary, ths crashes the IC (no auto reset, t’s properly borked (untl manual reset))
    To do more fancy thngs wth the keyboard emulaton, a lttle bt of modfcaton s requred to do more useful functons (make the sendReport functon publc), though ths could be seen as a ‘safety’ measure!
    Interrupts don’t work out the box – but a few lnes n pns_arduno.h, and the macros from a teensy wll fx that.

    Playng wth the leostck, the very rapd USB prototypng s great! There’s an example sketch that does the approprate keypresses to use the IDE to reprogram tself- that’s crazy!
    In addton, f not scared off by makefles, t’s easy to modfy the USB drvers, e.g. request 100ma nstead of 500ma, f you run the arduno off an unpowered hub, wth an OS that complans about power.

    Interestng that they have changed (n v1.0.1) not only the bootloader from what t was before the offcal release (‘dskloader’ to ‘caterna’), but now the IDE wll wat for ~10s f t can’t connect (to a leonardo), and upload to any seral port that appears wthn those seconds. Why? Because now t’s very possble to break the USB connecton by messng up n software, and wndows can enumerates USB devces too slowly to beat the bootloader tmeout.

    However, the most extng thng s that whatever people do wth ths can be ported easly to the 8/16u2 controllers on all UNOs. Snce the ardunoISP sketch s fxed n v1.0.1, wth a Leonardo and an UNO, a great amount of USB possbltes arse. Already, people have made a prank UNO, that does keyboard malarkey when plugged n.

    The Leostck forums are a useful place for varous modfcatons to the software, and I look forward to seeng what people do wth the 32u4!

    • John Boxall says:

      Thanks for your detaled reply. Yeah, the ssues about the Leonardo came n ths mornng after postng. The retalers really need to tell people ‘ths s not for begnners’ etc. I love the lttle LeoStck, Jon and Marc should be very proud :)

    • Lauszus says:

      The USB functonalty doesn’t use tmer2 – the problem wth the tone() lbrary s that the Leonardo doesn’t have a tmer2, so that’s why t crashes. But t has now been fxed: https://gthub.com/arduno/Arduno/pull/102

      The external nterrupt worked fne for me – I even added support for INT2 and INT3 as well. See: https://gthub.com/arduno/Arduno/pull/92

      I must say that I’m actually very pleased wth the Leonardo, but yes I wouldn’t recommend t to a begnner!

      • Fractal says:

        Ah, that makes sense!
        Nce job contrbutng, you are an asset to the communty :)
        Good to hear the nterrupts are fxed now.
        Let’s hope v1.02 doesn’t ntroduce more bugs than t fxes!

      • John Boxall says:

        Thanks.
        Yeah, hopefully they can st on the current framework for a few years.
        However I have a suspcous feelng that as newer technology appears (e.g. Cortex M0/M3) etc at a cheaper prce, the Arduno world wll become more fragmented and de “a death of a thousand cuts”. Frankly they should have stayed wth the Uno R3 and held out untl the Due was released. Such s lfe.

  5. I thnk ths s probably a sgn of thngs to come, the Arduno Due may very well have to adopt dfferent pnout on the sheld header as well. It s also gong to become more complcated by a wave of 3.3V (or lower) requrements. Between shelds needng to use IOREF and odd pn mappngs, t wll be much harder to make wdely acceptable shelds.

    • Fractal says:

      Well, the wrtng has been on the wall snce the UNO (R2): New pns for I2C, and an IOREF pn.
      Really, I guess the plans for the Due, and Leonardo need these changes.
      Due so far looks dentcal to the mega pnout, but wth the new UNO/Leo pns.
      In some ways, I’d have personally preferred them movng the headers, to not have that awkward 0.16″ gap, though the loss n backwards compatblty from that would be huger than the opton they have gone for.

      If the Due contnues to use the ATSAM3X8E, t’s gong to be 3.3v. Any new sheld ought use the new IOREF pns. I2C can easly be duplcated on the A5, and A4 pns, probably wth a solder brdge to attach/detach the analog pns for users of the latest boards. SPI s more complcated, but usng the 6 pn header should work wth most duemlanove clones.

      Unfortunately, the varous changes add to the cost of shelds – more vared headers (6, 8, 8, 10, and ICSP), voltage swtchng consderatons, backwards compatblty traces, and solder brdges. I guess that the net prce changes wll be small n comparson to the cost of gettng a sheld fabbed, soldered, and shpped though.

      Interestng tmes for Arduno, t should be nterestng to see how they cope wth the ‘threat’ of what appears to be a new wave of small, cheap, ARM powered, lnux computers.

  6. madworm says:

    And dd they fx the pn-spacng? NO. Wth all that free space they could easly have added a 2nd row of headers… FAIL.

  7. lectroleevin says:

    There s a Leonardo clone from Olmex (based n Bulgara) that has a L-Po charger on board: https://www.olmex.com/dev/olmexno-32u4.html

  8. Dark Alchemist says:

    WOW, I am havng flashbacks to my Commodore 64 days (1983-1988) where t’s seral port was all software. Dd we just go forward n reverse? Don’t lke t.

    • David Zanetti says:

      It’s not qute the same, snce the USB functons are provded by actual hardware on the MCU. What knd of USB devce you want s mplemented n software, sure. The seral drvers n the lbrares actually do a lot of heavy lftng even wth a hardware USART anyway.

      It also fxes an annoyng problem wth the 328P based Ardunos – only one seral port. Now you can get two, one on the sheld headers and one avalable over USB, and they don’t conflct. That’s a really postve change.

      • Dark Alchemist says:

        Well, I am not alone n not lkng t and they should gve us back our memory footprnt and get t back to a dedcated chp. I don’t need to be told by them how much better t s to have t on board when really t sn’t for many reasons.

  9. Jernej Plesnar says:

    have a problem to receve any message from arduno seral communcaton throught usb. can anyone please share a tested seral example for arduno leonardo, because am losng my mnd for searchng hours on nternet.

  10. programmer says:

    have the same problem , try to connect leonardo wth bluetooth module but the seral com port for the bluetooth fre fly module “not appear wth the other seral ports n tools of arduno IDE “, please what have to do????:(

Trackbacks/Pingbacks


Leave a Reply

Subscribe via email

Receive notifications of new posts by email.

The Arduino Book

Arduino Workshop

Für unsere deutschen Freunde

Dla naszych polskich przyjaciół ...

Australian Electronics!

Buy and support Silicon Chip - Australia's only Electronics Magazine.

Use of our content…

%d bloggers like this: