Basically, it's an alternative to SoftwareSerial, which uses a hardware timer to interfere much less with interrupts from other libraries. It is also capable of simultaneously transmitting and receiving, using buffers for both.
For cases where NewSoftSerial or SoftSerial lose data or interfere with other libraries, AltSoftSerial offers an alternative way to emulate an additional serial port. In some cases, it may perform better, in others is may offer no improvement (while consuming a timer).
No SoftwareSerial approach can rival true HardwareSerial with a real UART, but when no extra serial port is available, hopefully this alternative library can help in cases where the existing libraries have issues.
Wow, could be a lifesaver. Couldn't get it to work on Uno, though -- I hook up a GPS receiver on pins 8&9 and no data arrives, even if I exchange the RX/TX pins in config/known_boards.h.
It works with NewSoftSerial but the interrupt delays are killing the Serial.
Do NOT change config/known_boards.h! (unless you're adding another board)
On Uno, pin 8 is always receive, because that is the pin with timer1's input capture signal. Pin 9 is always transmit, because that is timer1's compare A waveform generator pin.
The definitions in known_boards.h are merely for documentation, and for the library to configure the correct pins using pinMode (so receive becomes and input and transmit becomes an output). The actual use of the pins when the library is running is due to way the timer hardware is physically connected within the chip. The numbers in known_boards.h have no effect on the actual pins used, since the library directly controls the timer and the timer connects to specific pins. If you change known_boards.h, the only effect is the library will use pinMode on the wrong pins. It will still use the same pins while running, but they may not be set to the correct modes if you edited the .h file.
Why AltSoftSerial is not working for you, I do not know? I can't see your hardware. At this point, I would highly recommend you download a fresh copy of AltSoftSerial. Do not modify known_boards.h.
Ouch. As you can see, the shield is meant to be inserted just one way and fits nicely together with the GPRS shield. Will try putting it backwards nevertheless, just to make sure.
Is it that some deep code hacking is needed to reverse the pins or is it impossible at all because of wiring reasons?
andr:
Ouch. As you can see, the shield is meant to be inserted just one way and fits nicely together with the GPRS shield. Will try putting it backwards nevertheless, just to make sure.
You will probably damage the shield if you reverse ALL the pins. Only pins 8 and 9 should be swapped.
It's unfortunate this shield was designed with the pins swapped. AltSoftSerial did not exist 2 years ago when it was made. I wrote AltSoftSerial only a few weeks ago.
Is it that some deep code hacking is needed to reverse the pins or is it impossible at all because of wiring reasons?
AltSoftSerial only works with the pins as documented. On boards like Uno with only one 16 bit timer, there are absolutely no other options.
As explained above, it uses timer1's special features, and those hardware features are hard-wired to those specific pins. It is absolutely impossible from software to make any pin other than 8 on Uno act as a 16 bit timer input capture.
AltSoftSerial will only work if you connect the signals as documented. It provides a lot of benefit, but the limitation is only specific pins can be used.
If "will try putting it backwards" means only swapping pins 8 and 9, then good.
If it means attempting plug the whole shield in some strange way (perhaps hanging off the edge of the Uno) which reverses 8 and 9, but also causes other pins to line of differently... well, don't do that!
It is absolutely impossible from software to make any pin other than 8 on Uno act as a 16 bit timer input capture.
Actually you could use any one of the analog pins as an input for the 16 bit timer.
Wow, yes, you're right. The AN1 pin can too. I didn't notice that before.
The signal will become inverted, so the library would need to handle reverse polarity (on my to-do list), and of course code would need to enable the analog comparator and ADC mux.
I'm going to have to give this a try now. My current project uses NSS and as luck would have it I just happened to route those serial signals to 8 and 9 (what are the odds?).
Hey Paul,
I haven't tried this alternative yet but I just wanted to be sure on a couple of things before I implement this library. I need to use pin change interrupts on most of my IO pins but unfortunately NewSoftSerial ties up all the pin change interrupt vectors even if they're not used so I get multiple vector define errors when I compile. I could rem out ports C and D in NSS but I still lose PCI for the rest of the IO pins on Port B.
From what I can tell your library does not use pin change interrupts, can you confirm this?
Also you mention that PWM on pin D10 can't be used. I assume I can still use D10 for other functions just not PWM?
How does code size compare to NSS?
Thanks again for this library, it will probably save me a lot of time!
wayneft:
From what I can tell your library does not use pin change interrupts, can you confirm this?
Confirmed, pin change interrupts are not used.
Also you mention that PWM on pin D10 can't be used. I assume I can still use D10 for other functions just not PWM?
Yes. I've added some text to the web page to clarify this point.
How does code size compare to NSS?
I didn't compare. Maybe you can tell me?
Just click "Verify", make a note of the size, then change just a couple lines your code to switch to AltSoftSerial, and click Verify again. Subtract the numbers.... pretty easy!
Did you have any luck using the analog pins for the Altsoftlibrary. I need to use an usb host shiled and another device at the same time. The usb host shield uses the 8 and 9 pins so I can not use them to transmit and receive from the other device.
On Arduino Uno, AltSoftSerial must use pins 8 and 9. It can not work on any other pins. It uses timer1, which is connected to those pins. That's the price for better timer-assisted software serial.
I believe the host shield uses those 2 pins as ordinary signals, so it should be possible to physically modify a host shield to use different pins.
Altsoftserial library is really fantastic for 2 way communication.
I was using softwareserial with GSM for sending data over GPRS over 10 seconds and it was working but the problem was i was not able to check response from GSM if any error occurred.
Then i use altsoftserial and it's life saving but i can see one minor problem here.
Now instead of sending data in interval of 10 seconds it's send 2 data in 20 seconds and sometime 3 data in 30 seconds.
I have a silly question to ask, but i wanna ask it because it isn't mentioned in Basic Usage. :
Does AltSoftSerial supports altserial.write() function?
just wanted to thank Paul Stoffregen for this library!
I was having a nightmare trying to read ESP8266 response with NewSoftwareSerial, many hours trying to simplify and make the code more robust to try and make it work. When I found AltSoftSerial it took me 2 minutes to get it working and now I have 99.2% of website response read success. That is on a tests of 15000 calls !!!
Thanks Paul, all my ESP8266 projects are using now AltSoftSerial