I am doing a project which will involve data logging. I feel I am setting up the connections correctly, but I still receive an initializing error when doing the CardInfo sketch. I have also made sure to format my SD card so I know that is not the issue.
I have quadruple checked the wiring from the sd module to the nano and I am stumped. I have tried Pin 10, Pin 4, and pin 8 for the CS connection with no luck. Yes, I make sure to change the CS in the program itself to the corresponding Pin as well when I tried the other Pins.
I have attached images of my pinouts
and here is my code:
#include <SPI.h>
#include <SD.h>
// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;
// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
// MKRZero SD: SDCARD_SS_PIN
const int chipSelect = 10;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("\nInitializing SD card...");
// we'll use the initialization code from the utility libraries
// since we're just testing if the card is working!
if (!card.init(SPI_HALF_SPEED, chipSelect)) {
Serial.println("initialization failed. Things to check:");
Serial.println("* is a card inserted?");
Serial.println("* is your wiring correct?");
Serial.println("* did you change the chipSelect pin to match your shield or module?");
while (1);
} else {
Serial.println("Wiring is correct and a card is present.");
}
// print the type of card
Serial.println();
Serial.print("Card type: ");
switch (card.type()) {
case SD_CARD_TYPE_SD1:
Serial.println("SD1");
break;
case SD_CARD_TYPE_SD2:
Serial.println("SD2");
break;
case SD_CARD_TYPE_SDHC:
Serial.println("SDHC");
break;
default:
Serial.println("Unknown");
}
// Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
if (!volume.init(card)) {
Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
while (1);
}
Serial.print("Clusters: ");
Serial.println(volume.clusterCount());
Serial.print("Blocks x Cluster: ");
Serial.println(volume.blocksPerCluster());
Serial.print("Total Blocks: ");
Serial.println(volume.blocksPerCluster() * volume.clusterCount());
Serial.println();
// print the type and size of the first FAT-type volume
uint32_t volumesize;
Serial.print("Volume type is: FAT");
Serial.println(volume.fatType(), DEC);
volumesize = volume.blocksPerCluster(); // clusters are collections of blocks
volumesize *= volume.clusterCount(); // we'll have a lot of clusters
volumesize /= 2; // SD card blocks are always 512 bytes (2 blocks are 1KB)
Serial.print("Volume size (Kb): ");
Serial.println(volumesize);
Serial.print("Volume size (Mb): ");
volumesize /= 1024;
Serial.println(volumesize);
Serial.print("Volume size (Gb): ");
Serial.println((float)volumesize / 1024.0);
Serial.println("\nFiles found on the card (name, date and size in bytes): ");
root.openRoot(volume);
// list all files in the card with date and size
root.ls(LS_R | LS_DATE | LS_SIZE);
}
void loop(void) {
}
I appreciate any help and thanks in advance if you take a look at this.
Used the SDfat lib, which gave me a compile error for the Nano it was struct stat error. I will add the code below.
Those are the only things I could really think to try doing.
Once I get a soldering kit or find someone who can help me solder it I will do so.
If anyone has any advice I would greatly appreciate your help and thank you kindly in advance for any who helps!
Arduino: 1.8.13 (Windows Store 1.8.42.0) (Windows 10), Board: "Arduino Nano 33 BLE"
In file included from c:\users\expan\onedrive\documents\arduinodata\packages\arduino\tools\arm- none-eabi-gcc\7-2017q4\arm-none-eabi\include\sys\_default_fcntl.h:200:0,
from c:\users\expan\onedrive\documents\arduinodata\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\sys\fcntl.h:4,
from c:\users\expan\onedrive\documents\arduinodata\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\fcntl.h:1,
from C:\Users\expan\OneDrive\Documents\Arduino\libraries\SdFat-master\src/FatLib/FatApiConstants.h:30,
from C:\Users\expan\OneDrive\Documents\Arduino\libraries\SdFat-master\src/FatLib/FatFile.h:36,
from C:\Users\expan\OneDrive\Documents\Arduino\libraries\SdFat-master\src/FatLib/ArduinoFiles.h:33,
from C:\Users\expan\OneDrive\Documents\Arduino\libraries\SdFat-master\src/FatLib/FatLib.h:27,
from C:\Users\expan\OneDrive\Documents\Arduino\libraries\SdFat-master\src/SdFat.h:33,
from C:\Users\expan\AppData\Local\Temp\arduino_modified_sketch_271835\SdInfo.ino:5:
c:\users\expan\onedrive\documents\arduinodata\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\sys\stat.h:27:8: error: redefinition of 'struct stat'
struct stat
^~~~
In file included from C:\Users\expan\OneDrive\Documents\ArduinoData\packages\arduino\hardware\mbed\1.1.6\cores\arduino/mbed/platform/platform.h:26:0,
from C:\Users\expan\OneDrive\Documents\ArduinoData\packages\arduino\hardware\mbed\1.1.6\cores\arduino/mbed/drivers/InterruptIn.h:20,
from C:\Users\expan\OneDrive\Documents\ArduinoData\packages\arduino\hardware\mbed\1.1.6\cores\arduino/Arduino.h:35,
from C:\Users\expan\AppData\Local\Temp\arduino_build_412993\sketch\SdInfo.ino.cpp:1:
C:\Users\expan\OneDrive\Documents\ArduinoData\packages\arduino\hardware\mbed\1.1.6\cores\arduino/mbed/platform/mbed_retarget.h:501:8: note: previous definition of 'struct stat'
struct stat {
^~~~
Using library SPI in folder: C:\Users\expan\OneDrive\Documents\ArduinoData\packages\arduino\hardware\mbed\1.1.6\libraries\SPI (legacy)
Using library SdFat-master at version 1.1.4 in folder: C:\Users\expan\OneDrive\Documents\Arduino\libraries\SdFat-master
exit status 1
Error compiling for board Arduino Nano 33 BLE.