1

The title says it all.

Angone with experience here on this subject?

I want to use all Hardware serial, SoftwareSerial and AltSoftSerial on Arduino Duemilanove with At328.

Is it possible?

2

in short - Yes. The following compiles and should work

Note the following links detail some subtle issues about HOW to use these various libraries. Some are more optimal depending upon your usage.

http://www.pjrc.com/teensy/td_libs_AltSoftSerial.html#speed

http://forum.arduino.cc/index.php?topic=152122.0;wap2

You might also want to consider just using either Alt or Soft. Note that NewSoftwareSerial is incorporated in the IDE 1.5.5+

/*
  Software serial multple serial test

 Receives from the hardware serial, sends to software serial.
 Receives from software serial, sends to hardware serial.

 The circuit:
 * RX is digital pin 10 (connect to TX of other device)
 * TX is digital pin 11 (connect to RX of other device)

 Note:
 Not all pins on the Mega and Mega 2560 support change interrupts,
 so only the following can be used for RX:
 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69

 Not all pins on the Leonardo support change interrupts,
 so only the following can be used for RX:
 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).

 created back in the mists of time
 modified 25 May 2012
 by Tom Igoe
 based on Mikal Hart's example

 This example code is in the public domain.

 */
#include <SoftwareSerial.h>
#include <AltSoftSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

AltSoftSerial altSerial; 
// AltSoftSerial always uses these pins:
// Board          Transmit  Receive   PWM Unusable
// -----          --------  -------   ------------
// Arduino Uno        9         8         10


void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(57600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(4800);
  mySerial.println("Hello, world?");
  altSerial.begin(9600);
  altSerial.println("Hello World");
}

void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());

  char c;

  if (Serial.available()) {
    c = Serial.read();
    altSerial.print(c);
  }
  if (altSerial.available()) {
    c = altSerial.read();
    Serial.print(c);
  }
}
| improve this answer | |
1

You should be aware that SoftwareSerial is blocking other interrupts when sending/receiving. I'm not sure exactly how AltSoftSerial behaves, but I believe it was written to deal with that issue. The issue arises if you use a slow baud rate on the SoftwareSerial in combination with a high baud rate on hardware serial. Then you can loose incoming data on the hardware serial. AltSoftSerial will probably be completely blocked during SoftwareSerial activity - hardwareserial can still send / receive one-two bytes in the hardware tx/rx registers. According to https://www.pjrc.com/teensy/td_libs_AltSoftSerial.html you can use AltSoftSerial together with SoftwareSerial, as long as the baud rate for SoftwareSerial is at least 10 times the baud rate of that used for AltSoftSerial.

If you never transmit/receive simultaneously on different interface, you don't really have to worry about any of the above mentioned issues.

When I write SoftwareSerial, I refer to NewSoftSerial, which has been called SoftwareSerial in Arduino for a while now (since 1.0 I believe).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.