Skip to content

mhviola/drifter-tracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Waveshare ESP32-S3-SIM7670G GNSS Data Logger

GPS data logger that saves location and datetime to SD card every 5 seconds.

Hardware Required

  • 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

Quick Start

  1. 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
  2. Upload Code:

    • Open project in PlatformIO
    • Upload src/main.cpp to board
    • Open Serial Monitor (115200 baud)
  3. 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! ✓✓✓"
  4. Data Logging:

    • Data logs every 5 seconds
    • Saves to SD card at /datalog.txt
    • Also prints to serial monitor

Troubleshooting Journey (For Future Reference)

This project had several challenges. Here's what we learned:

Problem 1: No GPS Data Initially

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=1 to power on GNSS
  • Use AT+CGNSSTST=1 to start NMEA output
  • Then parse the NMEA sentences with TinyGPSPlus library

Problem 2: No Response from Module

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!

Problem 3: Still No Response After Power On

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

Problem 4: SD Card Won't Initialize

What we see: f_mount failed and Select Failed errors

Possible causes:

  1. Board variant might not have SD card slot
  2. Wrong pin configuration for SD card
  3. SD card not formatted (needs FAT32)
  4. SD card not inserted or defective
  5. 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

Hardware Configuration

Verified Working Configuration

// 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 12

Alternative SD Card Pins (if defaults don't work)

Some Waveshare board variants use different pins:

// Alternative SPI pins:
#define SD_CS 5
#define SD_MOSI 35
#define SD_MISO 37
#define SD_SCK 36

Or your board might use SD_MMC mode (uncomment in code if needed).

SD Card Troubleshooting

If SD card isn't working:

  1. 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
  2. Try a different SD card

    • Use FAT32 format
    • 32GB or smaller recommended
    • Some cards are incompatible with ESP32
  3. Format the card

    Format as FAT32 (not exFAT or NTFS)
    Allocation unit size: Default
    
  4. Check SD card pins in code

    • Adjust pin definitions if your board uses different pins
    • Try the alternative pin sets provided in comments
  5. Monitor initialization

    • Code tries 3 different initialization methods
    • Watch serial monitor to see which method works

Understanding the Output

Serial Monitor Output

=================================
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
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Data File Format

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)

Customization

Change Logging Interval

Edit this line to change from 5 seconds to another value:

const unsigned long saveInterval = 5000; // milliseconds (5000 = 5 seconds)

Add Custom Sensor Data

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 | ";

Reduce Serial Output

Once GPS is working, you can comment out the debug output:

// In processGNSSData() function:
// Serial.print(c);  // Comment this line to reduce output

Change Filename

const char* dataFileName = "/mydata.txt";  // Change filename

Key Learnings

  1. Module Power is Critical

    • The 4G DIP switch MUST be ON
    • Red LED indicates module power
    • Without this, nothing will work!
  2. GNSS is Built-In

    • Not a separate module
    • Controlled via AT commands
    • Shares UART with cellular functions
  3. Pin Discovery is Important

    • Don't assume pins from other boards
    • Create a pin scanner when unsure
    • Document working pins for future
  4. GPS Needs Time

    • Cold start: 30-120 seconds
    • Warm start: 5-30 seconds
    • Needs clear sky view
    • Won't work indoors
  5. SD Card Compatibility Varies

    • Different board variants have different configs
    • Some boards don't have SD slots
    • Serial-only logging is a good fallback

Libraries Used

  • TinyGPSPlus: NMEA sentence parsing
  • SD (ESP32 built-in): SD card file operations
  • FS (ESP32 built-in): File system operations

AT Commands Reference

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

License

Free to use and modify for any purpose.

Credits

Developed through iterative troubleshooting and problem-solving with the Waveshare ESP32-S3-SIM7670G-4G board.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published