УРЛАГ
ГОО САЙХАН БА ЭРҮҮЛ МЭНД
ГАРААР ХИЙСЭН
СОЁЛ БА ТҮҮХ
ҮЗВЭР НААДАМ
БАЙГАЛЬ ОРЧИН
ХООЛ БА УНДАА
УРВУУ ИНЖЕНЕРЧЛЭЛ
ШИНЖЛЭХ УХААН
СПОРТ
ТЕХНОЛОГИ
ӨМСДӨГ ХЭРЭГСЭЛ
GPS Position Logger
Ed

Зохиогч

Ed

14. Наймдугаар сар 2026FI
3
0
0
0
0

GPS Position Logger

A logger that writes where it has been to a microSD card. The GPS shield kit carries an EM-506 receiver that emits standard NMEA sentences over serial; the sketch keeps only the lines that carry a valid fix and appends them as CSV. It is the same logging pattern as the data-logging thermometer with position substituted for temperature, so the two share a card format and a workflow. A cold receiver with no stored almanac can take several minutes to reach its first fix, and it needs sky — it will not fix indoors.
Дунд шат
3 hours

Зааварчилгаа

1

Solder the GPS shield headers

The kit contains the shield, an EM-506 receiver with its interface cable, and R3 headers. Solder the headers to the shield.

Materials for this step:

SparkFun GPS Shield KitSparkFun GPS Shield Kit1 багц

Tools needed:

Ryobi ONE+ RSI18-0 Cordless Soldering IronRyobi ONE+ RSI18-0 Cordless Soldering Iron
2

Stack both shields and check for pin clashes

Plug the EM-506 into the shield's connector, then stack GPS shield and microSD shield on the Uno.

  1. GPS shield: receiver on D2/D3 with its switch in the DLINE position.
  2. microSD shield: SPI on D11/D12/D13, card select on D8.
Those two sets do not overlap, which is why the pair can stack. Always check this before powering any two shields together — a clash shows up as one board mysteriously not working.

Materials for this step:

microSD ShieldmicroSD Shield1 ширхэг
Arduino Uno R3 SMDArduino Uno R3 SMD1 ширхэг
3

Power, and read raw NMEA before parsing anything

USB-B from the computer while testing; 7–12 V on the barrel jack once it runs standalone.

Before writing any parser, print the receiver's output straight through and look at it. You should see comma-separated sentences beginning with $.

Sentences arriving with empty position fields mean the receiver is alive and talking but has no fix yet. That is the normal cold-start state — not a fault.

Materials for this step:

USB-B CableUSB-B Cable1 ширхэг
4

Upload the logging sketch

No GPS library needed — the sketch reads NMEA directly, so nothing is hidden behind an abstraction. SD and SPI ship with the IDE. Format the card FAT32 first.

gps_logger.inoarduino
// GPS Position Logger
// EM-506 on the GPS shield (D2/D3, DLINE) -> Uno -> microSD Shield (CS D8)
// Appends one CSV line per VALID fix: utc,latitude,longitude
//
// Parses $GPRMC directly rather than using a GPS library, so every field
// is visible. RMC layout:
//   $GPRMC,utc,status,lat,N/S,lon,E/W,speed,course,date,...
//   field:  1   2      3   4    5   6
// status 'A' = valid fix, 'V' = warning (no fix). Only 'A' is logged.

#include <SoftwareSerial.h>
#include <SPI.h>
#include <SD.h>

const int  GPS_RX_PIN = 2;    // Arduino receives <- GPS TX
const int  GPS_TX_PIN = 3;    // Arduino transmits -> GPS RX (unused here)
const long GPS_BAUD   = 4800; // EM-506 factory default
const int  SD_CS_PIN  = 8;
const char LOG_FILE[] = "gpslog.csv";

SoftwareSerial gps(GPS_RX_PIN, GPS_TX_PIN);

char    sentence[100];
uint8_t idx = 0;

void setup() {
  Serial.begin(9600);
  gps.begin(GPS_BAUD);

  if (!SD.begin(SD_CS_PIN)) {
    Serial.println(F("SD init failed: card absent, not FAT32, or wrong CS pin"));
    while (true) { }
  }
  if (!SD.exists(LOG_FILE)) {
    File f = SD.open(LOG_FILE, FILE_WRITE);
    if (f) { f.println(F("utc,latitude,longitude")); f.close(); }
  }
  Serial.println(F("waiting for a fix -- this needs open sky"));
}

// Returns a pointer to comma-separated field n (0 = the sentence type).
char *field(char *s, uint8_t n) {
  uint8_t seen = 0;
  if (n == 0) return s;
  for (char *p = s; *p; p++) {
    if (*p == ',') {
      seen++;
      if (seen == n) return p + 1;
    }
  }
  return NULL;
}

void handleSentence(char *s) {
  if (strncmp(s, "$GPRMC", 6) != 0) return;   // only RMC carries the status flag

  char *status = field(s, 2);
  if (!status || *status != 'A') {            // 'V' = no fix yet
    Serial.println(F("...no fix"));
    return;
  }

  char *utc = field(s, 1);
  char *lat = field(s, 3);
  char *ns  = field(s, 4);
  char *lon = field(s, 5);
  char *ew  = field(s, 6);
  if (!utc || !lat || !ns || !lon || !ew) return;

  File f = SD.open(LOG_FILE, FILE_WRITE);
  if (!f) { Serial.println(F("could not open log file")); return; }

  // Fields are still comma-terminated in place; print up to the next comma.
  for (char *p = utc; *p && *p != ','; p++) { f.print(*p); Serial.print(*p); }
  f.print(',');  Serial.print(',');
  for (char *p = lat; *p && *p != ','; p++) { f.print(*p); Serial.print(*p); }
  f.print(*ns);  Serial.print(*ns);
  f.print(',');  Serial.print(',');
  for (char *p = lon; *p && *p != ','; p++) { f.print(*p); Serial.print(*p); }
  f.println(*ew); Serial.println(*ew);

  f.close();     // close == flush, one fix at most lost on a power cut
}

void loop() {
  while (gps.available()) {
    char c = gps.read();
    if (c == '\n') {
      sentence[idx] = '\0';
      handleSentence(sentence);
      idx = 0;
    } else if (c != '\r' && idx < sizeof(sentence) - 1) {
      sentence[idx++] = c;
    }
  }
}
5

Take it outside for the first fix

Put the unit under open sky, powered, and leave it. Watch for the fix indicator before judging the build.

Testing a GPS receiver indoors and concluding it is broken is the single most common failure in this project. A cold start with no stored almanac legitimately takes minutes.

Материал

4

Шаардлагатай багаж

1
Estimated Total
$101.00

CC0 Нийтийн домэйн

Энэ загвар CC0 дор гаргагдсан. Та зөвшөөрөл авахгүйгээр хуулах, өөрчлөх, түгээх, ашиглах боломжтой.

Загвараар дамжуулан бүтээгдэхүүн худалдаж авч Бүтээгчийг дэмжээрэй Бүтээгчийн шимтгэл Борлуулагчаар тогтоосон, эсвэл энэ загварын шинэ хувилбар үүсгэж орлогоо хуваахын тулд өөрийн загварт холбоос болгон оруулна уу.

Хэлэлцүүлэг

(0)

Нэвтрэх хэлэлцүүлэгт нэгдэхийн тулд

Loading comments...