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

Поделиться
HTML-код
  • Опубликовано: 4 окт 2024

Комментарии • 25

  • @distortion_tech_lab
    @distortion_tech_lab 4 месяца назад

    Darn. Should have watched this video before I ordered my level shifters 🤣 this works how I expected mine to work.

    • @BytesNBits
      @BytesNBits  4 месяца назад +1

      These ones are really good and very easy to get working in both directions.

  • @donaldkormos5529
    @donaldkormos5529 8 месяцев назад

    Thanks for video!! Order couple SD modules and try experimenting soon. Cheers ...

  • @e-twinningproject4693
    @e-twinningproject4693 Год назад +1

    hi sir,
    how can i display movie using tft 2.8

    • @BytesNBits
      @BytesNBits  Год назад +1

      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!).

  • @boacmihnea5463
    @boacmihnea5463 9 месяцев назад

    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  9 месяцев назад +1

      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 9 месяцев назад

      Thank you! 👍

  • @umutkayacan7659
    @umutkayacan7659 3 года назад +1

    Nice video!

  • @josegarcia-sv2sh
    @josegarcia-sv2sh Год назад +1

    do you have the code for this example? thanks...

    • @BytesNBits
      @BytesNBits  Год назад

      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() {
      }

  • @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 11 месяцев назад

    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  11 месяцев назад

      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 11 месяцев назад

      @@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  11 месяцев назад

      @@waynehawkins654 No problem. Hope you get it working 😃

  • @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.

  • @jumbo999614
    @jumbo999614 2 месяца назад

    How to use SD card if ESP32 is used? I able to draw graphic and touch function but I can't get SD card to work.
    I found this tutorial ->ruclips.net/video/ZmMTr8LEa1A/видео.html
    Is this only way to fix the problem? I'm not good with soldering. I don't want to fry my ESP32 and TFT.

    • @BytesNBits
      @BytesNBits  2 месяца назад

      You can buy ESP32 models with the SD card slot built in. Otherwise you'll need to write a card adapter in to your circuit.

  • @josegarcia-sv2sh
    @josegarcia-sv2sh Год назад

    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

    • @jumbo999614
      @jumbo999614 2 месяца назад

      I always have similar problem. It is because of unmatched "{ " or "}"
      probably your loop is inside setup().