using hardwareSerial instead of SoftwareSerial for TinyGPS

Hello everyone,

I want to use the hardwareSerial instead of the SoftwareSerial for the TinyGPS since the softwareSerial is on conflict with the timer on the servo library. I read the other thread about this topic as well however I still do not understand how to place the hardwareSerial to the code.

however, I do not know how to use the hardwareSerial or how to implement it on the TinyGPS sketch.

any pointers?

Thanks

-C

On which Arduino?

Mark

Hi mark,

I am using an uno for now, but essentially I am going to transfer it into a nano

Hardware serial is what you use to communicate with the PC over the USB connection. It uses pins 0 and 1 on the Uno.

You can certainly use those pins for your GPS but not if you also want to display results on the Serial Monitor.

You could use the ServoTimer2 library - it should work OK with SoftwareSerial.
I also wrote a very basic yet another software serial that works with the standard servo library. But it may not work on a Nano.

...R

Hi robin,

I tried using servoTimer2 before, however on my case, it seems like the servotimer2 library doesnt work with virtualWire(maybe it was just my error for not knowing how to implement servotimer2 to the sketch).

i would like to display the coordinates so I dont think the hardwareSerial is not a good choice anymore.

Would you mind giving an example code on how to put the servotimer2 to the sketch? that would be greatly appreciated.

-C

You use the ServoTimer2 library in exactly the same way as Servo library.
The latest version that I have found is at download ServoTimer2 library
There is an example in the zip file

Hardware serial is what you use to communicate with the PC over the USB connection. It uses pins 0 and 1 on the Uno.

You can certainly use those pins for your GPS but not if you also want to display results on the Serial Monitor.

No in normal operation the GPS only use GPS Tx to Arduino Rx. You can still use serial to write to the monitor. Just remember to disconnect the GPS when uploading.

Mark

jordano00:
I tried using servoTimer2 before, however on my case, it seems like the servotimer2 library doesnt work with virtualWire(maybe it was just my error for not knowing how to implement servotimer2 to the sketch).

You did not say you were trying to using virtualWire as well as SoftWareSerial and Servo. The more libraries you use the greater is the likelihood of conflict and you will probably need to study the code within the libraries to see if a solution is possible

…R

I apologize for not mentioning the part about the virtualWire.

However, is there any way to make all 3 libraries to work together?

If you give us a description of the project you are trying to build it may be possible to suggest something.

...R

TinyGPS works fine on HardwareSerial. On a mega with 4 hardware serials, there is no problem talking to the computer on Serial and using the GPS on one of the other hardware serials.

In any case, the tinyGPS library doesn't use any serial at all. The sketch which uses the tinyGPS class is responsible for getting each char from the GPS device and then feeding that char into the tinyGPS class.

The tinyGPS object does not know or care which sort of serial it's char input comes from.

Example sketch using tinygps.

#define RXPIN 3
#define TXPIN 2
SoftwareSerial nss(RXPIN, TXPIN);
void loop()
{
  while (nss.available())
  {
    int c = nss.read();
    if (gps.encode(c))
    {
      // process new gps info here
    }
  }
}

To use hardware serial,
(1) get rid of the software serial line
(2) Add Serial.begin(9600) in setup( ) Or whatever rate your gps uses.
(3) Replace nss.available( ) with Serial.available( )
(4) Replace nss.read( ) with Serial.read( )

No changes with any aspect of the tinygps object are required.

If you only have one serial hardware device, and you connect it to the gps, then you can't have it connected to your computer at the same time. So no serial monitor output or debugging. That doesn't stop you displaying results on an lcd or other device on your arduino.

If you only have one serial hardware device, and you connect it to the gps, then you can't have it connected to your computer at the same time. So no serial monitor output or debugging.

Wrong -try it out all you do is leave the Rx of the GPS disconnected!

Mark