Go Down

Topic: Writing to SD Cards (Read 714 times) previous topic - next topic


Im after pure fundamentals here, just want to know how to do something along the lines of taking a value from a pin, whether it be a button high/low, or value from a sensor like a NTC.....And at defined increments of time, log that value data to a SD card.

I looked though the SD guides like SD/MMC From the ground up

but just cant find a guide/tutorial on the code side of things....and even the example codes in related libraries, like FileLogger, or SDuFAT go over my head.

Say i wanted to modify the simple bit of code below "Button" to log every time the button was pressed onto the card.....how would i go about it!?

Code: [Select]

const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin
// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);    
void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {    
    // turn LED on:    
    digitalWrite(ledPin, HIGH);  
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);


The answer to that question is entirely dependent on the library being used to write to the card. Unless, you are not using a library.

If you are not, then you should know how to write to the SD card.

If you are, you should be able to look in the header files, and figure out which methods write to the card, which methods read from the card, and which methods initialize access to the card, or create or traverse files and directories, etc.

If you can't, tell us which library you are using, and we can provide more help.


Feb 17, 2010, 07:17 pm Last Edit: Feb 17, 2010, 07:19 pm by n00b Reason: 1
If you are not, then you should know how to write to the SD card.

this is the whole point of the post.........i dont know how!!!!  :'(

where do i find how to????


this is the whole point of the post.........i dont know how!!!!

Then, you should be using a library that DOES know how. There are several available that include different levels of functionality. The additional functionality may or may not be required in your case, and comes with a cost (increased code size). You need to determine which library provides the minimum level of functionality that you need, if you are not capable of creating your own.

If you were capable, you would be asking much different questions, and on a different forum, I think.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131