Connect an SPI SD Card to Your Arduino - connection and coding

  Рет қаралды 9,837

Bytes N Bits

3 жыл бұрын

Arduino's don't have enough inbuilt storage to save large amounts of data. If you need to record sensor readings, experimental data, or access image files for use on an LCD screen you'll need to attach an SD card.
It sounds complex to connect it and then handle the file system, but the Arduino IDE with its built in libraries makes it very simple.
In this video I'll show you how to connect your SPI SD card reader, format your card and then create, read and update files and folders.
Make sure you check out the project pages on my website...
bytesnbits.co.uk/arduino-sd-card-setup

Пікірлер: 22
@distortion_tech_lab
@distortion_tech_lab Ай бұрын
Darn. Should have watched this video before I ordered my level shifters 🤣 this works how I expected mine to work.
@BytesNBits
@BytesNBits Ай бұрын
These ones are really good and very easy to get working in both directions.
@donaldkormos5529
@donaldkormos5529 5 ай бұрын
Thanks for video!! Order couple SD modules and try experimenting soon. Cheers ...
@BytesNBits
@BytesNBits 5 ай бұрын
Have fun!
@umutkayacan7659
@umutkayacan7659 3 жыл бұрын
Nice video!
@BytesNBits
@BytesNBits 3 жыл бұрын
Thanks!
@boacmihnea5463
@boacmihnea5463 6 ай бұрын
Hello, thank you for the tutorial. I have the following questions: is there a limit on the capacity of the SD card? I'm asking because I'm having trouble using a 16 Gb SD card. Can't find anywhere the specs of the SD part of this hardware. Thank you.
@BytesNBits
@BytesNBits 6 ай бұрын
FAT32 should be fine up to 32GB but as you mention the board itself might be limiting you. Individual files should be less than 4GB if you're hitting issues with large files.
@boacmihnea5463
@boacmihnea5463 6 ай бұрын
Thank you! 👍
@cansatmessi2.0
@cansatmessi2.0 Жыл бұрын
hi, do you know how can i connect two arduinos to the same sd card without having problems with the MOSI pin?
@BytesNBits
@BytesNBits Жыл бұрын
Hi. You need to isolate the output pins from each Arduino when it's not driving the SPI bus. Have a look at tri state buffers which will let you disconnect from the sd card, or have a play with setting the Arduino pins to their weak pull up state when not in use - not sure how this will affect the spi library code.
@waynehawkins654
@waynehawkins654 8 ай бұрын
Excellent. Thank you for the video, well explained. Question? If I was storing a large amount of data, say a data logger (Date\Time and Sample). EG 2023-10-28T23:00:00 100.1 And this was 1000s of sample values. How can I loop each line fast and read that line based on a index or line number on the file. That is not read the whole file and then loop, but somehow read a line directed on the SD card and return only that line. This way I don't have to store something that could be 4GB in size. EG - read line 10,009 and get what this line is?
@BytesNBits
@BytesNBits 8 ай бұрын
I guess there are a couple of routes. I have seen some SD card libraries that seem to allow random access to files. Have a look at mySD - github.com/nhatuan84/esp32-micro-sdcard/tree/master The other option is to break the data stream up into manageable chunks e.g. 100 samples per file and then save these with numeric file names, e.g. 1.txt, 2.txt. You'll then be able to pick out a block of 100 samples by filename. You might have to be careful about the number of files allowed in any folder, especially when you get to many thousands. You'd then need to use folders. e.g. folder 0000 contains data files 0-999, folder 0001 files 1000-1999, etc. You can then have 1000 folders of 1000 files. Hope this helps.
@waynehawkins654
@waynehawkins654 8 ай бұрын
@@BytesNBits Thank you for this. Will look into the mySD option. But a good idea to do lots of files, seen this before and explains why people have done things this way.
@BytesNBits
@BytesNBits 8 ай бұрын
@@waynehawkins654 No problem. Hope you get it working 😃
@e-twinningproject4693
@e-twinningproject4693 Жыл бұрын
hi sir, how can i display movie using tft 2.8
@BytesNBits
@BytesNBits Жыл бұрын
Hi. With an arduino you're not going to be able. It hasn't the processing power or memory to do it. Most microcontrollers (Pi Pico, ESP32, etc) would really struggle with this task and give only a couple of frames per second (if that!).
@oussimakh2330
@oussimakh2330 2 жыл бұрын
Hello how are you , I am trying to make a project with arduino Leonardo and 3.5 TFT LCD the project i want make it as timer controller of cocking food can you help me please
@BytesNBits
@BytesNBits 2 жыл бұрын
The Leonardo should work very much the same as the Uno in the video. You just need to make sure you connect to the right pins and adjust the software setup accordingly.
@josegarcia-sv2sh
@josegarcia-sv2sh 11 ай бұрын
do you have the code for this example? thanks...
@BytesNBits
@BytesNBits 11 ай бұрын
Here's the code from the tutorial. It might be that your compiler is complaining about there being an empty function in the loop function. Try adding something in there. #include "SPI.h" #include "SD.h" #define SD_CLK 13 #define SD_MISO 12 #define SD_MOSI 11 #define SD_CS 6 void setup() { Serial.begin(115200); // avoid chip select contention pinMode(SD_CS, OUTPUT); digitalWrite(SD_CS, HIGH); if (!SD.begin(SD_CS)) { Serial.println("SD Card initialization failed!"); while(true){ ; } } else { Serial.println("SD Card OK!"); } // check if directory / folder exists and create if (!SD.exists("/data")){ SD.mkdir("/data"); } // create folder for next data run int folderCounter = 1; String baseFolder = "/data/run"; while(SD.exists(baseFolder + folderCounter)){ folderCounter ++; } String runFolder = baseFolder + folderCounter; Serial.println("Folder for this run = " + runFolder); SD.mkdir(runFolder); runFolder = runFolder + "/"; // check if file exists and delete if (SD.exists(runFolder + "my_file.txt")){ SD.remove(runFolder + "my_file.txt"); } // create new file File myFile = SD.open(runFolder + "my_file.txt", FILE_WRITE); Serial.println("Created new file"); // put some text in the file myFile.print("This was created on run "); myFile.println(folderCounter); Serial.print("First line of text added to file on run"); Serial.println(folderCounter); // close file myFile.close(); // open file for reading myFile = SD.open(runFolder + "my_file.txt", FILE_READ); // output file contents to serial monitor char nextChar; byte nextByte; while(myFile.available()){ nextChar = myFile.read(); Serial.write(nextChar); } // close file myFile.close(); } void loop() { }
@josegarcia-sv2sh
@josegarcia-sv2sh 11 ай бұрын
I copied that code on video and I got some erros: C:\Users\pc\AppData\Local\Temp\cc6WS8wb.ltrans0.ltrans.o: In function `main': C:\Users\pc\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/main.cpp:46: undefined reference to `loop' collect2.exe: error: ld returned 1 exit status Se encontraron varias bibliotecas para "SD.h" Usado: C:\Users\pc\Documents\Arduino\libraries\SD No utilizado: C:\Users\pc\AppData\Local\Arduino15\libraries\SD exit status 1 Compilation error: exit status 1
MEU IRMÃO FICOU FAMOSO
00:52
Matheus Kriwat
Рет қаралды 45 МЛН
THEY WANTED TO TAKE ALL HIS GOODIES 🍫🥤🍟😂
00:17
OKUNJATA
Рет қаралды 17 МЛН
MEGA BOXES ARE BACK!!!
08:53
Brawl Stars
Рет қаралды 35 МЛН
MEU IRMÃO FICOU FAMOSO
00:52
Matheus Kriwat
Рет қаралды 45 МЛН