element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum SD library won't write to card
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 8 replies
  • Answers 1 answer
  • Subscribers 391 subscribers
  • Views 2679 views
  • Users 0 members are here
  • sdcard
Related

SD library won't write to card

rickseiden
rickseiden over 10 years ago

I've got a sketch that isn't writing to the SD card at all.  It will create a file on the card, but not write to it.

 

It's an eBay special SD Card (3X SD Card Interface Module Slot Socket Adapter Reader SPI Arduino Arm Pi USA | eBay), but otherwise works with the SD Library.  I can list files on the card. It will give me info about the card. It just won't write to it.

 

I even tried the data logger, and it will create the file, but not write.  Datalogger gives the "error opening datalog.txt" over and over again, even though the file is there, and was created on the card by the first run through.

 

Anyway, to simplify things, I wrote this barebones sketch:

 

#include <SD.h>

File myFile;

boolean SDOK=false;

 

void setup(){

  pinMode(10,OUTPUT);

  Serial.begin(57600);

  SDOK=SD.begin();

  if (SDOK){

    Serial.println("init OK");

    myFile=SD.open("TEST.TXT",FILE_WRITE);

    if (myFile){

      Serial.println("file OPEN");

      myFile.println("LINE ONE");

      Serial.println("prtn ONE");

      myFile.write("LINE TWO");

      Serial.println("wrte TWO");

      myFile.flush();

      myFile.close();

    } else {

      Serial.println("file FAIL");

    }

  } else {

    Serial.println("init FAIL");

  }

}

 

void loop(){

}

 

It will show the following output:

 

init OK

file OPEN

prtn ONE

wrte TWO


I'm not sure what I'm doing wrong.  I know the flush isn't necessary in there, but since it's not writing, I figured I'd throw it in there.

 

Any help you guys could give me would be greatly appreciated.


Thanks!

  • Sign in to reply
  • Cancel

Top Replies

  • rickseiden
    rickseiden over 10 years ago in reply to Jan Cumps +1
    That did it. I'm surprised that it was the 3v3 thing, as it has an input for 5v, but you can't argue with a working solution! Thank you so much!
Parents
  • Jan Cumps
    0 Jan Cumps over 10 years ago

    Since this adapter is for 3.3V signals, you have to drop your input signals (CS, MOSI and SCK)  to 3.3V.

    The best way to do that is via a dedicated voltage translator chip.

    This hack works for me on this particular adapter with an Arduino Uno:

    http://apcmag.com/arduino-project-5-digital-audio-player.htm

     

    See:

    You don't have permission to edit metadata of this video.
    Edit media
    x
    image
    Upload Preview
    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
  • rickseiden
    0 rickseiden over 10 years ago in reply to Jan Cumps

    That did it.  I'm surprised that it was the 3v3 thing, as it has an input for 5v, but you can't argue with a working solution!

     

    Thank you so much!

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Jan Cumps
    0 Jan Cumps over 10 years ago in reply to rickseiden

    Hooray!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • Jan Cumps
    0 Jan Cumps over 10 years ago in reply to rickseiden

    Hooray!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • rickseiden
    0 rickseiden over 10 years ago in reply to Jan Cumps

    Thanks again!

     

    Just in case someone else has this problem, I decided that my adafruit bidirectional level shifter was too valuable, so I went with an 74LVC245 I had previously purchased from adafruit.  I didn't quite get it from the datasheet, but then I remembered Google is my friend, and my friend told me to try this out.

     

    The only change I made was to run the CS signal through the 74LVC245 as well.  Worked like a charm the first time out.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube