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):
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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#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):
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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
#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):
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.
Clique para acessar o SkyNav_SKM53_Datasheet.pdf
Clique para acessar o PMTK_Protocol.pdf
Fonte: http://www.automalabs.com.br/modulo-gps-skylab-skm53/#comment-2321