So let’s say your using an Arduino in your project. You already have the hardware-based serial interface working with one portion of the project and need a second serial port for unrelated hardware. The obvious solution is to write one in software. But this is a place where working in the Arduino environment gets really hairy. Since there’s a layer of abstraction between the code and the hardware interrupts, it can be difficult to know if you are going to have timing problems. But there’s a new library available which seeks to reduce the latency of software-based serial communicationsย so that you don’t have to worry about it.
It’s named AltSoftSerial because it is a software-based serial library that is an alternative to the NewSoftSerial package. The former can function with just ย 2-3 microseconds of latency, while the latter has as much as a 174 microsecond hit. If it functions as advertised that’s quite an improvement. It’s not hard to put together a hardware test platform, and the example program is only about a dozen lines of code (which is the beauty of working in this environment) so give it a try if you have a free hour here or there.
I always have this problem.
Does former mean current or previous? and please don’t reply with “the former” or “the latter”.
Here’s your answer ๐
http://bit.ly/w3RStw
If I’m making a sentence about Thing A and Thing B, then the former would be Thing A and the latter would be Thing B
Former and latter follow the same order as the objects being addressed.
Think former as being first and latter being later.
Though it’s a bit formal, and requires that the reader have good memory.
Sorry… you kind of set yourself up for a smart-ass answer ๐
To add to Renee’s very well written description:
I usually think of Latter as Later (i.e. The Future), and Former is the opposite of Later (i.e. the Past)… in reference to the order in which you read the words ๐
I always cringe a little when authors do this. Relational references to a list in a previous sentence always bother me. But it gets bad when there’s a relational property of those two items, as there is here. So you’re left with, “is ‘former’ the old serial library, or the first item in the preceding list?” You just have to work it out by context. In this case, “former” meant the first item in the list (as it usually does), not the older library.
“formerly” ~= ‘previously’ (as in ‘the artist formerly known as Prince’)
An easy way to remember former vs latter is that ‘latter’ comes ‘later’.
I always use NewSoftSerial in my Arduino projects, so I’m going to have to check this out! Thanks HAD!
“The obvious solution is to write one in software. ”
Isn’t the obvious solution to use a more capable chip with multiple UARTs?
**coughxmegacough**
Yes, you are absolutely right, using a board with several real hardware serial ports is the obvious solution. That obvious solution is named “Arduino Mega” and generally is priced at $60.
If you already have a $30 Arduino Uno and need to connect 1 more device, a software-only solution starts to look pretty good.
Even better, on Teensy ($16), Wiring-S ($28) or Sanguino ($35), there is one extra hardware serial port, so a software solution lets you have TWO serial devices. I don’t believe there are any lower cost Arduino-compatible boards with two unused serial ports.
For full disclosure – I am the author of this library, and the author of Teensyduino (the add-on software that makes Teensy compatible with Arduino).
I wrote this library because people have trouble with the existing software serial libraries when they try to build projects which have simultaneous data transfer. Sure, an expensive board with lots of real serial ports is a perfect answer in a technical sense, but a more compatible software-only solution is a lot more “obvious” when it comes to hardware cost!
There is a whole world of other chips , you dont have to use arduino.
Btw, $60 buys you a FULL BLOWN 128MB 500MHZ Linux board and you use arduino?
Thanks Paul! – I have spent a number of hair pulling hours troubleshooting dropped data because of simultaneous rx/tx on hardware and software serial with a 328P, I’ll look forward to giving this a try in the future! ๐
– And btw, you may be able to get linux board for $60, but that still doesn’t compare to roll your own arduino compatible as I usually use. $5 or $6 gets you rolling with one of those…
@Paul
great library, thanks for sharing it.
@rasz
you got me interested here, which linux board do you use, and compared to the arduino or any other micro-controller how hard will it be to cross over and use it? (i’m used to direct control the hardware in c/c++. not really knowing how to write kernel drivers for linux…)
Out of curiosity, where does one procure this $60 assboard, and does it run on the few milliamps of current like the Arduino or have digital or analog IO readily available?
You’re problem is not that the chips have 1 UART. The problem is that you stick with only what you know.
First problem is the Arduino is obviously expensive. 30$… I can build one for 30$, including shipping costs for all components and have my PCB manufactured per piece (which is very expensive, PCB production in bulk is much cheaper)
The next problem, why UART? It’s outdated, not everyone has a real UART anymore. I know, let’s use USB! http://www.obdev.at/products/vusb/benefits.html and you can with a simple AVR. It’s even cheaper in hardware then any UART solution. And you get a free power source!
But you stick with what you know and pay 30$+ for an Arduino.
@Daid, Yes a ASCII output by one device readable by any other device by simply knowing the speed at which you’re transferring is totally comparable to implementing the USB protocol and writing software to read the data you want. Even if you’re paid minimum wage I’ll bet you the average hacker will be able to implement UART, go to work, and earn the $30 for the Arduino before most people finish figuring out how to code for USB.
UART may be outdated, but there’s a good reason people still use it.
Bravekit over in Ukraine has two STM32-based “header” boards. The STM32F100 board has two USARTS for $15, while the STM32F103 board for $26 has three. And lots of other I/O, of course. Their USARTS can do DMA-driven I/O too, for potentially very large buffers and less intervention needs from the CPU.
But programming such uC’s are undoubtedly much more difficult than Arduino compatibles. So thanks for working on this library.
“The next problem, why UART? Itโs outdated, not everyone has a real UART anymore. I know, letโs use USB!”
Who says you’re communicating with a computer?
What if you need full duplex communication between two boards but don’t have an extra wire for a clock? (This happened to me recently in a project at work. Custom cord we had a billion of, and they couldn’t give me an extra wire)
You are absolutely right! Use another chip and then do the many years to become an EE – never mind you just wanted to make a cool RFID reader for your carport, it’s completely worth it! /sarcasm.
In the ideal world one would just make a chip from logic gates and be done with it ๐
The former means the earlier mentioned one, the latter means the one that is mentioned later in the sentence.
*you’re
Use a chipKIT Uno32 from Digilent. PIC based Arduino clone that has multiple UARTS for $27.
ChipKit is impressive hardware, but the Arduino compatibility still leaves quite a lot to be desired.
Sure, you get multiple serial ports. But do ANY of them support buffered transmit? Admittedly Arduino added this only in 1.0, but it is present now on all hardware serial ports on Arduino. Teensyduino has had it for years. Without transmit buffering, you’ll really only be able to maintain full output rate on a single port, even even that requires wasting CPU cycles waiting in blocking transmit.
For another example, I recently tested my Encoder library with a ChipKit board.
http://www.pjrc.com/teensy/td_libs_Encoder.html
You can read about it near the bottom of the page in the “Low Performance Polling Mode” section. It’s a perfect example of incredible hardware that can’t do a fraction of what lesser hardware with good software can accomplish.
I’m sure Diligent (and maybe community contributions?) will eventually improve the software. But if you look the hardware alone, you’ll get a pretty unrealistic idea of what you can accomplish by using on the easy-to-use Arduino functions and Arduino libraries.
LOl, at all the pic fans and ‘you can get a full blown assboard for $ยฃ60’ guys, this isn’t for you, this is for people that are using an arduino or compatible atmega chips that could do with an extra port.
That’s the thing with tinkerers, you don’t necessarily know that you’ll need extra things until you have a need for them, why spend $60 when I can spend $10 and do stuff in software?
@Paul, thanks for taking the time to write the library, It’ll be much appreciated by a lot of people I’m sure.
Former…. the one that came first. Usually used in the temporal sense as in the Apple][ came before the IBM, where IBM would be the latter. Several examples above may be confusing as they refer to the structure of the sentence such as “IBM was the new kid on the block, knocking the APPLE][ from it’s king of the hill position” where in this instance IBM is the former IN THE SENTENCE.
That will either clear it all up… or totally confuse you.
Glad to be of help.
While your explanation is good, I just wanted to point out that your example is not. IBM was around decades before Apple. IBM was probably around before Jobs himself. If you mean the IBM PC, then, carry on.
IMHO ChipKit came about just so Microchip is part of the game, not that they needed to be. Of course the software support won’t be the same as Atmel.
However the real benefit for me is using the ubber-small PICs – those with only 4-6 pins that fit into real small places. Sure there is no GCC support for those but at this level of development C becomes impractical. Let’s not start the Atmel vs Microchip touchy-feely favorite chain.
Overall I agree that Ardunio’s contribution to the community was really in making the software platform available and extensible so what we have today is not easy to beat.
There are also 4 and 6 pins avr’s, they are called the Tinyxx, xx being two numbers you know..
I don’t think Atmel makes a 4pin AVR… 6pin tinyAVR yes, but not 4pin.
4 pins? I know there are 6 and 8 pins.
Bau, there’s nothing wrong with pics, except in the context of this article, they’re irrelevant, just as arm, intel, amd etc. are too ๐
what i want to know is .. what kind / brand breadboard is that?
nice grammar, Szczys.
You need to clarify what is meant by latency in this context… my immediate thought was that it was a turnaround time – i.e in a simple echo program how long does it take for me to see my character again.
Having read the website it’s not round trip latency in a simple echo test program context, but an interrupt latency – as in how much is having this software library in my software is going to potentially delay all other interrupts in the worst case.
Copying headline numbers without clear definition is never good…
Right. Interesting to know what we are actually talking about here…
Yes, you’re absolutely correct, the HAD summary dropped the word “interrupt” before latency.
Hopefully the take away message is still the fact that an improved/alternate software serial library is now available. Either that, or finer grammatical point of using “former” and “later”….
Or you could just use the Propeller where all the serial ports are implemented in software already.