Hello,
I have an em406a gps hooked up to an arduino uno. I am using the tinygps library to interpret the gps data on the arduino and output the lat/lon to the serial. Here is part of the arduino code:
- #include <NewSoftSerial.h>
- #include <TinyGPS.h>
- #define RXPIN 2
- #define TXPIN 3
- #define GPSBAUD 4800
- TinyGPS gps;
- NewSoftSerial uart_gps(RXPIN, TXPIN);
- void getgps(TinyGPS &gps);
- void setup()
- {
- Serial.begin(115200);
- uart_gps.begin(GPSBAUD);
- Serial.println("");
- Serial.println("GPS");
- Serial.println(" ...waiting for lock... ");
- Serial.println("");
- }
- void loop()
- {
- while(uart_gps.available())
- {
- int c = uart_gps.read();
- if(gps.encode(c))
- {
- getgps(gps);
- }
- }
- }
- void getgps(TinyGPS &gps)
- {
- float latitude, longitude;
- gps.f_get_position(&latitude, &longitude);
- Serial.print(latitude,5);
- Serial.print(" ");
- Serial.println(longitude,5);
- }
Here is my processing code:
- import processing.serial.*;
- Serial myPort;
- Float lat;
- Float lon;
- void setup() {
- frameRate(5);
- println(Serial.list());
- myPort = new Serial(this, Serial.list()[0], 115200);
- }
- void draw() {
- while (myPort.available() > 0) {
- String inBuffer = myPort.readString();
- if (inBuffer != null) {
- String[] nums = split(inBuffer, ' ');
- Float lat = float(nums[0]);
- Float lon = float(nums[1]);
- println(lat+","+lon);
- }
- }
- }
Does anyone know a good way to send data via serial from arduino to processing so that it can be broken apart in processing into different variables(latitude,longitude,speed,etc.)?
Thanks
Stephen
1