SD card not logging

Hi,

for the last few hours, I tried to log data to the IMU. however, the firmware code that was on the sparkfun website didn’t log the data on to the SD card. Then wrote the following code to just log some data, which didn’t work either.

#include <SparkFunMPU9250-DMP.h>

// SD Library manages file and hardware control

#include <SD.h>

// config.h manages default logging parameters and can be used

// to adjust specific parameters of the IMU

#include “config.h”

// Flash storage (for nv storage on ATSAMD21)

#ifdef ENABLE_NVRAM_STORAGE

#include <FlashStorage.h>

#include <SPI.h>

#endif

void setup() {

// Open serial communications and wait for port to open:

LOG_PORT.begin(9600);

//Serial.begin(9600);

while (!LOG_PORT) {

; // wait for serial port to connect. Needed for native USB port only

}

}

void loop() {

LOG_PORT.println(“Initializing SD card…”);

// see if the card is present and can be initialized:

if(SD.begin(38))

{

LOG_PORT.println(“mission passed boss”);

delay(2000);

}

while (!SD.begin(38))

{

LOG_PORT.println(“Card failed, or not present”);

}

if(SD.begin(38))

{

LOG_PORT.println(“mission passed boss”);

delay(2000);

}

LOG_PORT.println(“kkkkkkk”);

// make a string for assembling the data to log:

String dataString = “kkkk”;

// open the file. note that only one file can be open at a time,

// so you have to close this one before opening another.

File dataFile = SD.open(“datalog.txt”, FILE_WRITE);

// if the file is available, write to it:

if (dataFile) {

dataFile.println(dataString);

dataFile.close();

// print to the serial port too:

LOG_PORT.println(dataString);

}

// if the file isn’t open, pop up an error:

else {

LOG_PORT.println(“error opening datalog.txt”);

}

}

Hello.

What product are you having trouble with? Is it the Razor M0?

You need to enable logging to SD in the menu on the Razor M0, it doesn’t automatically log out of the box.

Try putting the original firmware back on, then go into the menu and enable logging and see if that gets you going.

Details can be found in the [hookup guide on how to access the menu.

Also, make sure your SD card is 32 gigs or less in size and formatted FAT32. Larger cards and other filesystems won’t work with the Razor.](https://learn.sparkfun.com/tutorials/9dof-razor-imu-m0-hookup-guide#getting-started-with-the-example-firmware)