Trouble with SoftSerial on the Arduino Leonardo
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 :
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... 7 taking reading... 16 taking reading... 16
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 :taking reading... 0 taking reading... 0 taking reading... 0 taking reading... 0 taking reading... 0 taking reading...
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.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)
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.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.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).
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.
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
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 :)
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
Ö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.
Prendi abercrombietutto per iscritto. Assicuratevi di ottenere r4 3ds una copia del contratto.
I will instantly grab your rss feed to stay informed of any updates. Social Bookmarks
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.
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
Pretty insightful post. Never thought that it was this simple after all.here
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.
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
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 .
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.
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
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
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 .
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.
There are so many comments here that are really interesting and useful to me thanks for sharing a link especially for sharing this blog.
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.
The website is looking bit flashy and it catches the visitors eyes. Design is pretty simple and a good user friendly interface.....
Good posting, im subscribing to your rss. Thanks for sharing a very informative article. Many thanks once more. as thanks
The website is looking bit flashy and it catches the visitors eyes. Design is pretty simple and a good user friendly interface....
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
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.
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..........:)
Good blog,thanks for your sharing so great article.This is a regular article.hope you can keep writing more good aritcle....
Your article is very exciting and informational. I am trying to decide on a career move and this has helped me with one aspect.
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.
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
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.
The website is looking bit flashy and it catches the visitors eyes. Design is pretty simple and a good user friendly interface..
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.
Thanks for this exciting post. It is well written and has some great content.Florida Seo
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
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
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
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
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
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
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/
Thanks for the code and what exactly what I'm looking for, going to try and get my mate recover...
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
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
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.
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
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
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
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
This is indeed a great blog post for all us visitors.
somanabolic muscle maximizer scam
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!
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!
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
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.
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
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
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
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
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
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.
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
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.
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
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.

