Multiple Software serial

Hi. I have a GPS hooked up to a software serial port and that works. I also have a serial radio module. I want the GPS info to be transmitted from the radio. When I have two software serial ports open Tiny GPS library doesn’t detect a GPS. So I decided to use hardware serial and just have the GPS data printed to serial and then just hook up the radio to the hardware serial but that doesn’t work. When its plugged into my computer I can see the info on the serial monitor and the TX light comes on but when i just have power hooked up the TX light doesn’t light up. My code is just a very slightly modified version of the Tiny GPS example. The second software serial is commented out. Any help would be greatly appreciated. :slight_smile: Thanks.

#include <TinyGPS++.h>
#include <SoftwareSerial.h>

TinyGPSPlus gps;

SoftwareSerial ss(8, 9); //GPS RX, TX
//SoftwareSerial radioSerial(10, 11); //Radio RX, TX

void setup()
{
  Serial.begin(9600);
  ss.begin(9600);
  //radioSerial.begin(9600);
}

void loop()
{
  while (ss.available() > 0)
    if (gps.encode(ss.read()))
      displayInfo();

  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    Serial.println(F("No GPS detected: check wiring."));
    while (true);
  }
}

void displayInfo()
{
  Serial.print(F("Location: "));
  if (gps.location.isValid())
  {
    Serial.print(gps.location.lat(), 6);
    Serial.print(F(","));
    Serial.print(gps.location.lng(), 6);
  }
  else
  {
    Serial.print(F("INVALID"));
  }

  Serial.print(F("  Date/Time: "));
  if (gps.date.isValid())
  {
    Serial.print(gps.date.month());
    Serial.print(F("/"));
    Serial.print(gps.date.day());
    Serial.print(F("/"));
    Serial.print(gps.date.year());
  }
  else
  {
    Serial.print(F("INVALID"));
  }

  Serial.print(F(" "));
  if (gps.time.isValid())
  {
    if (gps.time.hour() < 10) Serial.print(F("0"));
    Serial.print(gps.time.hour());
    Serial.print(F(":"));
    if (gps.time.minute() < 10) Serial.print(F("0"));
    Serial.print(gps.time.minute());
    Serial.print(F(":"));
    if (gps.time.second() < 10) Serial.print(F("0"));
    Serial.print(gps.time.second());
    Serial.print(F("."));
    if (gps.time.centisecond() < 10) Serial.print(F("0"));
    Serial.print(gps.time.centisecond());
  }
  else
  {
    Serial.print(F("INVALID"));
  }

  Serial.println();
}

First, SoftwareSerial will only allow you to RX from one device at a time. Read the write-up on it to see how to multiplex. Personally, I've had little success with SoftwareSerial and ended up writing my own non-blocking soft uart. Good discussion about doing so in the AVR application notes.

Second to consider, the GPS data stream is (typically) Rx only and if your use of the monitor is to display data only (i.e, no input), split the hardware serial between the two. Connect Rx to the GPS and Tx to a TTL/USB convertor. You might get by using the in-built circuitry for Rx, definitely cannot share the Tx. The only other thing you need to take care for is that they're all the same baud rate.

You might get by using the in-built circuitry for Rx, definitely cannot share the Tx.

You can share the pins 0+1 take a look at the old Wireless/SD shield.

Mark

Sorry, misleading. While you could have multiple sources all connected to Rx at the same time, notwithstanding contention issues, the Tx driver can't supply enough to drive multiple outputs (simultaneously). You can share the pin with any other device(s) you want, but if more than one, you'll need some extra circuitry to jack up the signal (outliers not included).

Take a look at the circuit diagram for the shield ( it's in the product section) The shield works faultlessly with both XBEE's and WiFly chips.

Mark

DKWatson: Sorry, misleading. While you could have multiple sources all connected to Rx at the same time, notwithstanding contention issues, the Tx driver can't supply enough to drive multiple outputs (simultaneously).

This seems very mixed up.

If you want to connect several sources to a single Rx pin then they each need to be isolated using diodes because all the Tx pins of the sources will otherwise be fighting with each other to pull the line HIGH when they are idle.

You can connect one Tx to several Rx's at the same time - assuming you are happy for all the Rxs to receive the same data. No doubt there is a maximum number of Rxs (without using a buffer chip to regenerate the signal) but I have no idea what it is.

...R

Robin2:
You can connect one Tx to several Rx’s at the same time - assuming you are happy for all the Rxs to receive the same data. No doubt there is a maximum number of Rxs (without using a buffer chip to regenerate the signal) but I have no idea what it is.

…R

It’s basically a matter of summing the Iih/il of the RX pins of the connected devices. At the calculated required current, Voh/ol of the TX device should still be within the limits of Vih/il of the RX devices.

If all were Arduinos with 328P, you can drive something like 20,000; more than you want to wire :wink:

The easiest solution by far is to just use a suited microcontroller that has multiple hardware UARTs.

Pieter

sterretje: If all were Arduinos with 328P, you can drive something like 20,000;

Many more than I could afford :)

...R

So basically i could use one software serial port port and hook up the tx to the radio and rx to the gps?

Yes.

gregory21greg: So basically i could use one software serial port port and hook up the tx to the radio and rx to the gps?

Technically (that is, electrically) yes you could.

Whether it would be useful is another question. GPS devices tend to send data all the time and you would not be able to listen to the GPS while talking to the radio.

...R