Wa Koodu

Gba GPS Location lati awọn modulu GPS U-blox Neo-6 ati Neo-7 pẹlu Arduino

Gba GPS Location lati awọn modulu GPS U-blox Neo-6 ati Neo-7 pẹlu Arduino

Iṣẹ́ yìí ṣàfihàn bí a ṣe ń ṣopọ̀ module GPS U-blox Neo-6M tàbí Neo-7M pẹ̀lú Arduino láti gba data ipo (latitude àti longitude). Àwọn module tí kò gbowó yìí, tí a lè rí ní orí ayélujára, pèsè ọ̀nà tí ó rọrùn láti fi ìṣiṣẹ́ GPS kún àwọn iṣẹ́ rẹ. LED bulu tí ó yàtọ̀ lórí Neo-7M (nínú fídíò ní 02:53) ń fi àmì GPS fix han, ẹ̀yà tí ó wúlò fún ìfìdírí gbígba ifihan.

gps_neo-6m_neo-7m-1

Àwọn èrò díẹ̀ nínú iṣẹ́ pẹ̀lú module GPS àti Arduino:

  • Olùtọ̀nà GPS: Kọ data ipo sílẹ̀ kí o sì fi hàn lórí máàpù.
  • Ọ̀pá ìdarí Geocaching: Lọ sí àwọn ipoidojúkọ pàtó.
  • Ìdarí Ọkọ̀ Aifọwọ́yi: Darí robot tàbí drone.
  • Ilé Ìwọ̀n Ojúọjọ́: Fi data ipo kún àwọn ìwọ̀n ojúọjọ́.
  • Ìtọ̀nà Ẹranko: Ṣe àbójútó ìṣísẹ̀ ẹranko.
gps_neo-6m_neo-7m-4

Ohun èlò / Àwọn ẹ̀yà

  • Arduino Uno (tàbí bọọdù tí ó báramu)
  • Module GPS U-blox Neo-6M tàbí Neo-7M
  • Àwọn okun oníjàngbọ̀n
  • Okun USB
  • (Kì í ṣe dandan) Antenna òde àti asopọ̀ SMA
gps_neo-6m_neo-7m-3

Ìtọ́sọ́nà Ìsopọ̀

gps_neo-6m_neo-7m-2-wiring

Ìsopọ̀ náà rọrùn (nínú fídíò ní 10:39):

%%WIRING%%

  • GPS VCC sí Arduino 3.3V
  • GPS GND sí Arduino GND
  • GPS TX sí pin 3 Arduino (tí a ṣàlàyé gẹ́gẹ́ bí RX nínú kóòdù)
  • GPS RX sí pin 4 Arduino (tí a ṣàlàyé gẹ́gẹ́ bí TX nínú kóòdù)

Rántí, TX sopọ̀ sí RX àti òmíràn (nínú fídíò ní 11:10). Fídíò náà tún fi hàn bí a ṣe le lo àwọn okun oníjàngbọ̀n rírọrùn fún ìsopọ̀ (nínú fídíò ní 10:24).

Àlàyé Kóòdù

Iṣẹ́ yìí ń lo ilé-ìkàwé TinyGPS++. Ṣe ìgbàlódò sílẹ̀ kí o sì fi sí i nípasẹ̀ olùṣàkóso ilé-ìkàwé Arduino IDE. Àwọn àtúnṣe kóòdù pàtàkì ni ìtumọ̀ àwọn pin serial software àti iye baud (nínú fídíò ní 07:00):


#include <TinyGPS++.h>
#include <SoftwareSerial.h>

static const int RXPin = 3, TXPin = 4;
static const uint32_t GPSBaud = 9600; // Àìyàn àkọ́kọ́ fún àwọn module U-blox

Àwọn àṣàyàn RXPin àti TXPin ń ṣàlàyé àwọn pin Arduino tí a sopọ̀ sí module GPS. Iye baud àìyàn àkọ́kọ́ fún àwọn module U-blox jẹ́ 9600. Ohun pàtàkì nínú kóòdù ni kíka data serial láti GPS àti ṣíṣe àtúpalẹ̀ rẹ̀ nípasẹ̀ ilé-ìkàwé TinyGPS++ (nínú fídíò ní 08:03):


// Ohun TinyGPS++
TinyGPSPlus gps;

// Ìsopọ̀ serial sí ẹ̀rọ GPS
SoftwareSerial ss(RXPin, TXPin);

// ... (nínú ìṣiṣẹ́ loop) ...
while (ss.available() > 0)
  if (gps.encode(ss.read()))
    displayInfo();

Ìṣiṣẹ́ displayInfo() náà wá yọ latitude àti longitude jáde kí ó sì tẹ̀ wọ́n sílẹ̀ nígbàkigbà tí a bá gba GPS fix tí ó wulo (nínú fídíò ní 09:07):


void displayInfo()
{
  // ... kóòdù mìíràn ...

  if (gps.location.isValid())
  {
    Serial.print(gps.location.lat(), 6); // Latitude pẹ̀lú àwọn nọ́ńbà ẹ̀ẹ́wàá mẹ́fà
    Serial.print(F(","));
    Serial.print(gps.location.lng(), 6); // Longitude pẹ̀lú àwọn nọ́ńbà ẹ̀ẹ́wàá mẹ́fà
  }
  // ... kóòdù mìíràn ...
}

Iṣẹ́ Ààyè / Ìfihàn

Fídíò náà (nínú fídíò ní 12:29) ń fi iṣẹ́ náà hàn nígbà tí ó ń ṣiṣẹ́, tí ó fi àbájáde "INVALID" àkọ́kọ́ hàn nígbà tí kò sí ifihan GPS, kí ó sì wá fi àwọn ipoidojúkọ tí ó wulo hàn nígbà tí a ti gba fix. LED bulu tí ń ṣẹ́ kọ̀ọ̀kan lórí Neo-7M pèsè ìfìdírí ojú fún ifihan GPS (nínú fídíò ní 13:49).

GPS__451
GPS__451

Àwọn Orí Kọ̀ọ̀kan

  • [00:00] Ìfihàn àti Àkópọ̀ Iṣẹ́
  • [00:32] Àwọn Ìyàtọ̀ Module GPS (Neo-6M àti Neo-7M)
  • [04:30] Ìsopọ̀ Module GPS sí Arduino
  • [06:12] Àlàyé Kóòdù àti Ilé-ìkàwé TinyGPS++
  • [10:07] Àlàyé Ìsopọ̀ Kíkún àti Àwọn Ìlànà TX/RX
  • [12:29] Ìfihàn Ààyè àti Gbígba Ifihan

Aworan

GPS__451
GPS__451
gps_neo-6m_neo-7m-1
gps_neo-6m_neo-7m-1
gps_neo-6m_neo-7m-2-wiring
gps_neo-6m_neo-7m-2-wiring
gps_neo-6m_neo-7m-3
gps_neo-6m_neo-7m-3
gps_neo-6m_neo-7m-4
gps_neo-6m_neo-7m-4
155-Get GPS location from U-Blox Neo-6 and Neo-7 GPS modules with Arduino
Ede: C++
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
/*
 * Original library source: https://github.com/mikalhart/TinyGPSPlus
   This sample sketch demonstrates the normal use of a TinyGPSPlus object.
   It requires the use of SoftwareSerial, and assumes that you have a
   4800-baud serial GPS device hooked up on pins 3(rx) and 4(tx).

   Modified by Ahmad Shamshiri for Robojax.com 
   on September 09, 2018 at 20:20 in Ajax, Ontario, Canada
   Watch video instructions for this code:https://youtu.be/hbRpr1HbDf8
*/
static const int RXPin = 3, TXPin = 4;
static const uint32_t GPSBaud = 9600;

// The TinyGPS++ object
TinyGPSPlus gps;

// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);

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

  Serial.println(F("Robojax GPS Demo"));
  Serial.println(F("A simple demonstration of TinyGPS++ with an attached GPS module"));
  Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
  Serial.println(F("by Mikal Hart"));
  Serial.println();
}

void loop()
{

  // This sketch displays information every time a new sentence is correctly encoded.
  while (ss.available() > 0)
    if (gps.encode(ss.read()))
      displayInfo();

  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    Serial.println(F("No GPS detected: check wiring."));
    while(true);
  }
 delay(100);
}

void displayInfo()
{
  Serial.print(F("Location: ")); 
  if (gps.location.isValid())
  {
    Serial.print(gps.location.lat(), 6);
    Serial.print(F(","));
    Serial.print(gps.location.lng(), 6);
  }
  else
  {
    Serial.print(F("INVALID"));
  }

  Serial.print(F("  Date/Time: "));
  if (gps.date.isValid())
  {
    Serial.print(gps.date.month());
    Serial.print(F("/"));
    Serial.print(gps.date.day());
    Serial.print(F("/"));
    Serial.print(gps.date.year());
  }
  else
  {
    Serial.print(F("INVALID"));
  }

  Serial.print(F(" "));
  if (gps.time.isValid())
  {
    if (gps.time.hour() < 10) Serial.print(F("0"));
    Serial.print(gps.time.hour());
    Serial.print(F(":"));
    if (gps.time.minute() < 10) Serial.print(F("0"));
    Serial.print(gps.time.minute());
    Serial.print(F(":"));
    if (gps.time.second() < 10) Serial.print(F("0"));
    Serial.print(gps.time.second());
    Serial.print(F("."));
    if (gps.time.centisecond() < 10) Serial.print(F("0"));
    Serial.print(gps.time.centisecond());
  }
  else
  {
    Serial.print(F("INVALID"));
  }

  Serial.println();
}

Orisun & itọkasi

Fáìlìs📁

Awọn faili miiran

  • GPS TinyGPSPlus NEO-7 DataSheet
    Datasheet for the u-blox NEO-7 GPS module, a compact GNSS receiver with high sensitivity and low power consumption. It provides positioning data via UART and is commonly used with Arduino and the TinyGPSPlus library.
    robojax_GPS_TinyGPSPlus_NEO-7_DataSheet.pdf 1.73 MB