element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • 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 & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • 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
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • 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 401 subscribers
  • Views 2763 views
  • Users 0 members are here
  • sdcard
Related

SD library won't write to card

rickseiden
rickseiden over 11 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 11 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 11 years ago

    I tried this and had a compilation error to start. The following was missing :

    #include <SPI.h>

     

    The programs you posted works for me. I have a file TEST.TXT with this content:

    LINE ONE

    LINE TWO

     

    SD card used: micro SD HC 4GB CO4G TAIWAN

     

    image

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

    I never got the comp error you got.  I'm using IDE 1.0.6 with a brand new Uno R3.

     

    I tried adding the include for SPI, but it didn't make a difference.

     

    Thanks for trying!  I really do appreciate it.

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

    I never got the comp error you got.  I'm using IDE 1.0.6 with a brand new Uno R3.

     

    I tried adding the include for SPI, but it didn't make a difference.

     

    Thanks for trying!  I really do appreciate it.

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

    > I'm using IDE 1.0.6 with a brand new Uno R3.

    Same Arduino, IDE 1.5.8.

    • 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