Έχω πρόβλημα στη λήψη δεδομένων GPS

ψήφοι
0

Δοκίμασα τον κωδικό GPS χωρίς τους κωδικούς για αισθητήρα υπερήχων και επιταχυνσιόμετρο και λειτούργησε απολύτως εντάξει.

Αλλά τώρα είμαι προσπαθεί να χρησιμοποιήσει το GPS με το επιταχυνσιόμετρο και αισθητήρα υπερήχων, το GPS δεν μου δίνει την κατάλληλη δεδομένα πίσω σε μένα. Ωστόσο, επιταχυνσιόμετρο και αισθητήρα υπερήχων δώσει πίσω σωστή τιμή για Arduino σειριακή οθόνη.

Από τότε που χρησιμοποιώ Adafruit Ultimate GPS Breakout v3, όταν αναλυθεί τα δεδομένα NMEA, θα πρέπει να πάρετε κάτι σαν ακόλουθα Ώρα: xx: xx: xx.xxx Ημερομηνία: xx / xx / xxxx Τοποθεσία και το κ.λπ.

Αντ 'αυτού, παίρνει μόνο για να Ημερομηνία και συμπληρώθηκε με 0 αντ' αυτού.

Ήδη δοκιμάσει μόνο με τη χρήση κωδικών GPS για να ελέγξει αν ήταν πρόβλημα μονάδα GPS.

Ολόκληρο Κωδικός

//Declare Needed header file
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#define GPSSerial Serial1
Adafruit_GPS GPS(&GPSSerial);
#define GPSECHO false

uint32_t timer=millis();

//Declare the pins
#define echoPin 7
#define trigPin 8

//Define Accelerometer Address
const int MPU=0x68;

//Declare Accelerometer Variable
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;

float f1=1.3;
byte *fp = (byte *) &f1;

//Declare the ultrasonic variables
long duration;
long distance;
void setup()
{
  //Join I2C bus as Slave with Address 8;
  Wire.begin (8);

  //Call SendData Command
  Wire.onRequest(SendData);

  //Setup Pins as output and input to operate ultrasonic sensor
  pinMode(echoPin, INPUT);
  pinMode(trigPin, OUTPUT);

  //Setup for Accelerometer Sensor
  Wire.beginTransmission(MPU);
  Wire.write(0x6B);
  Wire.write(0);
  Wire.endTransmission(true);
  //Begin Serial Monitor

  Serial.begin (9600);
  //GPS Sensor Setting
  Serial.begin (9600);
  Serial.println(Adafruit GPS Test);
  GPS.begin (9600);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_10HZ);
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  delay(1000);
}

void loop ()
{
  dist();
  GY521();
  readGPS();
  delay(3000);
}
//Obtain Ultrasonic Data
void dist()
{
  digitalWrite (trigPin,LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin,HIGH);
  delayMicroseconds(2);
  digitalWrite(trigPin,LOW);
  duration=pulseIn(echoPin,HIGH);
  distance=duration/58.2;
  Serial.print(distance);
  Serial.println( cm);
}
//Obtain Accelerometer Data
void GY521()
{
  Wire.beginTransmission(MPU);
  Wire.write(0x3B);
  Wire.endTransmission(false);
  Wire.requestFrom(MPU,12,true);
  AcX=Wire.read()<<8|Wire.read();
  AcY=Wire.read()<<8|Wire.read();
  AcZ=Wire.read()<<8|Wire.read();
  GyX=Wire.read()<<8|Wire.read();
  GyY=Wire.read()<<8|Wire.read();
  GyZ=Wire.read()<<8|Wire.read();

  Serial.println(Accelerometer: );
  Serial.print(X= ); Serial.println(AcX);
  Serial.print(Y= ); Serial.println(AcY);
  Serial.print(Z= ); Serial.println(AcZ);

//  Serial.print(f1= );
//  Serial.print(fp[0], HEX);
//  Serial.print(fp[1], HEX);
//  Serial.print(fp[2], HEX);
//  Serial.print(fp[3], HEX);
//  Serial.println();

}

void readGPS()
{
  // read data from the GPS in the 'main loop'
  char c = GPS.read();
  // if you want to debug, this is a good time to do it!
  if (GPSECHO)
    if (c);
  // if a sentence is received, we can check the checksum, parse it...
  if (GPS.newNMEAreceived()) {
    // a tricky thing here is if we print the NMEA sentence, or data
    // we end up not listening and catching other sentences!
    // so be very wary if using OUTPUT_ALLDATA and trying to print out data
    // this also sets the newNMEAreceived() flag to false
    if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
      return; // we can fail to parse a sentence in which case we should just wait for another
  }
  // if millis() or timer wraps around, we'll just reset it
  if (timer > millis()) timer = millis();

  // approximately every 2 seconds or so, print out the current stats
  if (millis() - timer > 2000) {
    timer = millis(); // reset the timer
    Serial.print(\nTime: );
    if (GPS.hour < 10) { Serial.print('0'); }
    Serial.print(GPS.hour, DEC); Serial.print(':');
    if (GPS.minute < 10) { Serial.print('0'); }
    Serial.print(GPS.minute, DEC); Serial.print(':');
    if (GPS.seconds < 10) { Serial.print('0'); }
    Serial.print(GPS.seconds, DEC); Serial.print('.');
    if (GPS.milliseconds < 10) {
      Serial.print(00);
    } else if (GPS.milliseconds > 9 && GPS.milliseconds < 100) {
      Serial.print(0);
    }
    Serial.println(GPS.milliseconds);
    Serial.print(Date: );
    Serial.print(GPS.day, DEC); Serial.print('/');
    Serial.print(GPS.month, DEC); Serial.print(/20);
    Serial.println(GPS.year, DEC);
    Serial.print(Fix: ); Serial.print((int)GPS.fix);
    Serial.print( quality: ); Serial.println((int)GPS.fixquality);
    if (GPS.fix) {
      Serial.print(Location: );
      Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
      Serial.print(, );
      Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
      Serial.print(Speed (knots): ); Serial.println(GPS.speed);
      Serial.print(Angle: ); Serial.println(GPS.angle);
      Serial.print(Altitude: ); Serial.println(GPS.altitude);
      Serial.print(Satellites: ); Serial.println((int)GPS.satellites);
    }
  }
}

void SendData()
{
  byte test[]={distance,AcZ>>0x8, AcZ, fp[0], fp[1], fp[2], fp[3]};
  Wire.write(test,7);
}

Μόνο Κωδικός GPS

#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#define GPSSerial Serial1
Adafruit_GPS GPS(&GPSSerial);
#define GPSECHO false

uint32_t timer=millis();
void setup()
{
  Serial.begin (9600);
  Serial.println(Adafruit GPS Test);
  GPS.begin (9600);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_10HZ);
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  delay(1000);
}

void loop()
{
  readGPS();
}

void readGPS()
{
  // read data from the GPS in the 'main loop'
  char c = GPS.read();
  // if you want to debug, this is a good time to do it!
  if (GPSECHO)
    if (c);
  // if a sentence is received, we can check the checksum, parse it...
  if (GPS.newNMEAreceived()) {
    // a tricky thing here is if we print the NMEA sentence, or data
    // we end up not listening and catching other sentences!
    // so be very wary if using OUTPUT_ALLDATA and trying to print out data
    // this also sets the newNMEAreceived() flag to false
    if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
      return; // we can fail to parse a sentence in which case we should just wait for another
  }
  // if millis() or timer wraps around, we'll just reset it
  if (timer > millis()) timer = millis();

  // approximately every 2 seconds or so, print out the current stats
  if (millis() - timer > 2000) {
    timer = millis(); // reset the timer
    Serial.print(\nTime: );
    if (GPS.hour < 10) { Serial.print('0'); }
    Serial.print(GPS.hour, DEC); Serial.print(':');
    if (GPS.minute < 10) { Serial.print('0'); }
    Serial.print(GPS.minute, DEC); Serial.print(':');
    if (GPS.seconds < 10) { Serial.print('0'); }
    Serial.print(GPS.seconds, DEC); Serial.print('.');
    if (GPS.milliseconds < 10) {
      Serial.print(00);
    } else if (GPS.milliseconds > 9 && GPS.milliseconds < 100) {
      Serial.print(0);
    }
    Serial.println(GPS.milliseconds);
    Serial.print(Date: );
    Serial.print(GPS.day, DEC); Serial.print('/');
    Serial.print(GPS.month, DEC); Serial.print(/20);
    Serial.println(GPS.year, DEC);
    Serial.print(Fix: ); Serial.print((int)GPS.fix);
    Serial.print( quality: ); Serial.println((int)GPS.fixquality);
    if (GPS.fix) {
      Serial.print(Location: );
      Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
      Serial.print(, );
      Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
      Serial.print(Speed (knots): ); Serial.println(GPS.speed);
      Serial.print(Angle: ); Serial.println(GPS.angle);
      Serial.print(Altitude: ); Serial.println(GPS.altitude);
      Serial.print(Satellites: ); Serial.println((int)GPS.satellites);
    }
  }
}

Θα πρέπει να πάρετε αυτά τα δεδομένα

      Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
      Serial.print(, );
      Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
      Serial.print(Speed (knots): ); Serial.println(GPS.speed);
      Serial.print(Angle: ); Serial.println(GPS.angle);
      Serial.print(Altitude: ); Serial.println(GPS.altitude);
      Serial.print(Satellites: ); 
      Serial.println((int)GPS.satellites);
Δημοσιεύθηκε 24/10/2019 στις 12:53
πηγή χρήστη
Σε άλλες γλώσσες...                            

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more