Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 8 of 8

Thread: Can not create file on SD Card in Teensy 4.1

  1. #1
    Junior Member
    Join Date
    Dec 2020
    Posts
    3

    Can not create file on SD Card in Teensy 4.1

    I have a Teensy4.1
    Formatted a FAT32 SD card in windows.
    When I run the Teensy SD card example all is fine until the sketch tries to create a file.
    It can not.
    What can I do to enable file creation by Teensy on my card?

    The output I get is:

    Initializing SD card...Wiring is correct and a card is present.

    Card type: SDHC

    Volume type is FAT32

    Volume size (Kbytes): 7774208
    Volume size (Mbytes): 7592

    Files found on the card (name, date and size in bytes):
    SYSTEM~1/ 2020-11-22 14:48:06
    INDEXE~1 2020-11-22 14:48:08 76
    WPSETT~1.DAT 2020-12-01 18:45:30 12
    HDATA 2020-11-30 18:52:20 192
    SDATA 2020-11-30 18:54:54 444
    PDATA 2020-11-28 18:17:00 48
    HDATA_M 2020-11-28 18:17:26 0
    HDATA_Y 2020-11-28 18:17:30 0
    SDATA_M 2020-11-28 18:17:36 0
    SDATA_Y 2020-11-28 18:17:42 0
    PDATA_M 2020-11-28 18:17:50 0
    PDATA_Y 2020-11-28 18:17:54 0
    Could not create file

    The sketch I am using is:
    Code:
    // include the SD library:
    #include <SD.h>
    #include <SPI.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
    // Teensy audio board: pin 10
    // Teensy 3.5 & 3.6 & 4.1 on-board: BUILTIN_SDCARD
    // Wiz820+SD board: pin 4
    // Teensy 2.0: pin 0
    // Teensy++ 2.0: pin 20
    const int chipSelect = BUILTIN_SDCARD;
    
    void setup()
    {
      //UNCOMMENT THESE TWO LINES FOR TEENSY AUDIO BOARD:
      //SPI.setMOSI(7);  // Audio shield has MOSI on pin 7
      //SPI.setSCK(14);  // Audio shield has SCK on pin 14
      
     // Open serial communications and wait for port to open:
      Serial.begin(9600);
       while (!Serial) {
        ; // wait for serial port to connect.
      }
    
    
      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?");
        return;
      } else {
       Serial.println("Wiring is correct and a card is present.");
      }
    
      // print the type of card
      Serial.print("\nCard 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");
        return;
      }
    
    
      // print the type and size of the first FAT-type volume
      uint32_t volumesize;
      Serial.print("\nVolume type is FAT");
      Serial.println(volume.fatType(), DEC);
      Serial.println();
      
      volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
      volumesize *= volume.clusterCount();       // we'll have a lot of clusters
      if (volumesize < 8388608ul) {
        Serial.print("Volume size (bytes): ");
        Serial.println(volumesize * 512);        // SD card blocks are always 512 bytes
      }
      Serial.print("Volume size (Kbytes): ");
      volumesize /= 2;
      Serial.println(volumesize);
      Serial.print("Volume size (Mbytes): ");
      volumesize /= 1024;
      Serial.println(volumesize);
    
      
      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) {
      File blah = SD.open("XXX",FILE_WRITE);
      if (blah) {
        Serial.print("Successfully created file");
      } else {
        Serial.print("Could not create file");
      }
      blah.println("Yadayada");
      blah.close();
      SD.remove("XXX");
      while(true);
    }
    Thanks for any help...
    Last edited by Frank B; 12-02-2020 at 07:47 PM. Reason: added code tags

  2. #2
    This is the first thing I would check. Someone else was having the issue they could .begin(), but couldn't .open() anything. Quote from Paul on this thread:

    Quote Originally Posted by PaulStoffregen View Post
    The big caveat is whether you're really using the SD library from Teensyduino. It's in hardware/teensy/avr/libraries/SD. If you turn on verbose info, Arduino tells you the full pathname of every library it used. If you have multiple conflicting versions, it should alert you to the conflict and tell you which one it actually used. You really should use the one Teensyduino installs into hardware/teensy/avr/libraries/SD.

  3. #3
    Junior Member
    Join Date
    Dec 2020
    Posts
    3
    Dear Sand Wich,

    Thanks for the reply.
    I am pretty sure that I am using the Teensy version of the SD.h library. I even renamed the bog standard Arduino one so that
    it wouldn't get picked up. Yet, it is still not writing to the SD
    I tried two different SD cards (one brand new)...

    The output of a verbose compile is:


    Code:
    /home/marco/arduino-1.8.13/arduino-builder -dump-prefs -logger=machine -hardware /home/marco/arduino-1.8.13/hardware -hardware /home/marco/Arduino/hardware -tools /home/marco/arduino-1.8.13/tools-builder -tools /home/marco/arduino-1.8.13/hardware/tools/avr -built-in-libraries /home/marco/arduino-1.8.13/libraries -libraries /home/marco/Arduino/libraries -fqbn=teensy:avr:teensy41:usb=serial,speed=600,opt=o2std,keys=en-us -ide-version=10813 -build-path /tmp/arduino_build_606012 -warnings=none -build-cache /tmp/arduino_cache_410159 -verbose /home/marco/Arduino/Teensy41_SD_test/Teensy41_SD_test.ino
    /home/marco/arduino-1.8.13/arduino-builder -compile -logger=machine -hardware /home/marco/arduino-1.8.13/hardware -hardware /home/marco/Arduino/hardware -tools /home/marco/arduino-1.8.13/tools-builder -tools /home/marco/arduino-1.8.13/hardware/tools/avr -built-in-libraries /home/marco/arduino-1.8.13/libraries -libraries /home/marco/Arduino/libraries -fqbn=teensy:avr:teensy41:usb=serial,speed=600,opt=o2std,keys=en-us -ide-version=10813 -build-path /tmp/arduino_build_606012 -warnings=none -build-cache /tmp/arduino_cache_410159 -verbose /home/marco/Arduino/Teensy41_SD_test/Teensy41_SD_test.ino
    Using board 'teensy41' from platform in folder: /home/marco/arduino-1.8.13/hardware/teensy/avr
    Using core 'teensy4' from platform in folder: /home/marco/arduino-1.8.13/hardware/teensy/avr
    Detecting libraries used...
    /home/marco/arduino-1.8.13/hardware/teensy/../tools/arm/bin/arm-none-eabi-g++ -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=153 -DARDUINO=10813 -DARDUINO_TEENSY41 -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH -I/home/marco/arduino-1.8.13/hardware/teensy/avr/cores/teensy4 /tmp/arduino_build_606012/sketch/Teensy41_SD_test.ino.cpp -o /dev/null -DARDUINO_LIB_DISCOVERY_PHASE
    Alternatives for SD.h: [SD@1.2.4 SD@1.2.2]
    ResolveLibrary(SD.h)
      -> candidates: [SD@1.2.4 SD@1.2.2]
    /home/marco/arduino-1.8.13/hardware/teensy/../tools/arm/bin/arm-none-eabi-g++ -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=153 -DARDUINO=10813 -DARDUINO_TEENSY41 -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH -I/home/marco/arduino-1.8.13/hardware/teensy/avr/cores/teensy4 -I/home/marco/arduino-1.8.13/hardware/teensy/avr/libraries/SD /tmp/arduino_build_606012/sketch/Teensy41_SD_test.ino.cpp -o /dev/null -DARDUINO_LIB_DISCOVERY_PHASE
    Alternatives for SPI.h: [SPI@1.0]
    ResolveLibrary(SPI.h)
      -> candidates: [SPI@1.0]
    /home/marco/arduino-1.8.13/hardware/teensy/../tools/arm/bin/arm-none-eabi-g++ -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=153 -DARDUINO=10813 -DARDUINO_TEENSY41 -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH -I/home/marco/arduino-1.8.13/hardware/teensy/avr/cores/teensy4 -I/home/marco/arduino-1.8.13/hardware/teensy/avr/libraries/SD -I/home/marco/arduino-1.8.13/hardware/teensy/avr/libraries/SPI /tmp/arduino_build_606012/sketch/Teensy41_SD_test.ino.cpp -o /dev/null -DARDUINO_LIB_DISCOVERY_PHASE
    Using cached library dependencies for file: /home/marco/arduino-1.8.13/hardware/teensy/avr/libraries/SD/File.cpp
    Using cached library dependencies for file: /home/marco/arduino-1.8.13/hardware/teensy/avr/libraries/SD/SD.cpp
    Using cached library dependencies for file: /home/marco/arduino-1.8.13/hardware/teensy/avr/libraries/SD/cache_t3.cpp
    Using cached library dependencies for file: /home/marco/arduino-1.8.13/hardware/teensy/avr/libraries/SD/card_t3.cpp
    Using cached library dependencies for file: /home/marco/arduino-1.8.13/hardware/teensy/avr/libraries/SD/dir_t3.cpp
    Using cached library dependencies for file: /home/marco/arduino-1.8.13/hardware/teensy/avr/libraries/SD/fat_t3.cpp
    Using cached library dependencies for file: /home/marco/arduino-1.8.13/hardware/teensy/avr/libraries/SD/file_t3.cpp
    Using cached library dependencies for file: /home/marco/arduino-1.8.13/hardware/teensy/avr/libraries/SD/init_t3.cpp
    Using cached library dependencies for file: /home/marco/arduino-1.8.13/hardware/teensy/avr/libraries/SD/utility/NXP_SDHC.cpp
    Using cached library dependencies for file: /home/marco/arduino-1.8.13/hardware/teensy/avr/libraries/SD/utility/Sd2Card.cpp
    Using cached library dependencies for file: /home/marco/arduino-1.8.13/hardware/teensy/avr/libraries/SD/utility/SdFile.cpp
    Using cached library dependencies for file: /home/marco/arduino-1.8.13/hardware/teensy/avr/libraries/SD/utility/SdVolume.cpp
    Using cached library dependencies for file: /home/marco/arduino-1.8.13/hardware/teensy/avr/libraries/SPI/SPI.cpp
    Generating function prototypes...
    /home/marco/arduino-1.8.13/hardware/teensy/../tools/arm/bin/arm-none-eabi-g++ -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=153 -DARDUINO=10813 -DARDUINO_TEENSY41 -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH -I/home/marco/arduino-1.8.13/hardware/teensy/avr/cores/teensy4 -I/home/marco/arduino-1.8.13/hardware/teensy/avr/libraries/SD -I/home/marco/arduino-1.8.13/hardware/teensy/avr/libraries/SPI /tmp/arduino_build_606012/sketch/Teensy41_SD_test.ino.cpp -o /tmp/arduino_build_606012/preproc/ctags_target_for_gcc_minus_e.cpp -DARDUINO_LIB_DISCOVERY_PHASE
    /home/marco/arduino-1.8.13/tools-builder/ctags/5.8-arduino11/ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives /tmp/arduino_build_606012/preproc/ctags_target_for_gcc_minus_e.cpp
    Compiling sketch...
    /home/marco/arduino-1.8.13/hardware/teensy/../tools/precompile_helper /home/marco/arduino-1.8.13/hardware/teensy/avr/cores/teensy4 /tmp/arduino_build_606012 /home/marco/arduino-1.8.13/hardware/teensy/../tools/arm/bin/arm-none-eabi-g++ -x c++-header -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=153 -DARDUINO=10813 -DARDUINO_TEENSY41 -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH -I/home/marco/arduino-1.8.13/hardware/teensy/avr/cores/teensy4 /tmp/arduino_build_606012/pch/Arduino.h -o /tmp/arduino_build_606012/pch/Arduino.h.gch
    Using previously compiled file: /tmp/arduino_build_606012/pch/Arduino.h.gch
    /home/marco/arduino-1.8.13/hardware/teensy/../tools/arm/bin/arm-none-eabi-g++ -c -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=153 -DARDUINO=10813 -DARDUINO_TEENSY41 -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH -I/tmp/arduino_build_606012/pch -I/home/marco/arduino-1.8.13/hardware/teensy/avr/cores/teensy4 -I/home/marco/arduino-1.8.13/hardware/teensy/avr/libraries/SD -I/home/marco/arduino-1.8.13/hardware/teensy/avr/libraries/SPI /tmp/arduino_build_606012/sketch/Teensy41_SD_test.ino.cpp -o /tmp/arduino_build_606012/sketch/Teensy41_SD_test.ino.cpp.o
    Compiling libraries...
    Compiling library "SD"
    Using previously compiled file: /tmp/arduino_build_606012/libraries/SD/cache_t3.cpp.o
    Using previously compiled file: /tmp/arduino_build_606012/libraries/SD/dir_t3.cpp.o
    Using previously compiled file: /tmp/arduino_build_606012/libraries/SD/init_t3.cpp.o
    Using previously compiled file: /tmp/arduino_build_606012/libraries/SD/File.cpp.o
    Using previously compiled file: /tmp/arduino_build_606012/libraries/SD/SD.cpp.o
    Using previously compiled file: /tmp/arduino_build_606012/libraries/SD/card_t3.cpp.o
    Using previously compiled file: /tmp/arduino_build_606012/libraries/SD/fat_t3.cpp.o
    Using previously compiled file: /tmp/arduino_build_606012/libraries/SD/file_t3.cpp.o
    Using previously compiled file: /tmp/arduino_build_606012/libraries/SD/utility/NXP_SDHC.cpp.o
    Using previously compiled file: /tmp/arduino_build_606012/libraries/SD/utility/Sd2Card.cpp.o
    Using previously compiled file: /tmp/arduino_build_606012/libraries/SD/utility/SdVolume.cpp.o
    Using previously compiled file: /tmp/arduino_build_606012/libraries/SD/utility/SdFile.cpp.o
    Compiling library "SPI"
    Using previously compiled file: /tmp/arduino_build_606012/libraries/SPI/SPI.cpp.o
    Compiling core...
    Using precompiled core: /tmp/arduino_cache_410159/core/core_6c39079b90190c67f8ac0eafcdd6ad78.a
    Linking everything together...
    /home/marco/arduino-1.8.13/hardware/teensy/../tools/arm/bin/arm-none-eabi-gcc -O2 -Wl,--gc-sections,--relax -T/home/marco/arduino-1.8.13/hardware/teensy/avr/cores/teensy4/imxrt1062_t41.ld -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -o /tmp/arduino_build_606012/Teensy41_SD_test.ino.elf /tmp/arduino_build_606012/sketch/Teensy41_SD_test.ino.cpp.o /tmp/arduino_build_606012/libraries/SD/File.cpp.o /tmp/arduino_build_606012/libraries/SD/SD.cpp.o /tmp/arduino_build_606012/libraries/SD/cache_t3.cpp.o /tmp/arduino_build_606012/libraries/SD/card_t3.cpp.o /tmp/arduino_build_606012/libraries/SD/dir_t3.cpp.o /tmp/arduino_build_606012/libraries/SD/fat_t3.cpp.o /tmp/arduino_build_606012/libraries/SD/file_t3.cpp.o /tmp/arduino_build_606012/libraries/SD/init_t3.cpp.o /tmp/arduino_build_606012/libraries/SD/utility/NXP_SDHC.cpp.o /tmp/arduino_build_606012/libraries/SD/utility/Sd2Card.cpp.o /tmp/arduino_build_606012/libraries/SD/utility/SdFile.cpp.o /tmp/arduino_build_606012/libraries/SD/utility/SdVolume.cpp.o /tmp/arduino_build_606012/libraries/SPI/SPI.cpp.o /tmp/arduino_build_606012/../arduino_cache_410159/core/core_6c39079b90190c67f8ac0eafcdd6ad78.a -L/tmp/arduino_build_606012 -larm_cortexM7lfsp_math -lm -lstdc++
    /home/marco/arduino-1.8.13/hardware/teensy/../tools/arm/bin/arm-none-eabi-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 /tmp/arduino_build_606012/Teensy41_SD_test.ino.elf /tmp/arduino_build_606012/Teensy41_SD_test.ino.eep
    /home/marco/arduino-1.8.13/hardware/teensy/../tools/arm/bin/arm-none-eabi-objcopy -O ihex -R .eeprom /tmp/arduino_build_606012/Teensy41_SD_test.ino.elf /tmp/arduino_build_606012/Teensy41_SD_test.ino.hex
    /home/marco/arduino-1.8.13/hardware/teensy/../tools/stdout_redirect /tmp/arduino_build_606012/Teensy41_SD_test.ino.lst /home/marco/arduino-1.8.13/hardware/teensy/../tools/arm/bin/arm-none-eabi-objdump -d -S -C /tmp/arduino_build_606012/Teensy41_SD_test.ino.elf
    /home/marco/arduino-1.8.13/hardware/teensy/../tools/stdout_redirect /tmp/arduino_build_606012/Teensy41_SD_test.ino.sym /home/marco/arduino-1.8.13/hardware/teensy/../tools/arm/bin/arm-none-eabi-objdump -t -C /tmp/arduino_build_606012/Teensy41_SD_test.ino.elf
    /home/marco/arduino-1.8.13/hardware/teensy/../tools/teensy_post_compile -file=Teensy41_SD_test.ino -path=/tmp/arduino_build_606012 -tools=/home/marco/arduino-1.8.13/hardware/teensy/../tools/ -board=TEENSY41
    Multiple libraries were found for "SD.h"
     Used: /home/marco/arduino-1.8.13/hardware/teensy/avr/libraries/SD
     Not used: /home/marco/arduino-1.8.13/libraries/SD
    Using library SD at version 1.2.2 in folder: /home/marco/arduino-1.8.13/hardware/teensy/avr/libraries/SD 
    Using library SPI at version 1.0 in folder: /home/marco/arduino-1.8.13/hardware/teensy/avr/libraries/SPI 
    /home/marco/arduino-1.8.13/hardware/teensy/../tools/arm/bin/arm-none-eabi-size -A /tmp/arduino_build_606012/Teensy41_SD_test.ino.elf
    Sketch uses 30656 bytes (0%) of program storage space. Maximum is 8126464 bytes.
    Global variables use 45756 bytes (8%) of dynamic memory, leaving 478532 bytes for local variables. Maximum is 524288 bytes.
    Last edited by Frank B; 12-02-2020 at 07:46 PM. Reason: added code tags

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,774
    Use SD.begin(chipSelect) to initialize the card. Delete all that other init stuff. Look at any of the SD examples in File > Examples > SD, except for CardInfo.

    When you initialize the card this way, you can use those info functions to learn about the card. But the rest of the SD library isn't properly initialized. It leaves the SD library unable to work. You need to use SD.begin(pin) to fully initialize the entire SD library when you want to do anything more than get the card info.

    You might also consider using the 1.54-beta5. The SD library has been updated / replaced with SdFat. The same SD functions still work, but it can now use long filenames and larger cards.

  5. #5
    Senior Member
    Join Date
    Jul 2014
    Posts
    3,066
    I would first try a standard example from the SD library that writes and reads from SD e.g. ReadWrite
    IMHO you are mixing up different low-level calls
    e.g. SD.begin is never called

    Edit: Paul was faster

  6. #6
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,544
    I ran into a similar problem except that my code couldn't find a file that I knew to be on the SD card - because Windows Explorer showed that it was there.
    I used the listfiles example SD sketch to list the SD directory when it was in the builtin slot on a T4.1 and got this:
    Code:
    Initializing SD card...initialization done.
    bomb_44.wav                                       598316
    bach_441.wav                                      10091100
    alien144.wav                                      23036
    drbell44.wav                                      203798
    log_161231_leap_second.txt                        327908
    wwvb_log_170106_1948-170109_0552.txt              835698
    wwvb_raw_170114_2031.txt                          512
    wwvb_raw_170114_2040.txt                          512
    wwvb_raw_170115_1136.txt                          512
    wwvb_raw_170114_1154.txt                          512
    wwvb_raw_170115_1312.txt                          512
    wwvb_raw_170115_1350.txt                          1024
    wwvb_raw_170115_1356_1603.txt                     35328
    wwvb_raw_170115_1604.txt                          29696
    wwvb_raw_170115_1811-2131.txt                     62464
    wwvb_raw_170115_2136-1024.txt                     187392
    wwvb_raw_170116_xxxx-2008.txt                     75264
    wwvb_raw_170117_0222-2106.txt                     271360
    System Volume Information/
      IndexerVolumeGuid                               76
      WPSettings.dat                                  12
    Violin_open_D_string_Clngre.wav                   873172
    ODClngre.wav                                      436608
    SDTEST3.WAV                                       13617358
    SDTEST4.WAV                                       17173152
    SDTEST1.WAV                                       16787550
    SDTEST2.WAV                                       16425698
    RECORD_AUDIOBOARD.RAW                             410112
    fox_rs.bmp                                        61494
    BaboonP.jpg                                       15038
    EagleEye.jpg                                      37755
    fox_rs.jpg                                        7702
    lena20k.jpg                                       19414
    Mouse.jpg                                         27808
    Mouse480.jpg                                      6609
    tiger.jpg                                         47316
    arduino.jpg                                       8426
    Baboon20.jpg                                      12569
    Baboon40.jpg                                      24384
    BaboonL.jpg                                       12569
    foxrsrot.jpg                                      23886
    Baboonrs.jpg                                      31707
    tiger_rs.jpg                                      33581
    19000112.wav                                      131564
    xyz20d.wav                                      124460
    foxrsrot.bmp                                      61494
    done!
    But when I put the card into the slot on an ST7735 TFT LCD with cs on pin 4 I got this:
    Code:
    Initializing SD card...initialization done.
    bomb_44.wav                                       598316
    bach_441.wav                                      10091100
    alien144.wav                                      23036
    drbell44.wav                                      203798
    log_161231_leap_second.txt                        327908
    wwvb_log_170106_1948-170109_0552.txt              835698
    wwvb_raw_170114_2031.txt                          512
    wwvb_raw_170114_2040.txt                          512
    wwvb_raw_170115_1136.txt                          512
    wwvb_raw_170114_1154.txt                          512
    wwvb_raw_170115_1312.txt                          512
    wwvb_raw_170115_1350.txt                          1024
    wwvb_raw_170115_1356_1603.txt                     35328
    wwvb_raw_170115_1604.txt                          29696
    wwvb_raw_170115_1811-2131.txt                     62464
    wwvb_raw_170115_2136-1024.txt                     187392
    wwvb_raw_170116_xxxx-2008.txt                     75264
    wwvb_raw_170117_0222-2106.txt                     271360
    System Volume Information/
      IndexerVolumeGuid                               76
      WPSettings.dat                                  12
    done!
    When the card is in the ST7735 slot, none of the files after WPSettings.dat are visible (my code was trying to open fox_rs.bmp). I "fixed" it by using Windows to copy the files I needed from this bad card onto a different one and now it works.

    So, try the listfiles example to look at the card. Maybe there's a "System Volume Information" directory getting in your way.

    Pete

  7. #7
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,544
    Your problem isn't related to mine. You appear to be using an older version of the cardinfo example. The latest version has root.openRoot and root.ls commented out.
    As Paul has suggested, try Arduino 1.8.13 with Teensyduino 1.54-beta5.

    Pete

  8. #8
    Junior Member
    Join Date
    Dec 2020
    Posts
    3
    Thanks all for the help.

    Especially Paul Stoffregen

    I have made some progress.

    I was hoping to open an SD file for simultaneous reading and writing.
    Is that even possible? The documentation seems a bit sketchy on this point, and most
    examples first open a file for writing, then reopen it for reading.

    It seems that if I open a file with FILE_WRITE, then .available() changes behaviour (as opposed to if I open with FILE_READ).

    In the following sketch I have commented one line in the main loop.
    Uncommenting it and commenting the one above it results in completely different behaviour. .available() never goes false.
    Is this the expected behaviour???

    Thanks for any help.

    /MR

    void setup()
    {
    //UNCOMMENT THESE TWO LINES FOR TEENSY AUDIO BOARD:
    //SPI.setMOSI(7); // Audio shield has MOSI on pin 7
    //SPI.setSCK(14); // Audio shield has SCK on pin 14

    // Open serial communications and wait for port to open:
    Serial.begin(9600);
    while (!Serial) {
    ; // wait for serial port to connect.
    }


    Serial.print("\nInitializing SD card...");

    SD.begin(chipSelect);
    }


    void loop(void) {
    SD.remove("XXX");
    File blah = SD.open("XXX",FILE_WRITE);
    if (blah) {
    Serial.print("Successfully created file");
    } else {
    Serial.print("Could not create file");
    }
    blah.println("Yadayada");
    blah.close();
    blah = SD.open("XXX",FILE_READ);
    // blah = SD.open("XXX",FILE_WRITE);
    blah.seek(0);
    while(blah.available()) {
    char h2f5 = blah.read();
    Serial.print(h2f5);
    }
    while(true);
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •