Здравствуйте все кто читает этот пост.
Имеется в наличии GPS NEO-6M-0-01 ublox и Arduino Mega2560 и есть скетч немного отредактированный (информацию для редактирования брал http://forum.arduino.cc/index.php?topic=107876.0 ) пример test_with_gps_device.ino под Arduino Mega2560 из библиотеки TinyGPS.h
Подключил TX GPS к RXD19 Arduino и соответственно RX GPS к TXD18 Arduino что соответствует Serial1 для Mega2560 ( http://arduino.cc/en/Reference/Serial )
Результатом работы видим вот такое...
Testing TinyGPS library v. 13
by Mikal Hart
Sats HDOP Latitude Longitude Fix Date Time Date Alt Course Speed Card Distance Course Card Chars Sentences Checksum
(deg) (deg) Age Age (m) --- from GPS ---- ---- to London ---- RX RX Fail
-------------------------------------------------------------------------------------------------------------------------------------
**** **** ********* ********** **** ********** ******** **** ****** ****** ***** *** ******* ****** *** 84 0 0
**** **** ********* ********** **** ********** ******** **** ****** ****** ***** *** ******* ****** *** 326 0 0
**** **** ********* ********** **** ********** ******** **** ****** ****** ***** *** ******* ****** *** 494 0 0
**** **** ********* ********** **** ********** ******** **** ****** ****** ***** *** ******* ****** *** 664 0 0
**** **** ********* ********** **** ********** ******** **** ****** ****** ***** *** ******* ****** *** 826 0 0
**** **** ********* ********** **** ********** ******** **** ****** ****** ***** *** ******* ****** *** 988 0 0
**** **** ********* ********** **** ********** ******** **** ****** ****** ***** *** ******* ****** *** 1150 0 0
**** **** ********* ********** **** ********** ******** **** ****** ****** ***** *** ******* ****** *** 1312 0 0
Подскажите что не правильно?
017 | static void gpsdump(TinyGPS &gps); |
018 | static bool feedgps(); |
019 | static void print_float( float val, float invalid, int len, int prec); |
020 | static void print_int(unsigned long val, unsigned long invalid, int len); |
021 | static void print_date(TinyGPS &gps); |
022 | static void print_str( const char *str, int len); |
029 | Serial .print( "Testing TinyGPS library v. " ); Serial .println(TinyGPS::library_version()); |
030 | Serial .println( "by Mikal Hart" ); |
032 | Serial .println( "Sats HDOP Latitude Longitude Fix Date Time Date Alt Course Speed Card Distance Course Card Chars Sentences Checksum" ); |
033 | Serial .println( " (deg) (deg) Age Age (m) --- from GPS ---- ---- to London ---- RX RX Fail" ); |
034 | Serial .println( "-------------------------------------------------------------------------------------------------------------------------------------" ); |
041 | unsigned long age, date, time, chars = 0; |
042 | unsigned short sentences = 0, failed = 0; |
043 | static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002; |
045 | print_int(gps.satellites(), TinyGPS::GPS_INVALID_SATELLITES, 5); |
046 | print_int(gps.hdop(), TinyGPS::GPS_INVALID_HDOP, 5); |
047 | gps.f_get_position(&flat, &flon, &age); |
048 | print_float(flat, TinyGPS::GPS_INVALID_F_ANGLE, 10, 6); |
049 | print_float(flon, TinyGPS::GPS_INVALID_F_ANGLE, 11, 6); |
050 | print_int(age, TinyGPS::GPS_INVALID_AGE, 5); |
052 | print_float(gps.f_altitude(), TinyGPS::GPS_INVALID_F_ALTITUDE, 7, 2); |
053 | print_float(gps.f_course(), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2); |
054 | print_float(gps.f_speed_kmph(), TinyGPS::GPS_INVALID_F_SPEED, 6, 2); |
055 | print_str(gps.f_course() == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(gps.f_course()), 6); |
056 | print_int(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0xFFFFFFFF : (unsigned long )TinyGPS::distance_between(flat, flon, LONDON_LAT, LONDON_LON) / 1000, 0xFFFFFFFF, 9); |
057 | 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); |
058 | print_str(flat == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(TinyGPS::course_to(flat, flon, LONDON_LAT, LONDON_LON)), 6); |
060 | gps.stats(&chars, &sentences, &failed); |
061 | print_int(chars, 0xFFFFFFFF, 6); |
062 | print_int(sentences, 0xFFFFFFFF, 10); |
063 | print_int(failed, 0xFFFFFFFF, 9); |
069 | static void smartdelay(unsigned long ms) |
071 | unsigned long start = millis(); |
074 | while (Serial1.available()) |
075 | gps.encode(Serial1.read()); |
076 | } while (millis() - start < ms); |
079 | static void print_float( float val, float invalid, int len, int prec) |
089 | Serial .print(val, prec); |
090 | int vi = abs(( int )val); |
091 | int flen = prec + (val < 0.0 ? 2 : 1); |
092 | flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1; |
093 | for ( int i=flen; i<len; ++i) |
099 | static void print_int(unsigned long val, unsigned long invalid, int len) |
103 | strcpy(sz, "*******" ); |
105 | sprintf(sz, "%ld" , val); |
107 | for ( int i=strlen(sz); i<len; ++i) |
115 | static void print_date(TinyGPS &gps) |
118 | byte month, day, hour, minute, second, hundredths; |
120 | gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age); |
121 | if (age == TinyGPS::GPS_INVALID_AGE) |
122 | Serial .print( "********** ******** " ); |
126 | sprintf(sz, "%02d/%02d/%02d %02d:%02d:%02d " , |
127 | month, day, year, hour, minute, second); |
130 | print_int(age, TinyGPS::GPS_INVALID_AGE, 5); |
135 | static void print_str( const char *str, int len) |
137 | int slen = strlen(str); |
138 | for ( int i=0; i<len; ++i) |
139 | Serial .print(i<slen ? str[i] : ' ' ); |
Вы где пробуете? У меня дома, например, ГПС сигнал практически отсутствует. Когда ГПС синхронизируется то начинает моргать СД на плате. У вас моргает?
Я, кстати, не помню почему, пользовал с этим модулем другую библиотеку и переделал из нее пример - рабочий.
01
// This example illustates basic use of the NMEA library.
02
// It assumes that a GPS receiver is connected to serial
03
// port 'Serial1' at 4800 bps, and that a LED is connected
04
// to digital i/o pin 0.
05
//
06
// A GPS data connection of type GPRMC is created, and
07
// used to get distance to a destination. If the distance
08
// is under 500 meters, the LED lights up, otherwise it
09
// is off.
10
11
#include <nmea.h>
12
13
NMEA gps(GPRMC);
// GPS data connection to GPRMC sentence type
14
15
// destination coordinates in degrees-decimal
16
float
dest_latitude = 60.000342;
17
float
dest_longitude = 30.294522;
18
19
void
setup
() {
20
Serial
.begin(9600);
21
Serial1.begin(9600);
22
pinMode(0, OUTPUT);
23
}
24
25
void
loop
() {
26
if
(Serial1.available() > 0 ) {
27
// read incoming character from GPS
28
char
c = Serial1.read();
29
30
// check if the character completes a valid GPS sentence
31
if
(gps.decode(c)) {
32
// check if GPS positioning was active
33
if
(gps.gprmc_status() ==
'A'
) {
34
// read distance to destination in meters and set led accordingly
35
if
(gps.gprmc_distance_to(dest_latitude, dest_longitude, MTR) < 500.0) {
36
digitalWrite(0, HIGH);
37
}
38
else
{
39
digitalWrite(0, LOW);
40
}
41
Serial
.print (
"Sentence = "
);
42
Serial
.println (gps.gprmc_distance_to(dest_latitude, dest_longitude, MTR));
43
}
44
}
45
}
46
}
нет не моргает. Вы имеете в виде СД PWR, он единственный на плате.
Спасибо все заработало :)
Интересное дело, после того как отработала ваша программа, заработал и TinyGPS :)