In a recent Thread the usual complaints were made about the SoftwareSerial library not functioning alongside the Servo library. In Reply #17 @oric_dan suggested a limited version of SoftwareSerial for the Uno that would work in parallel with other libraries.
That prompted the realization that I had a few projects that together probably contained all of the concepts necessary to achieve that.
The attached code sss.ino is the result. It uses Pins 3 (INT1) and 4 and Timer2A and seems to work quite happily with the Servo library. It is only intended for use on an Uno (or standalone Atmega 328).
The file DemoSimpleSoftSerial.ino illustrates the use of sss.ino. And the file DemoPartner.ino is a program that I have run on a Mega (because it has multiple hardware Serial Ports) to receive data from and send data to the Uno.
I concluded that there is little advantage in converting the code into a Class or into a proper Library. Because of its simplicity there cannot be multiple instances of it - in other words you can only use it to add one Software Serial connection to an Uno. Because of the way the Arduino manages projects the variables in sss.ino are not accessible to the code in the main .ino file but the various functions are. I have prefixed the names of all the functions and variables with sss to reduce the possibility of clashing with names in other parts of a project.
To use the code you just need to add a copy of the file sss.ino into the Arduino project. Using the demo program attached you would put both of the file DemoSimpleSoftSerial.ino and sss.ino into a directory called DemoSimpleSoftSerial.
Interestingly the code works exactly as I expected it would when the idea first occurred to me but I could fill a whole book with the stupid mistakes that wasted time while bringing the various pieces together.
sss.ino (11.5 KB)
DemoSimpleSoftSerial.ino (1.82 KB)
DemoPartner.ino (701 Bytes)