Creating cage using NEO 6m GPS module

Hi there,
I am currently working on creating a cage for Arduino installed in drone using neo 6m GPS module. The problem statement is such that, upon pressing the push button, the current location should be saved and from there around a 50mts cage should be created. I have tried with the following code and I'm getting the error as mentioned below. Can anyone suggest me if there is any alternative to do it?

#include <TinyGPS++.h>
#include <SoftwareSerial.h>
// The TinyGPS++ object
TinyGPSPlus gps;
String fix; // the current GPS fix


const int PUSH_BUTTON = 2;
int buzzer = 12;
long a;
int status;

static const int RXPin = 4, TXPin = 3; //gps module connections
static const uint32_t GPSBaud = 9600;
float lat, lng;
float homeLat = 12.334455;
float homeLon = 05.112233;
#define Radius 0.0005 // Buzzer alert Radius = 50 m

// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);

void setup(){
    pinMode(PUSH_BUTTON, INPUT_PULLUP); //push button input
    pinMode(buzzer,OUTPUT);//initialize the buzzer pin as an output
    Serial.begin(9600);
    ss.begin(GPSBaud);
}

void loop(){
  unsigned char i;

  while (ss.available() > 0){
    gps.encode(ss.read());
    if (gps.location.isUpdated()){
      Serial.print("Latitude= "); 
      Serial.print(gps.location.lat(), 6);
      Serial.print(" Longitude= "); 
      Serial.println(gps.location.lng(), 6);
    }
    
    status = digitalRead(PUSH_BUTTON);
    if (status== HIGH){
          fix = gps.read(); // save the latest

   }  
  
     if (fix.valid.location) {
      
    float dist = fix.location.DistanceKm( home );      
     if (dist >= Radius ){

      for(i=0;i<80;i++)
      {
        digitalWrite(buzzer, HIGH);
      }
    }
    else{
      digitalWrite(buzzer, LOW);
    }
    }
    delay(1000);
  }

and the error is:

exit status 1
'class TinyGPSPlus' has no member named 'read'

Any lead/suggestion is much appreciated. Thank you!!

The TinyGPSPlus class has no read function.

@Danois90 Thanks for the reply. In that case, How do I save the location upon pressing the button? any idea?

Lat and long would seem to be the logical things to save so that you can calculate the relative position between the original (saved) position and the current position

Another question

        for (i = 0; i < 80; i++)
        {
          digitalWrite(buzzer, HIGH);
        }

It will not cause an error, but what is the purpose of this for loop. It will be completed in microseconds, assuming that is that the compiler does not optimise it away

You need to read data from the GPS and parse it with the TinyGPS(Plus) class. The TinyGPS(Plus) class does not read data from the GPS by itself. Here is a guide to look at.

EDIT: If you look at the code you posted, the "if" statement before the one that checks for button press prints latitude and longitude to serial monitor. Do not use the "String" class for anything on AVR based boards, there is always a better way of storing stuff, two floats would probably be ideal.

Later you use "fix.location.DistanceKm()" so that is not a String. I think you want a "TinyGPSLocation"

 TinyGPSLocation fix;

 if (gps.location.isValid())
    fix = gps.location;

Later you use "fix.location.DistanceKm()" but I don't think that function exists. You probably want the
double gps.distanceBetween(double lat1, double long1, double lat2, double long2);

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.