GPS module
Article directory
foreword
There is also a GPS in hand, it is very convenient to use arduino as a module. It is planned to be combined with the SMS module. The SMS module has been used last time. This time, learn the GPS module and see the module
. You need to pay attention to set the corresponding baud rate, the baud rate of GPS module is 115200. When using it, it must be noted that the latitude and longitude cannot be obtained indoors, so it must be tested outdoors. Let's see how to use this module.
1. Arduino code
If you just write a serial port and print the content, you can see a large area of GPS output, but when we use it, we often only need latitude and longitude. A TinyGPS++ analysis library is provided in arduino, which can analyze the latitude and longitude. If the library will not be installed, you can read the previous blog, and here is the code directly.
/*
richowe
*/
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
TinyGPSPlus gps;
SoftwareSerial ss(6, 7);
float latitude;
float longitude;
int incomedate=0;
void setup()
{
Serial.begin(9600); //set the baud rate of serial port to 9600;
ss.begin(115200); //set the GPS baud rate to 9600;
}
void loop()
{
while (ss.available() > 0)
{
gps.encode(ss.read()); //The encode() method encodes the string in the encoding format specified by encoding.
if (gps.location.isUpdated())
{
latitude = gps.location.lat(); //gps.location.lat() can export latitude
longitude = gps.location.lng();//gps.location.lng() can export latitude
Serial.print("Latitude=");
Serial.print(latitude, 6); //Stable after the fifth position
Serial.print(" Longitude=");
Serial.println(longitude, 6);
delay(500);
}
}
}
Related information can be printed through the serial port.