6

At the moment I'm using two softserials to connect to a GPS and an GSM module.

It seems not possible to have two open software-serials. So I was looking for an solution

After the initial-setup, the GPS module is only needed to be read from; while the GSM module needs to be bidirectional. So:

GPS > listen only
GSM > listen and write

Now I came across the GPS library from Adafruit, which uses an interrupt to receive data. Is this instead of a software serial. Or do I again run into the limitation?

An other solution might be to use the D0 and D1 to attach eg the GPS module. But than I won't be able to see the debug messages in my serial monitor. Is that correct?

Sorry in advance for these n00b questions. But I'm frustrated the things dont work as I want :)

edit

  • This is the adafruit GPS board.
  • And the board with whom it is connected: Gboard
  • The Sim900 is connected to D2/D3 and the GPS is connected to A2/A3.
  • D0/D1 are connected to a FTDI breakout board, which is plugged into my USB.
stUrb
  • 351
  • 2
  • 5
  • 10

5 Answers5

2

Adafruit_GPS.h (line 132-), which is included in Adafruit_GPS.cpp (line 13) refers in turn to the SoftwareSerial library on AVR platform and Arduino IDE version > 100.

#ifdef __AVR__
#if ARDUINO >= 100
    SoftwareSerial *gpsSwSerial;
#else
    NewSoftSerial *gpsSwSerial;
#endif
#endif

This means it uses software serial on an Uno. It also means if your problem is indeed with Software Serial, that is the library to check for bugs / updates or commit a patch to.

jippie
  • 2,901
  • 14
  • 23
1

The solution to your problem might be to combine AltSoftSerial with SoftwareSerial. I haven't done it myself (yet) but I have the same problem as yours.

SoftwareSerial does busy wait for counting time between two bits, so it can't read simultaneously from two ports (some bits could be lost).

AltSoftSerial was created to overcome some of these limitations. It's interrupt-based. Unfortunately, it's harwired for one port (and pins 7 & 8). My understanding is that you can combine it with SoftwareSerial to read from 2 simultaneous ports. Pins 7 & 8 aren't what you need, from the description of the GBoard, but AltSoftSerial is open source, you can change the pin numbers (and possibly some masks) in the source code.

Hope this helps.

0

So you want three serial ports: upload/debug (hardware serial), GSM (software serial) and GPS (software serial). Unfortunately, two SoftSerial ports are not going to work at the same time (or even send and receive at the same time on one SoftSerial port). In your current configuration it's not going to be solvable.

If you can wire the GPS to different pins, there are a couple of options to try. One would be to disconnect the FTDI when running (reconnect to program) so you can use the hardware serial port for either GSM or GPS (probably the former). If you need some print statements for debugging, you could use SoftSerial or AltSoftSerial (and connect the FTDI differently). Reconnecting between upload/debug and run phases would be a pain but it comes with the platform you are choosing and the number of serial ports you need; you might be able to wire up a DPDT switch externally to do the switching rapidly.

The other and perhaps easier approach would be to connect the GPS to pins 8 and 9, and use AltSoftSerial for the GPS; as long as your baud rate to the GSM is high enough that might work. (SoftSerial for the GSM will turn off interrupts for excessive periods of time at low baud rates). Using AltSoftSerial makes use of the single 16 bit timer (Timer1), so this won't work if you use any other library which requires Timer1.

Zeph
  • 445
  • 3
  • 11
0

I've done exactly this. The secret sauce for me was the SoftwareSerial.listen().

Before running your GSM commands you have to make sure the GSM module's SoftwareSerial port is "listening". Then when you're done you have to listen() again to the GPS.

This is, of course, not terribly efficient, while the GSM port is listening any GPS data will be lost, but at least in my case the impact was negligible.

My code is here: https://github.com/lectroidmarc/gsm-tracker

As an aside, I have also considered plugging the GPS into the UART and running debug messages to a SoftwareSerial serial port, to be monitored during testing with another Arduino. I'm just not sure the benefit would be there.

Marc M
  • 1
  • 1
-1

There is a working example of this, using the Adafruit Ultimate GPS, and the Arduino GSM shield http://www.mallinson-electrical.com/shop/gpsgsm I hope this helps