Arduino sd card initialization failed

#include <Arduino_HTS221.h>
#include <Arduino_LPS22HB.h>
#include <Arduino_LSM9DS1.h>
#include <Wire.h>
#include <SD.h>
#include <SPI.h>


File dataFile;

float temperatureOffset = -30;
const int chipSelect = 4;


void setup() {
  Serial.begin(9600);
  while (!Serial) 


  if (!HTS.begin()) {
    Serial.println("온도 센서 초기화 실패");
    while (1);
  }


  if (!BARO.begin()) {
    Serial.println("대기압 센서 초기화 실패");
    while (1);
  }


  if (!SD.begin(chipSelect)) {
    Serial.println("SD 카드 초기화 실패");
    while (1);
  }

  if (!IMU.begin()) {
    Serial.println("IMU(가속도) 초기화 실패");
    while (1);
  }

  Serial.print("Accelerometer sample rate = ");
  Serial.print(IMU.accelerationSampleRate());
  Serial.println(" Hz");
  Serial.println();
  Serial.println("Acceleration in g's");
  Serial.println("X\tY\tZ");
}


void loop() {
  float temperature = HTS.readTemperature();
  float pressure = BARO.readPressure();
  float x, y, z;

  if (IMU.accelerationAvailable()) {
    IMU.readAcceleration(x, y, z);

    Serial.print(x);
    Serial.print('\t');
    Serial.print(y);
    Serial.print('\t');
    Serial.println(z);
  }

  // print the sensor value
  Serial.print("대기압 = ");
  Serial.print(pressure * 10);
  Serial.println(" hPa");


  // print each of the sensor values
  Serial.print("온도 = ");
  Serial.print(temperature + temperatureOffset);
  Serial.println(" °C");


  // print an empty line
  Serial.println();


  saveDataToSD(pressure, temperature, x, y, z);


  // wait 1 second to print again
  delay(1000);
}


void saveDataToSD(float temperature, float pressure, float x, float y, float z) {
  File dataFile = SD.open("data.csv", FILE_WRITE);


  if (dataFile) {
    // 온도 데이터를 A 열에 추가
    dataFile.print(temperature + temperatureOffset);
    dataFile.print(' °C');
    dataFile.print(",");


    // 압력 데이터를 B 열에 추가
    dataFile.print(pressure * 10);
    dataFile.print(' hPa');
    dataFile.print(",");

    // 가속도 x, y, z C, D, E 열에 추가
    dataFile.print(x);
    dataFile.print(",");
    dataFile.print(y);
    dataFile.print(",");
    dataFile.print(z);


    // 파일 닫기
    dataFile.close();


    Serial.println("데이터 저장 완료");
  } else {
    Serial.println("파일 열기 실패");
  }
}

I want to store data measured by the built-in sensor of the Arduino Nano 33 BLE SENSE on a sd card. However, the initialization of the sd card keeps failing.

< Hardware >

MOSI: 11 pins, MISO: 12 pins, SCK: 13 pins, CS: 4 pins, 5V: 5V, GND: GND

If you are powering the SD card adapter from the 5V pin on the Arduino have you shorted the pads that connect the pin to 5V on the board ?

Used a breadboard when connecting 5V pins. Are you asking this?

No. The 5V pin on the Nano 33 IoT only outputs voltage if you have shorted the two pads adjacent to it on the reverse of the board

Are you powering the SD card from that pin or a wire connected to it and, if so, have you shorted the 2 pads ?

Hi seoho07,

maybe this could be of some help:

https://forum.arduino.cc/t/sdcard-wiring-schemas-arduino-uno-arduino-uno-wifi-arduino-nano-33-iot/685091

as it has been for other mates here in the past

BR

Andrea

Hello,

I’m having similar issue. I’m using the sd card library with the same baro pressure sensor library. What’s interesting to me is both writing to sd card and reading pressure sensor work when I test them separately but when I tried to do those in one file, it’s either the initialization of pressure sensor failed or sd card failed. If you solved the problem, how did you do that? Any helps are appreciated!

hello!

I’m having a similar problem, should I not shorten the 2 gold pads behind it? But if I don’t do so, when I simply test reading and writing to sd card, it’s not working