CODE:
| #include <SoftwareSerial.h> | // Include the SoftwareSerial library with Arduino 0007 or later version |
| #define SoftrxPin 2 | // SoftwareSerial port on pin 2 (RX from the GPS) |
| #define SofttxPin 3 | // Not used, but needed to in order to declare SoftwareSerial; |
| SoftwareSerial mySerial = SoftwareSerial(SoftrxPin, SofttxPin); | // Set up a new serial port |
| byte GPRMC=0; | |
| void setup() { | |
| beginSerial(4800); | // general serial baudrate, in this case used internally by arduino to send data to the PC (pin 1) |
| mySerial.begin(4800); | // Set the data rate for the software serial port (used at pin 2) |
| pinMode(SoftrxPin, INPUT); | // Declare rx pin as INPUT |
| } | |
| void loop() { | |
| GPRMC = mySerial.read(); | |
| Serial.print(GPRMC, BYTE); | |
| } | |
SCHEMATIC:
Digital pin2 is defined as our software serial rx line.
COMMENT:
The atmega 8 microcontroller only has one serial port. These lines are internally connected to digital lines 0 and 1 of the arduino and are used to communicate with the PC via the USB port. (for programming the arduino for example or for sending serial data to the console window). Theoretically you could use that predefined rx line (pin 0) to connect your GPS module as well. However, you would alway have to physically disconnect the GPS unit from the Arduino when programming it. That is rather unpractical, so we are using the software serial function here and defined pin 2+3 as our rx/tx pins.