HOME - - - - - - - - Table of contents, my Arduino "How To" articles
Other material for programmers     

Reading and Writing SD cards

With Arduinos... in particular ESP8266s

filename: aht3ReadWriteSD.htm

This tutorial presents code for reading from, and writing to an SD (or microSD) card.

This may seem a terribly lightweight tutorial.

But it is the fruits of two very long days of work. Though there is little here, there is a great deal of information for you in the comments within the sourcecode... which you can download. (free).

Click these, to download the Arduino IDE files (.ino) files...

Read demo

Write demo

It is tweaked for use in an Sparkfun ESP8266 Thing Dev.


((q-alt text for image))

As it happens... I don't think it will have made a big difference to what's here, I was using the Hobbytronics.co.uk SDCARD-REG2. Not expensive (£7.20 at 3/19)... with features which means it plays nicely with either 5v or 3v3 systems.

If you search for that by name, don't be alarmed if you find "it" disconinuted... there was a version 1 of the module... which has beenm discontinued. At 3/19, we had the benefit of a version 2.

There are many pages about reading and writing to SD cards out there in internet land.... with the usual proportion of them containing bad or out of date information.

However, there isn't nearly as much on the web about doing it with an ESP8266... a wonderful device, but one with a few quirks to be overcome.

Although I haven't tested it I believe that it would work with other ESP8266s (I would be grateful for news that it did, if you find that to be so.)

The code should also work in non-ESP8266 Arduinos...

For that, you would remove the line saying SPI.setFrequency(1000000);... and...

... you would also probably have to change the numbers in...

#define pDI 13//no ; here
#define pDO 12
#define pCLK 14

I believe the "right" pins to use for these three are "set in stone" by the microprocessor you use.

The program reads two lines from an SD card. They need to be in a file called "creds.txt" in the root of the card. The file needs a very specific format... but if you read the comments in the code, you will see that this is not set in stone... as long as you can do a little re-programming.

The program isn't as "user friendly" as it ought to be. Various problems with the creds.txt file would cause inelegant system failures. (Nothing to damage your hardware... it would just fail to do what was wanted, and maybe not give very clear error messages.)

The Arduino IDE Serial Monitor will help you see "what's what", up to a point, when the program runs.

There is a great deal more help on how to read or write from (to) SD cards in the comments in the sourcecode.

This essay provides help with reading or writing to SD cards
The "read" routine here is crude...

The read routine offered here is crude. Useable! But not flexible, and not tolerant of imperfections in the composition of the file being read.

Someday someone will have to improve the core part of this. (The "access the SD card" part is, touch wood, "finished".)

Significant planning for that "better world" is available in another essay I've written: sFetchLineFromFile- a general function for reading text from a file.





   Search this site or the web        powered by FreeFind
 
  Site search Web search
Site Map    What's New    Search

The search engine is not intelligent. It merely seeks the words you specify. It will not do anything sensible with "What does the 'could not compile' error mean?" It will just return references to pages with "what", "does", "could", "not".... etc.
In addition to the tutorials for which this page serves as Table of Contents, I have other sites with material you might find useful.....

Sequenced set of tutorials on Arduino programming and electronics interfacing.
Tutorials about the free database supplied with Open Office/ Libre Office.

Some pages for programmers.
Using the parallel port of a Windows computer.


If you visit 1&1's site from here, it helps me. They host my website, and I wouldn't put this link up for them if I wasn't happy with their service.




Ad from page's editor: Yes.. I do enjoy compiling these things for you... hope they are helpful. However.. this doesn't pay my bills!!! If you find this stuff useful, (and you run an MS-DOS or Windows PC) please visit my freeware and shareware page, download something, and circulate it for me? Links on your page to this page would also be appreciated!

Click here to visit editor's Sheepdog Software freeware, shareware pages.. Material on this page © TK Boyd 3/19


And if you liked that, or want different things, here are some more pages from the editor of these tutorials....

Click here to visit the homepage of my biggest site.

Click here to visit the homepage of Sheepdogsoftware.co.uk. Apologies if the "?FrmAht" I added to that link causes your browser problems. Please let me know, if so?

Click here to visit editor's pages about using computers in Sensing and Control, e.g. weather logging.



To email this page's editor, Tom Boyd.... Editor's email address. Suggestions welcomed!


Valid HTML 4.01 Transitional Page has been tested for compliance with INDUSTRY (not MS-only) standards, using the free, publicly accessible validator at validator.w3.org. Mostly passes.

AND passes... Valid CSS!


Why does this page cause a script to run? Because of the Google panels, and the code for the search button. Why do I mention the script? Be sure you know all you need to about spyware.

....... P a g e . . . E n d s .....