Russell's Blog

New. Improved. Stays crunchy in milk.

Trouble with SoftSerial on the Arduino Leonardo

Posted by Russell on May 25, 2012 at 12:05 p.m.
While I was wandering around at Maker Faire last weekend, I heard someone say, "Woah, is this the Leonardo?" And lo, there was a handful of Arduino Leonardo boards lined up on a shelf for sale. I instantly grabbed one, and bundled it home to play with it.

The Leonardo is Arduino's latest board, announced last September. It uses the Atmega32u4 chip, which has onboard USB. This has two important implications; first, the Leonardo costs less than the Uno, and second it will be able to operate in any USB mode. That means people can make Human Interface Devices (HID), like mice and keyboards and printers, with Arduino, and present themselves to the host using the standard USB interfaces for those devices. That means you can build things that don't need to talk via serial, and use the host's built-in drivers for mice and printers and whatnot. This is a big step forward for Open Hardware.

Anyway, I'm developing an little remote environmental data logger to use for part of my dissertation project, and I thought I'd see if I could use the Leonardo board in my design. I'm using the Arduino board to talk to an Atlas Scientific pH stamp, which communicates by serial. It works fine on the Uno with SoftwareSerial (formerly known as NewSoftSerial until it was beamed up into the Arduino Core mothership).

Unfortunately, it didn't go so well on the Leo. The board can send commands to the pH stamp, but doesn't receive anything. I swapped in an FTDI for the pH stamp, and confirmed that the Leonardo is indeed sending data, but it didn't seem to be able to receive any characters I sent back. I tried moving the rx line to each the digital pins, and had no luck. Here is my test program :

#include <SoftwareSerial.h>

#define rxPin 2
#define txPin 3

SoftwareSerial mySerial( rxPin, txPin );

byte i;
byte startup = 0;

void setup() {

  mySerial.begin( 38400  );
  Serial.begin(   9600   );
}

void loop() {
  
  if( startup == 0 ) {             // begin startup
    for( i = 1; i <= 2; i++ ) {
      delay( 1000 );
      mySerial.print( "l0\r" );    // turn the LED off
      delay( 1000 );
      mySerial.print( "l1\r" );    // turn the LED on
    }
    startup = 1;                   // don't re-enter
  }                                // end startup

  Serial.println( "taking reading..." );
  mySerial.print( "r\r" );
  delay(1000);
  
  Serial.println( mySerial.available() );
  
}
On the Uno, I see the number increasing as the read buffer fills up :
taking reading...
0
taking reading...
0
taking reading...
7
taking reading...
16
taking reading...
16
On the Leo, it seems that nothing ever gets added to the read buffer, no matter how any characters I send over from the FTDI or which pins I used for the rx line :
taking reading...
0
taking reading...
0
taking reading...
0
taking reading...
0
taking reading...
0
taking reading...
I really wanted to see if I was crazy here, but I'm one of the first people among the General Public to get their hands on a Leonardo board. So, I started talking with Ken Jordan on #arduino on Freenode (he goes by Xark) who has a similar board, the Atmega32u4 Breakout+. It's based on the same chip as the Leonardo, but it has different pinouts and a different bootloader. He flashed the Leonardo bootloder onto his board, and worked out the following pin mapping :
Arduino 1.0.1     Adafruit         ATMEL
digitalWrite pin  atmega32u4+ pin  AVR pin function(s)
----------------  ---------------  ------------------
D0                D2               PD2 (#INT2/RXD1)
D1                D3               PD3 (#INT3/TXD1)
D2                D1               PD1 (#INT1/SDA)
D3#               D0               PD0 (#INT0/OC0B)
D4/A6             D4               PD4 (ICP1/ADC8)
D5#               C6               PC6 (OC3A/#OC4A)
D6#/A7            D7               PD7 (T0/OC4D/ADC10)
D7                E6 (LED)         PE6 (INT6/AIN0)
D8/A8             B4               PB4 (PCINT4/ADC11)
D9#/A9            B5               PB5 (OC1A/PCINT5/#OC4B/ADC12)
D10#/A10          B6               PB6 (OC1B/PCINT6/OC4B/ADC13)
D11#              B7               PB7 (OC0A/OC1C/PCINT7/#RTS)
D12/A11           D6               PD6 (T1/#OC4D/ADC9)
D13#  (LED)       C7               PC7 (ICP3/CLK0/OC4A)
D14   (MISO)      B3               PB3 (PDO/MISO/PCINT3)
D15   (SCK)       B1               PB1 (SCLK/PCINT1)
D16   (MOSI)      B2               PB2 (PDI/MOSI/PCINT2)
D17   (RXLED)     B0               PB0 (SS/PCINT0)
D18/A0            F7               PF7 (ADC7/TDI)
D19/A1            F6               PF6 (ADC6/TDO)
D20/A2            F5               PF5 (ADC5/TMS)
D21/A3            F4               PF4 (ADC4/TCK)
D22/A4            F1               PF1 (ADC1)
D23/A5            F0               PF0 (ADC0)
-     (TXLED)     D5               PD5 (XCK1/#CTS)
-     (HWB)       -  (HWB)         PE2 (#HWB)
This was derived from the ATmega 32U4-Arduino Pin Mapping and ATMEL's datasheet for the ATmega32U4 chip. Once that was worked out, he flashed my test program onto his board, and also found that SoftwareSerial could transmit fine, but couldn't receive anything.

Ken rummaged around a little more, and had this to say :

The SoftSerial seems to use PCINT0-3 so there seems to me a minor problem in Leo-land in that only PCINT0 appears to be supported (and it is on "funky" output for RXLED). Hopefully I am just misunderstanding something (but it imay be the interrupt remap table is incorrect for Leo).
Then he disappeared for a little while, and came back with :
I have confirmed my suspicion. When I disassemble SoftSerial.cpp.o I can see that only __vector_9 is compiled (i.e., one of 4 #ifdefs for PCINT0-3) and the interrupt vector 10 is PCINT0 (0 is reset vector so offset by one makes sense). So, unless you hook serial to RXLED pin of CPU I don't believe it will work with the current libs.

Also I believe the Leo page is just wrong when it says pins 2 & 3 support pin change interrupts (I think this was copied from Uno but it is incorrect, the only (exposed) pins are D8 D9 D10 and D11 that support PCINT according to the ATMEL datasheet (and these are PCINT 4-7 not the ones in the interrupt mapping table AFAICT).

I believe this is where I can stop worrying that I'd be wasting the time of the core Arduino developers, and say quod erat demonstrandum; it a bug in SoftwareSerial. Hopefully they can update the Arduino IDE before the boards hits wider distribution.

Update : So, it turns out that this is a known limitation of the Leonardo. David Mellis looked into it, and left this comment :

You're right that the Leonardo only has one pin change interrupt, meaning that the software serial receive doesn't work on every pin. You should, however, be able to use pins 8 to 11 (inclusive) as receive pins for software serial. Additionally, the SPI pins (MISO, SCK, MOSI) available on the ICSP header and addressable from the Arduino software as pins 14, 15, and 16 should work.
He is, of course, correct. I'm not sure why my testing didn't work on pins 8-11, but they do indeed work fine. Unfortunately, this means that the Leonardo is not compatible with a number of cool shields. The Arduino SoftSerial Library Reference documentation has been updated with a more detailed list of limitations.
womens mountain biking on May 13, 2013 at 11:21 a.m.

You may comment on the quantity of the blog. You could present its high grade. Your blog observations would extend your earnings. womens mountain biking

Luminess Air Reviews on May 13, 2013 at 2:44 p.m.

Nice post.Thank you for taking the time to publish this information very useful! I've been looking for books of this nature for a way too long. I'm just glad that I found yours. Looking forward for your next post. Thanks :)

grs on May 13, 2013 at 3:04 p.m.

Great post I would like to thank you for the efforts you have made in writing this interesting and knowledgeable article.
graphic designer san francisco

Danna on May 13, 2013 at 3:43 p.m.

Összehasonlítani abercrombie
"almát almával", ha ránézünk r4 3ds a becsléseket a különböz? cégek. Itt vannak.

Ema on May 13, 2013 at 4:02 p.m.

Prendi abercrombietutto per iscritto. Assicuratevi di ottenere r4 3ds una copia del contratto.

Social Bookmarks on May 13, 2013 at 10:20 p.m.

I will instantly grab your rss feed to stay informed of any updates. Social Bookmarks

onsite it services gulf breeze fl on May 14, 2013 at 3:50 a.m.

If generating a frequent line is residing out noisy, then maintaining a everyday weblog is residing at the top of your respiratory system. For a few several weeks there, I was shrieking like a banshee.

royalty free music on May 14, 2013 at 10:07 a.m.

I was very pleased to find this site. I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post

here on May 14, 2013 at 10:15 a.m.

Pretty insightful post. Never thought that it was this simple after all.here

power converter system on May 14, 2013 at 11:05 a.m.

I was very pleased to find this site. I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.

michael fiore text your ex back review on May 14, 2013 at 11:58 a.m.

You can post on the ease of use for the blog. You might author it's sweet. Your blog message shall maximize your leads. michael fiore text your ex back review

Purchase YouTube views on May 14, 2013 at 12:27 p.m.

Good work.. The post is written in very a good manner and it entails many useful information..I really love the way you discuss this kind of topic .

free bingo sites on May 14, 2013 at 12:52 p.m.

Now you have a good critically realistic display that gives brilliant sorts of ways to share individuals with this report achieving here's the approach. Recently i discovered these types of remarkably convenient. Done adequately along with thank you.

Small Business Directory on May 14, 2013 at 3:59 p.m.

That means you can build things that don't need to talk via serial, and use the host's built-in drivers for mice and printers and whatnot.
Small Business Directory

benz on May 14, 2013 at 4:09 p.m.

Nice post.Thank you for taking the time to publish this information very useful! I've been looking for books of this nature for a way too long. I'm just glad that I found yours. Looking forward for your next post. Thanks :)
ecigarette

wedding venues in CT on May 15, 2013 at 9:24 a.m.

Good work.. The post is written in very a good manner and it entails many useful information..I really love the way you discuss this kind of topic .

rent to own car on May 15, 2013 at 9:47 a.m.

Every word in this piece of work is very clear and your passion for this topic shines. Please continue your work in this area and I hope to see more from you in the future.

best upright vacuum on May 15, 2013 at 10:06 a.m.

There are so many comments here that are really interesting and useful to me thanks for sharing a link especially for sharing this blog.

beach wedding favor on May 15, 2013 at 10:13 a.m.

Thanx for a very interesting web site. Where else could I get that kind of info written in such an ideal approach? I have a undertaking that I’m just now working on, and I’ve been at the look out for such information.

family picture ideas on May 15, 2013 at 10:22 a.m.

The website is looking bit flashy and it catches the visitors eyes. Design is pretty simple and a good user friendly interface.....

Port St Lucie kitchen remodel on May 15, 2013 at 10:33 a.m.

Good posting, im subscribing to your rss. Thanks for sharing a very informative article. Many thanks once more. as thanks

Responsible Service of Alcohol on May 15, 2013 at 10:40 a.m.

The website is looking bit flashy and it catches the visitors eyes. Design is pretty simple and a good user friendly interface....

yola-termindas on May 15, 2013 at 10:44 a.m.

That means you can build things that don't need to talk via serial, and use the host's built-in drivers for mice and printers and whatnot. This is a big step forward for Open Hardware..

Feel Free To visit My Webpage : Visual Impact Muscle Building Click Here

Heart Rate Monitor Watch on May 15, 2013 at 10:45 a.m.

Nice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which I need, thanks to offer such a helpful information here.

driving lessons liverpool on May 15, 2013 at 10:53 a.m.

A very nice and useful information provided through this blog and like such blogs which always provides such educational information and it is nice to read it..........:)

cat tree on May 15, 2013 at 11:14 a.m.

Good blog,thanks for your sharing so great article.This is a regular article.hope you can keep writing more good aritcle....

building maintenance service toronto on May 15, 2013 at 11:24 a.m.

Your article is very exciting and informational. I am trying to decide on a career move and this has helped me with one aspect.

diamond loan on May 15, 2013 at 11:36 a.m.

Thanks for the marvelous posting! I certainly enjoyed reading it, you may be a great author. I will be sure to bookmark your blog and will come back sometime soon.

delonghi esam3300 magnifica coffee machine on May 15, 2013 at 12:28 p.m.

Awesome post. Your article affects a lot of "burning" problems of our society. It is impossible to be indifferent to these challenges.delonghi esam3300 magnifica coffee machine

luminess air on May 15, 2013 at 1:47 p.m.

Nice blog having nice information. some times we ignore this sort of things & also suffer a lot as well. However we can save a lot with the assistance of these tips for example time etc.

Speeding ticket lawyer in NJ on May 15, 2013 at 3:43 p.m.

The website is looking bit flashy and it catches the visitors eyes. Design is pretty simple and a good user friendly interface..

buy colored contacts on May 15, 2013 at 3:50 p.m.

Thanx for a very interesting web site. Where else could I get that kind of info written in such an ideal approach? I have a undertaking that I’m just now working on, and I’ve been at the look out for such information.

Florida Seo on May 15, 2013 at 5:12 p.m.

Thanks for this exciting post. It is well written and has some great content.Florida Seo

josep on May 15, 2013 at 8:25 p.m.

Arduino Leonardo boards lined up on a shelf for sale. I instantly grabbed one, and bundled it home to play with it. buy Google reviews

matthewlabeouf on May 15, 2013 at 9:19 p.m.

An inspiring Share, It is really an incredible work, It has suitable information, I presently wanted to say that you have really so motivating and very informative post. Thanks for your amazing postingdog sitting mississauga

matthewlabeouf on May 15, 2013 at 9:21 p.m.

It is amazing posting and incredible work, It has suitable information, I presently wanted to say that you have really so motivating and very informative post. Thanks for wonderful postingsuperior home inspection edmonton

matthewlabeouf on May 15, 2013 at 9:22 p.m.

It is amazing posting and incredible work, It has suitable information, I presently wanted to say that you have really so motivating and very informative post. Thanks for wonderful postingrepair doors toronto

matthewlabeouf on May 15, 2013 at 9:23 p.m.

It is amazing posting and incredible work, It has suitable information, I presently wanted to say that you have really so motivating and very informative post. Thanks for wonderful postingwindow installation toronto

matthewlabeouf on May 15, 2013 at 9:24 p.m.

An inspiring Share, It is really an incredible work, It has suitable information, I presently wanted to say that you have really so motivating and very informative post. Thanks for your amazing postingBest driving school in Edmonton

steve on May 16, 2013 at 2:04 a.m.

That is among the very good posts you will find inside the world wide web describing anything in depth about the topic.http://asbestosdefinition.org/how-to-identify-asbestos-tile/

s4 flip case on May 16, 2013 at 7:29 a.m.

Thanks for the code and what exactly what I'm looking for, going to try and get my mate recover...

asd on May 16, 2013 at 8:08 a.m.

Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates.
Important tips to make money by google adsense

josepmedia on May 16, 2013 at 10:18 a.m.

That means you can build things that don't need to talk via serial, and use the host's built-in drivers for mice and printers and whatnot. This is a big step forward for Open Hardware. salmon oil for dogs

hammad on May 16, 2013 at 9:39 p.m.

Anyone that has obtained their licence before the 1st of January 1997 is entitled to drive a car and a trailer with a combined weight of 8,250kg. || towing courses || This licence also entitles the driver to drive a minibus that is towing a trailer in excess of 750kg.

HTC One M7 Case on May 17, 2013 at 6:21 a.m.

Thanx for a very interesting web site. Where else could I get that kind of info written in such an ideal approach? I have a undertaking that I’m just now working on, and I’ve been at the look out for such information and if you're interested in HTC One M7 case then could go vanberry.com

finanical options on May 17, 2013 at 9:27 a.m.

The post is written in very a good manner and it entails much useful information for me. I am happy to find your distinguished way of writing the post

teach english in india on May 17, 2013 at 10:29 a.m.

You can post on the ease of use for the blog. You might author it's sweet. Your blog message shall maximize your leads.
teach english in india

natural dog food on May 17, 2013 at 10:36 a.m.

Your page is sweet, your graphics are great, and what's more, you use videos that are relevant to what you're saying. You're definitely one in a million, man!
natural dog food

stellafin on May 17, 2013 at 4:21 p.m.

This is indeed a great blog post for all us visitors.

somanabolic muscle maximizer scam

border broke on May 17, 2013 at 4:28 p.m.

This is exactly what I was looking for. Thanks for sharing this great article! That is very interesting Smile I love reading and I am always searching for informative information like this!

hammad on May 17, 2013 at 10:06 p.m.

You can break your sugar habit in just 21 days and this easy-to-follow, customizable detox can get you there. || 21 day sugar detox book || Many people going through this program have found that they were able to kick feelings of “false hunger”, eat less food naturally, and lose weight, all without feeling deprived or hungry!

Kardashian tape on May 17, 2013 at 10:35 p.m.

You can post on the order experience for the blog. You might forward it's mind busting. Your blog explication could skyrocket your viewers.Kardashian tape

hammad on May 17, 2013 at 10:47 p.m.

We here at Natural K9 Supplies know that you can always run down to the local supermarket or department store and pick up whatever is there on the shelves for your pooch, but would you use just any type of product on a member of your family that you love so much? Most likely, you would not do that. || ORGANIC DOG FOOD || The all natural dog supplies for your dog that you will find here at Natural K9 Supplies are so much healthier simply due to the fact that chemicals with the potential to harm your dog are never used.

matthewlabeouf on May 18, 2013 at 12:46 a.m.

It is amazing posting and incredible work, It has suitable information, I presently wanted to say that you have really so motivating and very informative post. Thanks for wonderful postingwindow contractor toronto

matthewlabeouf on May 18, 2013 at 12:47 a.m.

An inspiring Share, It is really an incredible work, It has suitable information, I presently wanted to say that you have really so motivating and very informative post. Thanks for your amazing postingEdmonton driving schools

matthewlabeouf on May 18, 2013 at 12:48 a.m.

An inspiring Share, It is really an incredible work, It has suitable information, I presently wanted to say that you have really so motivating and very informative post. Thanks for your amazing postingtoronto door

matthewlabeouf on May 18, 2013 at 12:49 a.m.

It is amazing posting and incredible work, It has suitable information, I presently wanted to say that you have really so motivating and very informative post. Thanks for wonderful postingdog sitting woodbridge

bellasowan on May 18, 2013 at 2:53 a.m.

I would like to thank you for the initiatives you have created in composing this content. I am expecting the same best perform from you later on as well. Actually your innovative composing capabilities has motivated me to begin my own Blog Engine weblog now. Really the writing a weblog is growing its pizza quickly. Your create up is a excellent example of it.Auto Headliner Repair Fort Lauderdale Pompano Beach Broward County

hammad on May 18, 2013 at 4:18 p.m.

In early human societies, mothers weaned their children by chewing up their food and then passing it into the infantile mouth by lip-to-lip contact- || french kissing tips || which involved a considerable amount of tonguing and mutual mouth pressure. Our species practiced this behavior for over a million years, and adult tongue kissing today is considered a relic gesture stemming from these origins.

Skycig coupon on May 18, 2013 at 7:37 p.m.

You can write about the surprise freebies on the blog. You might insert it's marquee. Your blog emotions can increase your admirers.
Skycig coupon

hammad on May 18, 2013 at 10:22 p.m.

Ever wondered why when you sometimes list a player at a low price in the FUT Market, it is bought within miliseconds? || fifa ultimate team millionaire autobuyer software || This was probably someone using an Autobuyer.

John Locke on May 19, 2013 at 4:36 a.m.

I simply stumbled in the course of your website as i was seeking about Askjeeve. I must many thanks for with all the time and energy to discuss your ideas inside your weblog. We are certain in order to save your web site for extended looking at.

how to buy youtube views

coach outlet on May 19, 2013 at 9:18 p.m.

A blog is something that can Coach Factory only benefit you and not hurt you, most of Coach Factory Online air max the time that is. Once you establish a presence online via louis vuitton outlet blog you then create more potential followers for you and your business that you didn’t previously have. You see there is much to gain when you create a blog, so read through this article and see how blogging can help you.



Choose a domain name that immediately tells potential readers what your blog is about. coach outlet It’s not likely that you louboutin are going to ralph lauren be able to procure a name like but, your blog is more likely to be about some particular aspect Hogan of your subject. Incorporate that aspect into the domain name along with your louis vuitton Coach Factory Outlet overall focus.



Don’t be afraid to stretch out your louis vuitton hand and ask your reader for a donation. Your loyal readers, in particular, will be likely to donate some to coach outlet your cause. If your blog is valuable enough, people will realize it. They will also realize that, longchamp not Coach Factory louis vuitton outlet Online only does Coach Outlet it cost you money to produce your blog, your time is valuable.



Make sure that you have a blog mailing list started early. The sooner you get this started, the more time you coach outlet will have gucci to make that list larger. Once your blog is more established, this list will be used to bring in money, and you will be thankful that you already took care of this.

Ignore this field:
 optional; will not be displayed
Don't put anything in this field:
 optional
Don't put anything here:
Leave this empty:
URLs auto-link and some tags are allowed: <a><b><i><p>.