GPS data logger that saves location and datetime to SD card every 5 seconds.
- Waveshare ESP32-S3-SIM7670G-4G Board
- GNSS Antenna (connects to GNSS antenna socket)
- SD Card (FAT32, <32GB recommended) - Optional
- USB Cable for programming and power
-
Hardware Setup:
- Connect GNSS antenna to the "GNSS antenna socket"
- Insert SD card (if you want to log to SD)
- Turn ON the 4G DIP switch on the back of the board (CRITICAL!)
- Connect USB cable
-
Upload Code:
- Open project in PlatformIO
- Upload
src/main.cppto board - Open Serial Monitor (115200 baud)
-
Wait for GPS Fix:
- Red LED should be lit (module powered)
- Place board near window or outdoors
- Wait 30-120 seconds for first GPS fix
- Serial monitor will show: "✓✓✓ GPS TIME LOCK ACQUIRED! ✓✓✓"
-
Data Logging:
- Data logs every 5 seconds
- Saves to SD card at
/datalog.txt - Also prints to serial monitor
This project had several challenges. Here's what we learned:
What we thought: GPS is a separate module connected via UART pins.
Reality: The GPS/GNSS is built into the SIM7670G cellular module, not a separate device!
Solution:
- GPS is accessed via AT commands to the SIM7670G module
- Use
AT+CGNSSPWR=1to power on GNSS - Use
AT+CGNSSTST=1to start NMEA output - Then parse the NMEA sentences with TinyGPSPlus library
What we tried: Sending AT commands but got "[No response]"
Root cause: The SIM7670G module wasn't powered on!
Solution:
- Turn ON the 4G DIP switch on the back of the board
- Red LED lights up = module is powered
- This was the critical missing step!
What we tried: Various UART pin combinations (42/41, 16/17, etc.)
Root cause: Wrong UART pin assignment for the SIM7670G module.
Solution:
- Created an automatic pin scanner tool
- Tested all common pin combinations at different baud rates
- Found working configuration: RX=17, TX=18, Baud=115200
What we see: f_mount failed and Select Failed errors
Possible causes:
- Board variant might not have SD card slot
- Wrong pin configuration for SD card
- SD card not formatted (needs FAT32)
- SD card not inserted or defective
- Board uses SD_MMC mode instead of SPI
Solutions to try:
- Code now tries multiple initialization methods
- Tries different SPI frequencies
- Falls back to serial-only logging if SD fails
- See "SD Card Configuration" section below
// SIM7670G Module UART
#define SIM7670_RX_PIN 17 // ESP32 RX <- SIM7670 TX
#define SIM7670_TX_PIN 18 // ESP32 TX -> SIM7670 RX
#define SIM7670_BAUD 115200 // Baud rate
// SD Card (if using SPI mode)
#define SD_CS 10
#define SD_MOSI 11
#define SD_MISO 13
#define SD_SCK 12Some Waveshare board variants use different pins:
// Alternative SPI pins:
#define SD_CS 5
#define SD_MOSI 35
#define SD_MISO 37
#define SD_SCK 36Or your board might use SD_MMC mode (uncomment in code if needed).
If SD card isn't working:
-
Check if your board has an SD slot
- Some SIM7670G board variants don't include SD card slots
- Code will fall back to serial-only logging
-
Try a different SD card
- Use FAT32 format
- 32GB or smaller recommended
- Some cards are incompatible with ESP32
-
Format the card
Format as FAT32 (not exFAT or NTFS) Allocation unit size: Default -
Check SD card pins in code
- Adjust pin definitions if your board uses different pins
- Try the alternative pin sets provided in comments
-
Monitor initialization
- Code tries 3 different initialization methods
- Watch serial monitor to see which method works
=================================
SIM7670G GNSS Initialization
=================================
Testing AT communication...
>> AT
AT
OK ← Module is responding!
Getting module information...
>> ATI
Manufacturer: SIMCOM INCORPORATED
Model: SIM7670G-MNGV ← Your module model
Revision: V1.9.05
IMEI: 864643060214048
Enabling GNSS power...
>> AT+CGNSSPWR=1
OK ← GNSS powered on
Starting GNSS session...
>> AT+CGNSSTST=1
OK ← NMEA sentences will start
[NMEA sentences appear here]
$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47
$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A
✓✓✓ GPS TIME LOCK ACQUIRED! ✓✓✓ ← Got satellite fix!
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
DateTime: 2025-12-23 18:45:32 | Sats: 8 | Lat: 37.774929, Lon: -122.419418, Alt: 52.1m
📝 2025-12-23 18:45:32 | Lat: 37.774929 | Lon: -122.419418 | Alt: 52.10m | Sats: 8 | Speed: 0.00 km/h | Status: OK
✓ Saved to SD card: /datalog.txt
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
The /datalog.txt file on SD card contains:
2025-12-23 18:45:32 | Lat: 37.774929 | Lon: -122.419418 | Alt: 52.10m | Sats: 8 | Speed: 0.00 km/h | Status: OK
2025-12-23 18:45:37 | Lat: 37.774930 | Lon: -122.419420 | Alt: 52.15m | Sats: 9 | Speed: 0.05 km/h | Status: OK
2025-12-23 18:45:42 | Lat: 37.774931 | Lon: -122.419422 | Alt: 52.20m | Sats: 9 | Speed: 0.10 km/h | Status: OK
Each line contains:
- DateTime: UTC time from GPS (accurate to the second)
- Lat/Lon: Location in decimal degrees (6 decimal places = ~0.1m accuracy)
- Alt: Altitude in meters above sea level
- Sats: Number of satellites used (more = better accuracy)
- Speed: Ground speed in km/h
- Status: Custom status field (add your own sensor data here)
Edit this line to change from 5 seconds to another value:
const unsigned long saveInterval = 5000; // milliseconds (5000 = 5 seconds)In the saveDataToSD() function, add your sensor readings:
// Add your custom sensor data here
dataLine += "Temp: " + String(temperature) + "C | ";
dataLine += "Humidity: " + String(humidity) + "% | ";
dataLine += "Pressure: " + String(pressure) + " hPa | ";Once GPS is working, you can comment out the debug output:
// In processGNSSData() function:
// Serial.print(c); // Comment this line to reduce outputconst char* dataFileName = "/mydata.txt"; // Change filename-
Module Power is Critical
- The 4G DIP switch MUST be ON
- Red LED indicates module power
- Without this, nothing will work!
-
GNSS is Built-In
- Not a separate module
- Controlled via AT commands
- Shares UART with cellular functions
-
Pin Discovery is Important
- Don't assume pins from other boards
- Create a pin scanner when unsure
- Document working pins for future
-
GPS Needs Time
- Cold start: 30-120 seconds
- Warm start: 5-30 seconds
- Needs clear sky view
- Won't work indoors
-
SD Card Compatibility Varies
- Different board variants have different configs
- Some boards don't have SD slots
- Serial-only logging is a good fallback
- TinyGPSPlus: NMEA sentence parsing
- SD (ESP32 built-in): SD card file operations
- FS (ESP32 built-in): File system operations
Useful SIM7670G AT commands for GNSS:
AT+CGNSSPWR=1 → Power on GNSS (0=off, 1=on)
AT+CGNSSPWR? → Check GNSS power status
AT+CGNSSMODE=1 → Set constellation mode (1=GPS+GLONASS+Beidou+Galileo)
AT+CGNSSTST=1 → Start NMEA output (0=stop, 1=start)
AT+CGNSSINFO → Get current GNSS information
AT+CGNSSHOT → Get single location fix
Free to use and modify for any purpose.
Developed through iterative troubleshooting and problem-solving with the Waveshare ESP32-S3-SIM7670G-4G board.