Hello,
I have the MicroSD Breakout with Level Shifter (MicroSD Breakout With Level Shifter Hookup Guide - SparkFun Learn) and Arduino UNO Wifi Rev 2 with me.
I was trying to code the SD module with the following code but doesn't seem to recognize my SD card module (SD card is installed).
Code is:
// Include the following libraries (C++ language code)
#include <SD.h> // Needed for the SD module
#include <Wire.h> // Needed for I2C to GNSS (Activcate any wires connected to the Arduino
#include <SparkFun_u-blox_GNSS_Arduino_Library.h> // Library can be found here: http://librarymanager/All#SparkFun_u-blox_GNSS
SFE_UBLOX_GNSS myGNSS; // Assigning SFE_UBLOX_GNSS variable from SD library to myGNSS (avoid any overrides)
#define PIN_SPI_CS 4 // Read and write pin is assigned on pin 4
long lastTime = 0; // Simple local timer. Limits amount if I2C traffic to u-blox module.
File myFile; // Assigning File variable from SD library to myFile (avoid any overrides)
// Set up
void setup()
{
Serial.begin(57600);
while (!Serial)
; //Wait for user to open terminal
if (!SD.begin(PIN_SPI_CS))
{
Serial.println(F("SD CARD FAILED, OR NOT PRESENT!"));
while (1); // don't do anything more:
}
Serial.println(F("SD CARD INITIALIZED."));
Wire.begin();
if (myGNSS.begin(Wire) == false) //Connect to the u-blox module using Wire port
{
Serial.println(F("Please check wiring. Freezing."));
while (1);
}
myGNSS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
myGNSS.setNavigationFrequency(20); //Set output to 20 times a second
}
// Gathering data
void loop()
{
// Query module only every minute. Doing it more often will just cause I2C traffic.
if (millis() - lastTime > 60000)
{
lastTime = millis(); //Update the timer
File dataFile = SD.open("zedf9p.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
///////////////////
// Print date and time in the Serial Monitor
Serial.print(myGNSS.getYear());
Serial.print(F("-"));
Serial.print(myGNSS.getMonth());
Serial.print(F("-"));
Serial.print(myGNSS.getDay());
Serial.print(F(","));
Serial.print(myGNSS.getHour());
Serial.print(F(":"));
Serial.print(myGNSS.getMinute());
Serial.print(F(":"));
Serial.print(myGNSS.getSecond());
Serial.print(F(","));
// Print date and time in the SD card
dataFile.print(myGNSS.getYear());
dataFile.print(F("-"));
dataFile.print(myGNSS.getMonth());
dataFile.print(F("-"));
dataFile.print(myGNSS.getDay());
dataFile.print(F(","));
dataFile.print(myGNSS.getHour());
dataFile.print(F(":"));
dataFile.print(myGNSS.getMinute());
dataFile.print(F(":"));
dataFile.print(myGNSS.getSecond());
dataFile.print(F(","));
///////////////////
// Collect the position data
int32_t latitude = myGNSS.getHighResLatitude();
int8_t latitudeHp = myGNSS.getHighResLatitudeHp();
int32_t longitude = myGNSS.getHighResLongitude();
int8_t longitudeHp = myGNSS.getHighResLongitudeHp();
uint32_t accuracy = myGNSS.getHorizontalAccuracy();
// Defines storage for the lat and lon units integer and fractional parts
int32_t lat_int; // Integer part of the latitude in degrees
int32_t lat_frac; // Fractional part of the latitude
int32_t lon_int; // Integer part of the longitude in degrees
int32_t lon_frac; // Fractional part of the longitude
// Calculate the latitude and longitude integer and fractional parts
lat_int = latitude / 10000000; // Convert latitude from degrees * 10^-7 to Degrees
lat_frac = latitude - (lat_int * 10000000); // Calculate the fractional part of the latitude
lat_frac = (lat_frac * 100) + latitudeHp; // Now add the high resolution component
if (lat_frac < 0) // If the fractional part is negative, remove the minus sign
{
lat_frac = 0 - lat_frac;
}
lon_int = longitude / 10000000; // Convert latitude from degrees * 10^-7 to Degrees
lon_frac = longitude - (lon_int * 10000000); // Calculate the fractional part of the longitude
lon_frac = (lon_frac * 100) + longitudeHp; // Now add the high resolution component
if (lon_frac < 0) // If the fractional part is negative, remove the minus sign
{
lon_frac = 0 - lon_frac;
}
// Print Lat and Long data in the Serial Monitor
Serial.print(lat_int); // Print the integer part of the latitude
Serial.print(".");
printFractional(lat_frac, 9); // Print the fractional part of the latitude with leading zeros
Serial.print(",");
Serial.print(lon_int); // Print the integer part of the latitude
Serial.print(".");
printFractional(lon_frac, 9); // Print the fractional part of the latitude with leading zeros
///////////////////
// Collect accuracy data
float f_accuracy;
// Convert the horizontal accuracy (mm * 10^-1) to a float
f_accuracy = accuracy;
// Now convert to m
f_accuracy = f_accuracy / 10000.0; // Convert from mm * 10^-1 to m
// Print accuracy data in the Serial Monitor
Serial.print(",");
Serial.println(f_accuracy, 4); // Print the accuracy with 4 decimal places
///////////////////
// Collect altitude, altitude (msl) and fix type. Then, print data in the Serial Monitor.
long altitude = myGNSS.getAltitude();
Serial.print(F(" Alt: "));
Serial.print(altitude);
long altitudeMSL = myGNSS.getAltitudeMSL();
Serial.print(F(" AltMSL: "));
Serial.print(altitudeMSL);
Serial.print(F(" (mm)"));
byte fixType = myGNSS.getFixType();
Serial.print(F(" Fix: "));
if(fixType == 0) Serial.print(F("No fix"));
else if(fixType == 1) Serial.print(F("Dead reckoning"));
else if(fixType == 2) Serial.print(F("2D"));
else if(fixType == 3) Serial.print(F("3D"));
else if(fixType == 4) Serial.print(F("GNSS + Dead reckoning"));
else if(fixType == 5) Serial.print(F("Time only"));
Serial.println();
///////////////////
// Print position, accuracy, altitude, altitude (msl) and fix type in the SD card
dataFile.print(lat_int); // Print the integer part of the latitude
dataFile.print(".");
dataFile.print(lat_frac); // Print the fractional part of the latitude with leading zeros
dataFile.print(",");
dataFile.print(lon_int); // Print the integer part of the latitude
dataFile.print(".");
dataFile.print(lon_frac); // Print the fractional part of the latitude with leading zeros
dataFile.print(",");
dataFile.print(f_accuracy, 4); // Print the accuracy with 4 decimal places
dataFile.print(",");
dataFile.print(altitude); // Print the altitude in mm
dataFile.print(",");
dataFile.print(altitudeMSL); // Print the altitude (msl) in mm
dataFile.print(",");
dataFile.print(fixType); // Print the Fix type (0=No fix, 1=Dead reckoning, 2=2D, 3=3D, 4=GNSS+Dead reckoning, 5=Time only)
dataFile.println("");
dataFile.close();
}
}
}
///////////////////
// Pretty-print the fractional part with leading zeros - without using printf
// (Only works with positive numbers)
void printFractional(int32_t fractional, uint8_t places)
{
if (places > 1)
{
for (uint8_t place = places - 1; place > 0; place--)
{
if (fractional < pow(10, place))
{
Serial.print("0");
}
}
}
Serial.print(fractional);
}
I have the following connections on my unit:

plus the CS pin on Arduino pin 4
Is there any way I can get help with this?
Thank you.

