Arduino Polska Forum

Pełna wersja: Komunikacja z GPS
Aktualnie przeglądasz uproszczoną wersję forum. Kliknij tutaj, by zobaczyć wersję z pełnym formatowaniem.
Witam, potrzebuje do swojego programu kod komunikujący się z modułem GPS. Dowiedziałem sie, że w jest gotowy szablon do sprawdzania modułu w bibliotece TinyGPS++, problem jest nastepujący mianowicie za każdym razem w monitorze portu wyskakuje mi "No GPS detected: check wiring." Czytałem też o bibliotece SoftwareSerial i wydaje się być ona zbędna na Arduino Mega więc ją wyłączyłem. Moduł mam podłączony pod PINY RX3 TX3 


Kod:
#include <TinyGPS++.h>
//#include <SoftwareSerial.h>
/*
  This sample sketch demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object.
  It requires the use of SoftwareSerial, and assumes that you have a
  4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
*/


// The TinyGPS++ object
TinyGPSPlus gps;

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

void setup()
{
 Serial.begin(115200);
 Serial1.begin(9600);

 Serial.println(F("DeviceExample.ino"));
 Serial.println(F("A simple demonstration of TinyGPS++ with an attached GPS module"));
 Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
 Serial.println(F("by Mikal Hart"));
 Serial.println();
}

void loop()
{
 // This sketch displays information every time a new sentence is correctly encoded.
 while (Serial1.available() > 0)
   if (gps.encode(Serial1.read()))
     displayInfo();

 if (millis() > 5000 && gps.charsProcessed() < 10)
 {
   Serial.println(F("No GPS detected: check wiring."));
   while(true);
 }
}

void displayInfo()
{
 Serial.print(F("Location: "));
 if (gps.location.isValid())
 {
   Serial.print(gps.location.lat(), 6);
   Serial.print(F(","));
   Serial.print(gps.location.lng(), 6);
 }
 else
 {
   Serial.print(F("INVALID"));
 }

 Serial.print(F("  Date/Time: "));
 if (gps.date.isValid())
 {
   Serial.print(gps.date.month());
   Serial.print(F("/"));
   Serial.print(gps.date.day());
   Serial.print(F("/"));
   Serial.print(gps.date.year());
 }
 else
 {
   Serial.print(F("INVALID"));
 }

 Serial.print(F(" "));
 if (gps.time.isValid())
 {
   if (gps.time.hour() < 10) Serial.print(F("0"));
   Serial.print(gps.time.hour());
   Serial.print(F(":"));
   if (gps.time.minute() < 10) Serial.print(F("0"));
   Serial.print(gps.time.minute());
   Serial.print(F(":"));
   if (gps.time.second() < 10) Serial.print(F("0"));
   Serial.print(gps.time.second());
   Serial.print(F("."));
   if (gps.time.centisecond() < 10) Serial.print(F("0"));
   Serial.print(gps.time.centisecond());
 }
 else
 {
   Serial.print(F("INVALID"));
 }

 Serial.println();
}
W tych linijkach:
Kod:
Serial.begin(115200);
Serial1.begin(9600);
deklarujesz, z jakimi UART i z jakimi prędkościami będziesz się bawił. 
A używasz RX3/TX3. 
Może zerknij do Arduino Reference:
"The Arduino Mega has three additional serial ports: 
Kod:
Serial1
 on pins 19 (RX) and 18 (TX), 
Kod:
Serial2
 on pins 17 (RX) and 16 (TX), 
Kod:
Serial3
 on pins 15 (RX) and 14 (TX). 
To use these pins to communicate with your personal computer, you will need an additional USB-to-serial adaptor, as they are not connected to the Mega’s USB-to-serial adaptor. To use them to communicate with an external TTL serial device, connect the TX pin to your device’s RX pin, the RX to your device’s TX pin, and the ground of your Mega to your device’s ground." i sam się domyślisz czy to ma prawo się udać.