GPS Outpute Integer?

For a tracking project, I have a GPS device serially connected to an Arduino (RX/TX). With Arduino and Processing code as below. However, teh serial data I'm recieving from the GPS is just a number, instead of what I thought should be the long string in the GPS NMEA protocol with location data, time, etc.! :astonished:

Any suggestions?

Thanks ahead of time! :)

Arduino Code on Arduino:

void setup() {
  // initialize the serial communication:
  //Serial.begin(9600);
  Serial.begin(4800);
}

void loop() {
  // send the value of analog input 0:
  //Serial.begin(9600);
  //Serial.println(analogRead(A0));
  if(Serial.available()){ 
    //Serial.begin(4800);
    Serial.println(Serial.read());
  }

  delay(100);
  digitalWrite(13, HIGH);
}

Processing Code on Computer, outputs serial data to a text file, "depth.txt"

import processing.serial.*;

Serial myPort, myPort2;
String inString, inString2;
PrintWriter output;
float inByte;
int count = 1;

void setup () {    
  println(Serial.list());
  size(300,300);
  myPort = new Serial(this, Serial.list()[1], 4800);
  //myPort2 = new Serial(this, Serial.list()[], 4800);
  myPort.bufferUntil('\r');
  //myPort2.bufferUntil('\n');
  output = createWriter("depth.txt");
}

void draw () throws NullPointerException{
  background(200);
  text("Click and hold to stop recording data", width/6, height/2);
  if(keyPressed||mousePressed){
    output.flush();
    output.close();
    exit();
  }
  delay(750);
  text(count, width/4, height/4);
  
  //text(inString, 3.5*width/4, height/4);
  count++;
}

void serialEvent(Serial myPort) {
   inString = myPort.readString();
   text(inString, 2.8*width/4, height/4);
   //inString2 = myPort2.readStringUntil('\n');
   
   if (inString != null) {
     inString = trim(inString);
     output.println(inString);
   }
//   if (inString2 != null) {
//     inString2 = trim(inString2);
//     output.println(inString2);
//   }
}

I don't know what you are doing. You said you had an GPS yet I can't see where you read it. What is your analogRead doing? Why do you read it instead of reading from the GPS?

Your Arduino is reading single characters from the GPS and sending each to Processing as a decimal character code followed by a newline. If you want to send the characters received from the GPS directly to Processing, change Serial.println(Serial.read()); to:

Serial.print((char)Serial.read());

Serial.read() returns an integer so it can return -1 if no character is available. You have to us a 'cast' operation to tell the compiler to treat it as a character in order to get Serial.print() to send it as a character and not as an integer. Use Serial.print() instead of Serial.println() so you don't get one character per line.

liudr: The lines you’re seeing are commented out; I was testing with ultrasound before I was using the GPS.

Thanks John, that fixed the problem :slight_smile:

Sorry my mistake. Tired eyes. :fearful: :blush: