• How to Use GPS module with STM32F103C8 to Get Location Coordinates

QC

How to Use GPS module with STM32F103C8 to Get Location Coordinates

 How to Use GPS module with STM32F103C8 to Get Location Coordinates



GPS là viết tắt của Hệ thống Định vị Toàn cầu và được sử dụng để phát hiện Vĩ độ và Kinh độ của bất kỳ vị trí nào trên Trái đất, với thời gian UTC chính xác (Phối hợp theo giờ quốc tế). Thiết bị này nhận tọa độ từ vệ tinh trong từng giây từng giây, với thời gian và ngày tháng. GPS cung cấp độ chính xác cao và cũng cung cấp dữ liệu khác ngoài tọa độ vị trí.


Chúng ta đều biết rằng GPS là một thiết bị rất hữu ích và được sử dụng rất phổ biến trong điện thoại di động và các thiết bị cầm tay khác để theo dõi vị trí. Nó có rất nhiều ứng dụng trong mọi lĩnh vực từ gọi taxi tại nhà của bạn để theo dõi độ cao của máy bay. Dưới đây là một số dự án hữu ích liên quan đến GPS, chúng tôi đã xây dựng trước đây:

Components Required

  • STM32F103C8 Microcontroller
  • GPS Module
  • 16x2 LCD display
  • Breadboard
  • Connecting Wires

Circuit Diagram and Connections


Circuit Connections between GPS module & STM32F103C8

GPS ModuleSTM32F103C8
RXDPA9 (TX1)
TXDPA10 (RX1)
+5V+5V
GNDGND

Connections between 16x2 LCD & STM32F103C8

LCD Pin NoLCD Pin NameSTM32 Pin Name
1Ground (Gnd)Ground (G)
2VCC5V
3VEEPin from Centre of Potentiometer
4Register Select (RS)PB11
5Read/Write (RW)Ground (G)
6Enable (EN)PB10
7Data Bit 0 (DB0)No Connection (NC)
8Data Bit 1 (DB1)No Connection (NC)
9Data Bit 2 (DB2)No Connection (NC)
10Data Bit 3 (DB3)No Connection (NC)
11Data Bit 4 (DB4)PB0
12Data Bit 5 (DB5)PB1
13Data Bit 6 (DB6)PC13
14Data Bit 7 (DB7)PC14
15LED Positive5V
16LED NegativeGround (G)

The whole setup will look like below:



Programming STM32F103C8 for GPS Module Interfacing

#include <LiquidCrystal.h>     //Library for using LCD display functions                      
#include <TinyGPS++.h>         //Library for using GPS functions

const int rs = PB11, en = PB10, d4 = PB0, d5 = PB1, d6 = PC13, d7 = PC14;  //LCD pins connected with STM32
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

TinyGPSPlus gps;               //Object gps for class TinyGPSPlus

void setup()
{
  Serial1.begin(9600);         //Begins Serial comunication at Serial Port 1 at 9600 baudrate
  lcd.begin(16,2);             //Sets display in 16x2 Mode
  lcd.print("Circuit Digest");
  lcd.setCursor(0,1);
  lcd.print("STM32 with GPS");
  delay(4000);
  lcd.clear();      
}

void loop()
{
  GPSDelay(1000);
  unsigned long start;
  double lat_val, lng_val;
  bool loc_valid;
  lat_val = gps.location.lat();        //Gets the latitude
  loc_valid = gps.location.isValid(); 
  lng_val = gps.location.lng();        //Gets the longitude
 
  if (!loc_valid)                     //Excecutes when invalid data is received from GPS
  {
    lcd.print("Waiting");
    Serial.print("Latitude : ");
    Serial.println("*****");
    Serial.print("Longitude : ");
    Serial.println("*****");
    delay(4000);
    lcd.clear();
  }
  else                              //Excutes when valid data is received from GPS
  {
    lcd.clear();
    
    Serial.println("GPS READING: ");
   
    Serial.print("Latitude : ");
    Serial.println(lat_val, 6);   //Prints latitude at Serial Monitor
   
    lcd.setCursor(0,0);
    lcd.print("LAT:");
    lcd.print(lat_val,6);         //Prints latitude at LCD display

    Serial.print("Longitude : ");
    Serial.println(lng_val, 6);   //Prints longitude at Serial monitor

    lcd.setCursor(0,1);
    lcd.print("LONG:");
    lcd.print(lng_val,6);          //Prints longitude at LCD display

    delay(4000);
  }
}

static void GPSDelay(unsigned long ms)          //Delay for receiving data from GPS
{
  unsigned long start = millis();
  do
  {
    while (Serial1.available()) 
    gps.encode(Serial1.read());
  } while (millis() - start < ms);
}








Nap Code vào PY32F003 dùng Stlink

 Nap Code vào PY32F003 dùng Stlink Bước 1: Cài đặt  KeilC v5.39 theo link sau ( chú ý 5.39 keil c mới nạp ok). https://edge07.111.ir.cdn.ir/...