
Este módulo opera com 5V e assim que é energizado começa a transmitir coordenadas no pino TXD (mas só serão válidas após o tempo de fix) , repetindo a cada 1s. A baudrate é 9600bps. O pino RXD só tem utilidade se você quiser reconfigurar o módulo, por isso você pode deixá-lo desconectado.
Teste básico
(não requer que o GPS esteja vendo satélites)
No Arduino Mega
Atenção: qualquer exemplo que você pegar na internet que use a biblioteca Newsoftserial poderá não funcionar no Mega. Nesse modelo de arduino, use as portas seriais reais.
Ligue o TXD do GPS no pino RX1 do Mega
Rode o sketch (não é preciso mudar nada) Examples -> Communication -> MultiserialMega
Algo assim deve aparecer no Serial Monitor (repete-se a cada 1s):
|
$GPRMC,204433.215,V,,,,,0.00,0.00,131013,,,N*48 $GPGGA,204434.215,,,,,0,0,,,M,,M,,*4B $GPGSA,A,1,,,,,,,,,,,,,,,*1E $GPGSV,1,1,01,09,,,23*70 |
No Arduino UNO
Instale a biblioteca NewSoftSerial
Ligue o TXD do GPS no pino 2 do Arduino.
Rode o seguinte sketch, ligeiramente adaptado do exemplo TwoPortReceive
#include <SoftwareSerial.h>
SoftwareSerial portOne(2,3);
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// Start each software serial port
portOne.begin(9600);
}
void loop()
{
// By default, the last intialized port is listening.
// when you want to listen on a port, explicitly select it:
portOne.listen();
Serial.println("Recebido do GPS:");
// while there is data coming in, read it
// and send to the hardware serial port:
while (portOne.available() > 0) {
char inByte = portOne.read();
Serial.write(inByte);
}
delay(1000);
Serial.println("");
Serial.println("");
}
Algo assim deve aparecer no Serial Monitor (repete-se a cada 1s):
|
Recebido do GPS: $GPGGA,210946.907,,,,,0,0,,,M,,M,,*4E $GPGSA,A,1,,,,,,,,,,,,,, |
Teste completo
Não faça este teste se sua instalação não tiver passado ainda no teste básico.
Neste teste o GPS precisa ver os satélites. Para isso você precisa estar num local que tenha visão direta para o céu e o lado da antena do GPS precisa estar voltado para cima.
Em um Arduino UNO
Instale a biblioteca TinyGPS (documentação e download da v13). Requer NewsoftSerial.
Conecte o TXD do GPS ao pino 4 do UNO.
Carregue o exemplo Examples -> TinyGPS -> test_with_gps_device
Mude a linha
ss.begin(4800);
para
ss.begin(9600);
Faça o upload do sketch.
Em um Arduino Mega
Instale a biblioteca TinyGPS (documentação e download da v13).
Conecte o TXD do GPS a RX1 do Mega.
Atenção: Os exemplos do TinyGPS usam a biblioteca Newsoftserial, que tem certos problemas para funcionar no Mega. Por isso eu fiz ligeiras modificações no exemplo para usar uma porta serial real do Mega.
Faça o upload do seguinte sketch:
#include <TinyGPS.h>
/* Exemplo test_with_gps_device modificado para usar a porta serial 1
do Arduino Mega.
Jefferson Ryan - Automalabs - 13/10/2013
*/
TinyGPS gps;
static void smartdelay(unsigned long ms);
static void print_float(float val, float invalid, int len, int prec);
static void print_int(unsigned long val, unsigned long invalid, int len);
static void print_date(TinyGPS &gps);
static void print_str(const char *str, int len);
void setup()
{
Serial.begin(115200);
Serial1.begin(9600);
Serial.print("Testing TinyGPS library v. ");
Serial.println(TinyGPS::library_version());
Serial.println("by Mikal Hart");
Serial.println();
Serial.println("Sats HDOP Latitude Longitude Fix Date Time Date Alt Course Speed Card Distance Course Card Chars Sentences Checksum");
Serial.println(" (deg) (deg) Age Age (m) --- from GPS ---- ---- to London ---- RX RX Fail");
Serial.println("-------------------------------------------------------------------------------------------------------------------------------------");
}
void loop()
{
float flat, flon;
unsigned long age, date, time, chars = 0;
unsigned short sentences = 0, failed = 0;
static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002;
print_int(gps.satellites(), TinyGPS::GPS_INVALID_SATELLITES, 5);
print_int(gps.hdop(), TinyGPS::GPS_INVALID_HDOP, 5);
gps.f_get_position(&flat, &flon, &age);
print_float(flat, TinyGPS::GPS_INVALID_F_ANGLE, 10, 6);
print_float(flon, TinyGPS::GPS_INVALID_F_ANGLE, 11, 6);
print_int(age, TinyGPS::GPS_INVALID_AGE, 5);
print_date(gps);
print_float(gps.f_altitude(), TinyGPS::GPS_INVALID_F_ALTITUDE, 7, 2);
print_float(gps.f_course(), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2);
print_float(gps.f_speed_kmph(), TinyGPS::GPS_INVALID_F_SPEED, 6, 2);
print_str(gps.f_course() == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(gps.f_course()), 6);
print_int(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0xFFFFFFFF : (unsigned long)TinyGPS::distance_between(flat, flon, LONDON_LAT, LONDON_LON) / 1000, 0xFFFFFFFF, 9);
print_float(flat == TinyGPS::GPS_INVALID_F_ANGLE ? TinyGPS::GPS_INVALID_F_ANGLE : TinyGPS::course_to(flat, flon, LONDON_LAT, LONDON_LON), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2);
print_str(flat == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(TinyGPS::course_to(flat, flon, LONDON_LAT, LONDON_LON)), 6);
gps.stats(&chars, &sentences, &failed);
print_int(chars, 0xFFFFFFFF, 6);
print_int(sentences, 0xFFFFFFFF, 10);
print_int(failed, 0xFFFFFFFF, 9);
Serial.println();
smartdelay(1000);
}
static void smartdelay(unsigned long ms)
{
unsigned long start = millis();
do
{
while (Serial1.available())
gps.encode(Serial1.read());
} while (millis() - start < ms);
}
static void print_float(float val, float invalid, int len, int prec)
{
if (val == invalid)
{
while (len-- > 1)
Serial.print('*');
Serial.print(' ');
}
else
{
Serial.print(val, prec);
int vi = abs((int)val);
int flen = prec + (val < 0.0 ? 2 : 1); // . and -
flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
for (int i=flen; i<len; ++i)
Serial.print(' ');
}
smartdelay(0);
}
static void print_int(unsigned long val, unsigned long invalid, int len)
{
char sz[32];
if (val == invalid)
strcpy(sz, "*******");
else
sprintf(sz, "%ld", val);
sz[len] = 0;
for (int i=strlen(sz); i<len; ++i)
sz[i] = ' ';
if (len > 0)
sz[len-1] = ' ';
Serial.print(sz);
smartdelay(0);
}
static void print_date(TinyGPS &gps)
{
int year;
byte month, day, hour, minute, second, hundredths;
unsigned long age;
gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age);
if (age == TinyGPS::GPS_INVALID_AGE)
Serial.print("********** ******** ");
else
{
char sz[32];
sprintf(sz, "%02d/%02d/%02d %02d:%02d:%02d ",
month, day, year, hour, minute, second);
Serial.print(sz);
}
print_int(age, TinyGPS::GPS_INVALID_AGE, 5);
smartdelay(0);
}
static void print_str(const char *str, int len)
{
int slen = strlen(str);
for (int i=0; i<len; ++i)
Serial.print(i<slen ? str[i] : ' ');
smartdelay(0);
}
Se seu GPS estiver enxergando os satélites, a saída será parecida com isto (eu dividi em duas partes porque não cabia na tela e alterei as coordenadas por privacidade):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
Testing TinyGPS library v. 13 by Mikal Hart Sats HDOP Latitude Longitude Fix Date Time Date Alt (deg) (deg) Age Age (m) -------------------------------------------------------------------- **** **** ********* ********** **** ********** ******** **** ****** 9 91 -8.022881 -34.324093 83 10/13/2013 22:18:40 95 20.00 9 91 -8.022881 -34.324093 89 10/13/2013 22:18:41 102 20.00 9 91 -8.022881 -34.324093 101 10/13/2013 22:18:42 113 20.00 9 91 -8.022881 -34.324093 122 10/13/2013 22:18:43 135 20.00 9 91 -8.022881 -34.324093 134 10/13/2013 22:18:44 148 20.00 Course Speed Card Distance Course Card Chars Sentences Checksum --- from GPS ---- ---- to London ---- RX RX Fail ----------------------------------------------------------------- ****** ***** *** ******* ****** *** 39 0 1 60.25 0.00 ENE 7418 22.79 NNE 502 2 1 60.25 0.00 ENE 7418 22.79 NNE 944 4 1 60.25 0.00 ENE 7418 22.79 NNE 1393 6 1 60.25 0.00 ENE 7418 22.79 NNE 1850 8 1 60.25 0.00 ENE 7418 22.79 NNE 2299 10 1 |
Se seu GPS não estiver enxergando os satélites, a saída de TinyGPS será parecida com isto (eu dividi em duas partes porque não cabia na tela):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
Testing TinyGPS library v. 13 by Mikal Hart Sats HDOP Latitude Longitude Fix Date Time Date Alt (deg) (deg) Age Age (m) -------------------------------------------------------------------- **** **** ********* ********** **** ********** ******** **** ****** **** **** ********* ********** **** ********** ******** **** ****** **** **** ********* ********** **** ********** ******** **** ****** **** **** ********* ********** **** ********** ******** **** ****** **** **** ********* ********** **** ********** ******** **** ****** Course Speed Card Distance Course Card Chars Sentences Checksum --- from GPS ---- ---- to London ---- RX RX Fail ----------------------------------------------------------------- ****** ***** *** ******* ****** *** 0 0 0 ****** ***** *** ******* ****** *** 136 0 0 ****** ***** *** ******* ****** *** 272 0 0 ****** ***** *** ******* ****** *** 408 0 0 ****** ***** *** ******* ****** *** 544 0 0 |
Note que o valor de Chars RX está incrementando em passos fixos (no caso, 136). Isso siginifica que a biblioteca está recebendo dados do GPS, mas não há coordenadas válidas nesses dados. Se Chars RX não estiver incrementando verfique todas as conexões.
Se você realmente precisar reconfigurar esse GPS, o documento MTK NMEA Packet User Manual (link para download no fim do texto) pode ser o que você precisa. Eu não testei, não aconselho seu uso e não dou garantias. Se você mexer nas configurações considere minha garantia finalizada. Estou fornecendo o arquivo apenas para sua conveniência.
Data: | 13 de outubro de 2013 |
Data: | 13 de outubro de 2013 |
Comentários