MicroMod Data Logging Carrier Board Hookup Guide

Pages
Contributors: El Duderino, Nate
Favorited Favorite 0

Arduino Examples

Note: This example assumes you are using the latest version of the Arduino IDE on your desktop. If this is your first time using Arduino, please review our tutorial on installing the Arduino IDE. If you have not previously installed an Arduino library, please check out our installation guide.

GPS Demo Circuit Example

We've written a quick example for the demo circuit from the Hardware Assembly section using the SparkFun GPS Breakout - ZEO-M8Q (Qwiic) to showcase how to log data from the GPS module to a µSD card. To assemble the circuit, simply plug in your GPS module to the Data Logging Carrier Board via a Qwiic cable and attach the GPS Antenna to the board using a u.Fl to SMA Adapter. If you've never worked with u.Fl connectors before this tutorial offers a few quick tips for using them. Also, the SparkFun u-blox Arduino library works with all of our u-blox modules so you can swap in a different u-blox GPS if you prefer.

In order to run this example you will need to have the SparkFun U-blox Arduino library installed. You can install it with the Arduino Library Manager by searching 'SparkFun u-blox GNSS' or you can download the zip here from the GitHub repository:

Copy the code below into a blank Arduino sketch, select your Processor Board (for the demo circuit we select, "SparkFun Artemis MicroMod") and the Port your board has enumerated on. If you are not using the MicroMod Artemis Processor, you'll need to adjust the define for Chip Select:

language:c
/*
  MicroMod Data Logging Carrier Board - ZOE-M8Q GPS Example
  This example code is in the public domain.
*/

#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include <SparkFun_u-blox_GNSS_Arduino_Library.h>

const int chipSelect = 23; // The CS pin is DATA3 or 23 for the MicroMod Artemis Processor. Adjust for your processor if necessary.
SFE_UBLOX_GNSS myGNSS;

long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module.
File myFile;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  Wire.begin();
  if (myGNSS.begin() == false) //Connect to the Ublox module using Wire port
  {
    Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
    while (1);
  }

  myGNSS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
  myGNSS.saveConfiguration(); //Save the current settings to flash and BBR

  Serial.print("Initializing SD card...");

  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    while (1);
  }
  Serial.println("card initialized.");

  myFile = SD.open("data.txt", FILE_WRITE); // Create or open a file called "data.txt" on the SD card
  if(myFile) 
  {
    if(myFile.size() == 0)  // Only create the header if there isn't any data in the file yet
    {
      myFile.println("Date\t\tTime\t\tLatitude\tLongitude\tAlt");
      myFile.println("MM/DD/YYYY\tHH/MM/SS\tdeg\t\tdeg\t\tmm");
      myFile.println("-------------------------------------------------------------------------------------");
    }
    myFile.close(); // Close the file to properly save the data
  }
  else {
    // if the file didn't open, print an error:
    Serial.println("error opening data.txt");
  }

}

void loop() 
{
  char gpsDate[10], gpsTime[10];
  //Query module only every 10 seconds. Adjust this value for more/less frequent GPS logs.
  if (millis() - lastTime > 10000)
  {
    lastTime = millis(); //Update the timer
    long latitude = myGNSS.getLatitude();
    long longitude = myGNSS.getLongitude();
    long altitude = myGNSS.getAltitude();
    uint8_t fixType = myGNSS.getFixType();
    if(fixType != 0){
      myFile = SD.open("data.txt", FILE_WRITE); // Open file "data.txt"
      if(myFile)
      {
        // Get date and time
      sprintf(gpsDate,"%d/%d/%d", myGNSS.getMonth(),myGNSS.getDay(),myGNSS.getYear());
      if(myGNSS.getSecond() < 10){
        sprintf(gpsTime,"%d/%d/0%d", myGNSS.getHour(),myGNSS.getMinute(),myGNSS.getSecond());
      }
      else
      {
        sprintf(gpsTime,"%d/%d/0%d", myGNSS.getHour(),myGNSS.getMinute(),myGNSS.getSecond());
      }
      // Save data to SD card
      myFile.print(gpsDate);
      myFile.print('\t');
      myFile.print(gpsTime);
      myFile.print('\t');
      myFile.print(latitude);
      myFile.print('\t');
      myFile.print(longitude);
      myFile.print('\t');
      myFile.println(altitude); 
      }

      Serial.print(gpsDate);
      Serial.print('\t');
      Serial.print(gpsTime);
      Serial.print('\t');
      Serial.print(latitude);
      Serial.print('\t');
      Serial.print(longitude);
      Serial.print('\t');
      Serial.println(altitude);

      myFile.close();

    }
    else  // GPS is looking for satellites, waiting on fix
    {
    uint8_t SIV = myGNSS.getSIV();
    Serial.print("Satellites in view: ");
    Serial.println(SIV);
    }
  } 
}

With the code adjusted, click the Upload button. For debugging, open your serial monitor and set the baud 115200. The code will print out if the SD card or GPS do not initialize properly. If the SD initialization fails, check that the card is inserted and locked and that it is formatted to FAT32. If the GPS initialization fails, check the connection to your GPS board or verify it is at the default I2C address.

If everything initializes properly, the code will open the "data.txt" file and begin logging data once the GPS has a fix and will also print the same data over serial. If the GPS does not have a lock, the code will print out the number of satellites in view over serial.

Power Control Examples

In addition to this GPS example, we've written two example sketches specifically for the Data Logging Carrier Board demonstrating how to control the 3.3V regulators powering the Qwiic connector/G2-3V3 pin and G1-3V3 rail. They can be found in the MicroMod Data Logging Carrier Board GitHub Repo or you can download the Zip of the repository by clicking the button below

Take note both Qwiic and 3V3 peripheral power are controlled via the enable pin on dedicated voltage regulators. An external pull-up turns both regulators on by default but can be controlled with standard logic. Power ON = HIGH and Power OFF = LOW.