Alla vill ha ett bra verktytg vid portabekörande som berättar Locator, dvs maidenhead, UTC gps kordinater
ganska enkelt
en oled display
ESP8266 D1 mini
Gps och gps antenn
koppla ihop
GPS TX D6 (GPIO12)
GPS RX D7 (GPIO13)
GPS VCC 3.3V
GPS GND GND
OLED SDA D2 (GPIO4)
OLED SCL D1 (GPIO5)
OLED VCC 3.3V
OLED GND GND
Kod arduino cc
#include <TinyGPSPlus.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// ========== PINNAR ==========
#define GPS_RX 12 // D6
#define GPS_TX 13 // D7
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C
// ========== OBJEKT ==========
TinyGPSPlus gps;
SoftwareSerial ss(GPS_RX, GPS_TX);
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// ========== MAIDENHEAD FUNKTION (6 tecken) ==========
String getMaidenhead(double lat, double lon) {
char locator[7];
lon += 180.0;
lat += 90.0;
// Field (A-R)
locator[0] = 'A' + int(lon / 20.0);
locator[1] = 'A' + int(lat / 10.0);
// Square (0-9)
locator[2] = '0' + int(fmod(lon, 20.0) / 2.0);
locator[3] = '0' + int(fmod(lat, 10.0));
// Subsquare (a-x)
locator[4] = 'a' + int(fmod(lon, 2.0) * 12.0);
locator[5] = 'a' + int(fmod(lat, 1.0) * 24.0);
locator[6] = '\0';
return String(locator);
}
void setup() {
Serial.begin(115200);
ss.begin(9600);
// OLED init
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("OLED misslyckades"));
for (;;);
}
display.clearDisplay();
display.setTextColor(SSD1306_WHITE);
display.setTextSize(1);
display.setCursor(0, 0);
display.println("GPS + Maidenhead");
display.println("Vantar pa fix...");
display.display();
}
void loop() {
// Läs GPS-data
while (ss.available() > 0) {
if (gps.encode(ss.read())) {
updateDisplay();
}
}
// Varning om ingen GPS efter 5 sekunder
if (millis() > 5000 && gps.charsProcessed() < 10) {
display.clearDisplay();
display.setCursor(0, 20);
display.println("Ingen GPS!");
display.println("Kolla kablage");
display.display();
delay(2000);
}
}
void updateDisplay() {
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0, 0);
if (gps.location.isValid()) {
// ===== MAIDENHEAD (stort) =====
String mh = getMaidenhead(gps.location.lat(), gps.location.lng());
display.setTextSize(2);
display.setCursor(20, 0);
display.println(mh);
// ===== Extra info =====
display.setTextSize(1);
display.setCursor(0, 22);
display.print("Lat: ");
display.println(gps.location.lat(), 5);
display.print("Lon: ");
display.println(gps.location.lng(), 5);
display.print("Sats: ");
display.print(gps.satellites.value());
display.print(" Alt: ");
display.print(gps.altitude.meters(), 0);
display.println("m");
// UTC-tid
if (gps.time.isValid()) {
display.print("UTC: ");
if (gps.time.hour() < 10) display.print("0");
display.print(gps.time.hour());
display.print(":");
if (gps.time.minute() < 10) display.print("0");
display.print(gps.time.minute());
display.print(":");
if (gps.time.second() < 10) display.print("0");
display.print(gps.time.second());
}
}
else {
display.setCursor(0, 20);
display.println("Soker satelliter...");
display.print("Sats: ");
display.println(gps.satellites.value());
}
display.display();
}




















