I have a parallax GPS that works with my Arduino (non mega). The way I always used it was by using the RX pin (0) and sending the information to a software serial to a LCD screen. That has always worked but now I am trying to send the information through the USB serial port of my computer. I tried both hooking up the GPS to the RX pin and using the GPS through software serial, once I open the Serial monitor the GPS stops sending information
On my Arduino it says Luigino 328, I know when I ordered this it has an extra feature that closes the serial port when uploading (so you can leave devices plugged into the serial port.) I don't know if this will affect it or not.
code below
#include <string.h>
#include <ctype.h>
#define bit9600Delay 84
#define halfBit9600Delay 42
#define bit4800Delay 188
#define halfBit4800Delay 94
#include <SoftwareSerial.h>
SoftwareSerial gps(2, 3);
int ledPin = 13; // LED test pin
int rxPin = 2; // RX PIN
int txPin = 3; // TX TX
int byteSerial=-1;
char linea[300] = "";
char comandoGPR[7] = "$GPRMC";
int cont=0;
int bien=0;
int conta=0;
int indices[13];
void setup() {
Serial.begin(9600);
pinMode(2,INPUT);
pinMode(3,OUTPUT);
pinMode(ledPin, OUTPUT); // Initialize LED pin
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
gps.begin(4800);
for (int i=0;i<300;i++){ // Initialize a buffer for received data
linea[i]=' ';
}
}
void loop() {
digitalWrite(ledPin, HIGH);
byteSerial=gps.read(); // Read a byte of the gps port
Serial.println(byteSerial, BYTE);
if (byteSerial == -1)
{ // See if the port is empty yet
delay(50);
} else {
linea[conta]=byteSerial; // If there is gps port data, it is put in the buffer
conta++;
gps.print(byteSerial, BYTE);
if (byteSerial==13) // If the received byte is = to 13, end of transmission
{
digitalWrite(ledPin, LOW);
cont=0;
bien=0;
for (int i=1;i<7;i++){ // Verifies if the received command starts with $GPR
if (linea[i]==comandoGPR[i-1]){
bien++;
}
}
if(bien==6){ // If yes, continue and process the data
for (int i=0;i<300;i++){
if (linea[i]==','){ // check for the position of the "," separator
indices[cont]=i;
cont++;
}
if (linea[i]=='*'){ // ... and the "*"
indices[12]=i;
cont++;
}
}
int i = map(analogRead(A0),0,1023,0,9);
switch(i){
case 0 :Serial.print("Time ") ;break;
case 1 :Serial.print("Status ");break;
case 2 :Serial.print("Lat ");break;
case 3 :Serial.print("Dir ");break;
case 4 :Serial.print("Long ");break;
case 5 :Serial.print("Dir ");break;
case 6 :Serial.print("Velo ");break;
case 7 :Serial.print("Head ");break;
case 8 :Serial.print("Date ");break;
case 9 :Serial.print("Magn ");break;
case 10 :Serial.print("(E/W) ");break;
case 11 :Serial.print("Mode: ");break;
case 12 :Serial.print("Checksum: ");break;
}
for (int j=indices[i];j<(indices[i+1]-1);j++){
Serial.print(linea[j+1]);
}
delay(200);
Serial.println("");
// Serial.println("---------------");
}
conta=0; // Reset the buffer
for (int i=0;i<300;i++){ //
linea[i]=' ';
}
}
}
}
Thank you for your help