Arduino SD.begin()
Description
The SD.begin() function initializes the SD library and SD card. It initializes the SPI bus, which is used for communication between Arduino and SD card. For SPI interface, the SS (slave select) pin is default to the hardware SS pin (pin 10 on most Arduino boards, 53 on the Mega)
Syntax
SD.begin()
SD.begin(ss_pin)
Parameters
- ss_pin: (optional) the pin connected to the slave select pin of the SD card. If not set, the hardware SS pin is used.
※ NOTES AND WARNINGS:
Even if you use a different SS pin from the default, the hardware SS pin must be kept as an output or the SD library functions will not work.
Returns
- true on success
- false on failure
Example Code
/*
* Created by ArduinoGetStarted.com
*
* This example code is in the public domain
*
* Tutorial page: https://arduinogetstarted.com/reference/library/arduino-sd.begin
*/
#include <SD.h>
#define PIN_SPI_CS 4
File file;
void setup() {
Serial.begin(9600);
if (!SD.begin(PIN_SPI_CS)) {
Serial.println("SD CARD FAILED, OR NOT PRESENT!");
while (1); // don't do anything more:
}
Serial.println("SD CARD INITIALIZED.");
}
void loop() {
}
Tutorials
See Also
※ ARDUINO BUY RECOMMENDATION
Arduino UNO R3 | |
Arduino Starter Kit |
Disclosure: Some links in this section are Amazon affiliate links. If you make a purchase through these links, we may earn a commission at no extra cost to you.
Additionally, some links direct to products from our own brand, DIYables .
Additionally, some links direct to products from our own brand, DIYables .