Author Options:

Arduino SoftwareSerial problem. Answered

I recently purchased and assembled the sparkfun GPS shield, and an EM 406a GPS module.  I also have a parallax serial lcd module.  They both work, but when used in the same code, neither of them work.  They bot use the SoftwareSerial library, but they are on different pins.  Any help?


The forums are retiring in 2021 and are now closed for new topics and comments.

Best Answer 7 years ago

Are you using the old Softwareserial library or the Newsoftserial library ? That means are you using arduino > 1.00, and calling the core software serial library FTFM If using multiple software serial ports, only one can receive data at a time. That means you have to 1.) Talk to the GPS. 2.) Receive from GPS. 3.) Switch to talking to display 4.) Talk to display Here's a link to a detailed explanation, quoted below. http://arduiniana.org/libraries/newsoftserial/
Using Multiple Instances
There has been considerable support for an library that would allow multiple soft serial devices. However, handling asynchronously received data from two, three, or four or more serial devices turns out to be an extremely difficult, if not intractable problem. Imagine four serial devices connected to an Arduino, each transmitting at 38,400 baud. As bits arrive, Arduino’s poor little processor must sample and process each of 4 incoming bits within 26 microseconds or else lose them forever. Yikes!
It occurred to me, though, that multiple instances could still be possible if the library user were willing to make a small concession. NewSoftSerial is written on the principle that you can have as many devices connected as resource constraints allow, as long as you only use one of them at a time. If you can organize your program code around this constraint, then NewSoftSerial may work for you.
What does this mean, exactly? Well, you have to use your serial devices serially, like this:
// Here's a GPS device connect to pins 3 and 4
NewSoftSerial gps(4,3);
// A serial thermometer connected to 5 and 6
NewSoftSerial therm(6,5);
// An LCD connected to 7 and 8
NewSoftSerial LCD(8,7); // serial LCD
void loop()
  // collect data from the GPS unit for a few seconds
  read_gps_data();  // use gps as active device
  // collect temperature data from thermometer
  read_thermometer_data(); // now use therm
  // LCD becomes the active device here
  LCD.print("Data gathered...");

5 years ago

But my Arduino said:

error: #error NewSoftSerial has been moved into the Arduino core as of version 1.0. Use SoftwareSerial instead.

And SoftwareSerial doesn't work too!!!
What i do wrong? )))


Answer 5 years ago

Dunno. How can I tell ? The least you could do is post your code....


7 years ago

The library is limited to using only 1 serial port at a time. Your code will have to switch back and forth between your 2 serial ports and give enough time to scan each port so the information can be transmitted back and forth. Check the included example for using multiple ports.