Mediatek GPS connected to ATmega1280 does not work.

3690902684?profile=originalHi,

I am currently trying to get GPS signal using Mediatek GPS connected to ATmega1280 as shown in the pictures. Now, Mediateck GPS shows solid blue LED, but LED C does not show red light. In addition, serial monitor shows only "." 

'Example_GPS' is used for the tests, and code is shown in the below. What I am guessing as error source is RXPIN and TXPIN number. Could anyone give me comments on it?

 

 ---------------------------------------------------------------------------------------------------------

/*
6-8-10
Aaron Weiss
SparkFun Electronics

Example GPS Parser based off of arduiniana.org TinyGPS examples.

Parses NMEA sentences from an EM406 running at 4800bps into readable
values for latitude, longitude, elevation, date, time, course, and
speed.

For the SparkFun GPS Shield. Make sure the switch is set to DLINE.

Once you get your longitude and latitude you can paste your
coordinates from the terminal window into Google Maps. Here is the
link for SparkFun's location.
http://maps.google.com/maps?q=40.06477,+-105.20997

Uses the NewSoftSerial library for serial communication with your GPS,
so connect your GPS TX and RX pin to any digital pin on the Arduino,
just be sure to define which pins you are using on the Arduino to
communicate with the GPS module.

REVISIONS:
1-17-11
changed values to RXPIN = 2 and TXPIN = to correspond with
hardware v14+. Hardware v13 used RXPIN = 3 and TXPIN = 2.

*/

// In order for this sketch to work, you will need to download
// NewSoftSerial and TinyGPS libraries from arduiniana.org and put them
// into the hardware->libraries folder in your ardiuno directory.
// Here are the lines of code that point to those libraries.
#include <NewSoftSerial.h>
#include <TinyGPS.h>

// Define which pins you will use on the Arduino to communicate with your
// GPS. In this case, the GPS module's TX pin will connect to the
// Arduino's RXPIN which is pin 3.
//#define RXPIN 2
//#define TXPIN 3

#define RXPIN 15
#define TXPIN 14

//Set this value equal to the baud rate of your GPS
//#define GPSBAUD 4800
#define GPSBAUD 38400

// Create an instance of the TinyGPS object
TinyGPS gps;
// Initialize the NewSoftSerial library to the pins you defined above
NewSoftSerial uart_gps(RXPIN, TXPIN);

// This is where you declare prototypes for the functions that will be
// using the TinyGPS library.
void getgps(TinyGPS &gps);

// In the setup function, you need to initialize two serial ports; the
// standard hardware serial port (Serial()) to communicate with your
// terminal program an another serial port (NewSoftSerial()) for your
// GPS.
void setup()
{
// This is the serial rate for your terminal program. It must be this
// fast because we need to print everything before a new sentence
// comes in. If you slow it down, the messages might not be valid and
// you will likely get checksum errors.
Serial.begin(115200);
//Sets baud rate of your GPS
uart_gps.begin(GPSBAUD);

Serial.println("");
Serial.println("GPS Shield QuickStart Example Sketch v12");
Serial.println(" ...waiting for lock... ");
Serial.println("");
}

// This is the main loop of the code. All it does is check for data on
// the RX pin of the ardiuno, makes sure the data is valid NMEA sentences,
// then jumps to the getgps() function.
void loop()
{
while(uart_gps.available()) // While there is data on the RX pin...
{
int c = uart_gps.read(); // load the data into a variable...
if(gps.encode(c)) // if there is a new valid sentence...
{
getgps(gps); // then grab the data.
}
}
}

// The getgps function will get and print the values we want.
void getgps(TinyGPS &gps)
{
// To get all of the data into varialbes that you can use in your code,
// all you need to do is define variables and query the object for the
// data. To see the complete list of functions see keywords.txt file in
// the TinyGPS and NewSoftSerial libs.

// Define the variables that will be used
float latitude, longitude;
// Then call this function
gps.f_get_position(&latitude, &longitude);
// You can now print variables latitude and longitude
Serial.print("Lat/Long: ");
Serial.print(latitude,5);
Serial.print(", ");
Serial.println(longitude,5);

// Same goes for date and time
int year;
byte month, day, hour, minute, second, hundredths;
gps.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths);
// Print data and time
Serial.print("Date: "); Serial.print(month, DEC); Serial.print("/");
Serial.print(day, DEC); Serial.print("/"); Serial.print(year);
Serial.print(" Time: "); Serial.print(hour, DEC); Serial.print(":");
Serial.print(minute, DEC); Serial.print(":"); Serial.print(second, DEC);
Serial.print("."); Serial.println(hundredths, DEC);
//Since month, day, hour, minute, second, and hundr

// Here you can print the altitude and course values directly since
// there is only one value for the function
Serial.print("Altitude (meters): "); Serial.println(gps.f_altitude());
// Same goes for course
Serial.print("Course (degrees): "); Serial.println(gps.f_course());
// And same goes for speed
Serial.print("Speed(kmph): "); Serial.println(gps.f_speed_kmph());
Serial.println();

// Here you can print statistics on the sentences.
unsigned long chars;
unsigned short sentences, failed_checksum;
gps.stats(&chars, &sentences, &failed_checksum);
//Serial.print("Failed Checksums: ");Serial.print(failed_checksum);
//Serial.println(); Serial.println();
}

---------------------------------------------------------------------------------------------------------

Capture.PNG

IMG_0121[1].JPG

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • hi Sunghun,

    I'm trying to read Gps data in the same way than you but It doesn't work.

    I am using a APM1(2560) with a MTK3329. I think there is an error in RXPin and TXPin. When I run the program the console shows: 

    *___ Mi primer Gps ___* 

    Andres Lopez
    Iniciando Gps...
    RxPin no disponible.
    RxPin no disponible.
    RxPin no disponible.
    RxPin no disponible.
    RxPin no disponible.
    RxPin no disponible.

    Could anyone give me comments on it? I need help.

     

    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------

     

    // necessary libraries
    #include <NewSoftSerial.h>
    #include <TinyGPS.h>

    #define RXPIN 4 // GPS TX pin connects to Arduino D0 (thankfully by default)
    #define TXPIN 3 // GPS RX pin connects to Arduino D1. You could change these if making your own hardware
    #define GPSBAUD 38400 // baud rate of our EM-406 GPS module. Change for your GPS module if different

    // Create an instance of the TinyGPS object
    TinyGPS gps;
    // Initialize the NewSoftSerial library to the pins you defined above
    NewSoftSerial uart_gps(RXPIN, TXPIN);


    void getgps(TinyGPS &gps);

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

    uart_gps.begin(GPSBAUD);

    Serial.print("*___ Mi primer Gps ___* \r\n");
    Serial.print("Andres Lopez\r\n");
    delay(2000);
    Serial.print("Iniciando Gps...\r\n");
    delay(3000);
    }

    void loop()
    {
    while(uart_gps.available()) // While there is data on the RX pin...
    {
    Serial.print("RxPin disponible");
    int c = uart_gps.read(); // load the data into a variable...
    if(gps.encode(c)) // if there is a new valid sentence...
    {
    getgps(gps); // then grab the data, and display on LCD
    }
    }
    Serial.print("RxPin no disponible.\r\n");
    }


    // The getgps function will get and print the values we want.
    void getgps(TinyGPS &gps)
    {
    // Define the variables that will be used
    float latitude, longitude;
    // Then call this function
    gps.f_get_position(&latitude, &longitude);

    Serial.print("Latitud: ");
    Serial.print(latitude,5);
    Serial.print("Longitud: ");
    Serial.print(longitude,5);


    // Same goes for date and time
    int year;
    byte month, day, hour, minute, second, hundredths;
    gps.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths);

    Serial.print(hour, DEC);
    Serial.print(":");

    if (minute<10)
    {
    Serial.print("0");
    Serial.print(minute, DEC);
    } else if (minute>=10)
    {
    Serial.print(minute, DEC);
    }

    Serial.print(":");


    if (second<10)
    {
    Serial.print("0");
    Serial.print(second, DEC);
    } else if (second>=10)
    {
    Serial.print(second, DEC);
    }

    Serial.print(" ");
    Serial.print(day, DEC);
    Serial.print("/");
    Serial.print(month, DEC);
    Serial.print("/");
    Serial.print(year, DEC);
    Serial.print(gps.f_altitude());
    Serial.print("m ");
    Serial.print(gps.f_speed_kmph());
    Serial.print("km/h");

    // Here you can print statistics on the sentences.
    unsigned long chars;
    unsigned short sentences, failed_checksum;
    gps.stats(&chars, &sentences, &failed_checksum);

    }

     

  • That is an ArduPilot Mega, with a 1280, and has 4 serial ports.

    The GPS is plugged into one of the serial ports.

    Therefore you do not need the "New Soft Serial" library. That is for Arduino which only has one serial port and already in use for debugging or USB or whatever, so it needs to bit-bang to use any other pins as serial ports.

    You just need to talk to serial port 3 (numbered from 0)

    Serial3.begin(GPSBAUD)

    Serial3.print ... 

    (etc)
     

    and then you can reach the GPS

This reply was deleted.

Activity

Neville Rodrigues liked Neville Rodrigues's profile
Jun 30
Santiago Perez liked Santiago Perez's profile
Jun 21
More…